当前位置: 首页>>代码示例>>Java>>正文


Java SOAPHeaderElement.addAttribute方法代码示例

本文整理汇总了Java中javax.xml.soap.SOAPHeaderElement.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPHeaderElement.addAttribute方法的具体用法?Java SOAPHeaderElement.addAttribute怎么用?Java SOAPHeaderElement.addAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.soap.SOAPHeaderElement的用法示例。


在下文中一共展示了SOAPHeaderElement.addAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeTo

import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if (header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(name);

    if (type != null)
        she.addAttribute(typeAttributeName, type);
    she.addTextNode(value);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:RelatesToHeader.java

示例2: handleMessage

import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (isRequest) {
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPHeader soapHeader = soapEnv.getHeader();

            if (soapHeader == null) {
                soapHeader = soapEnv.addHeader();
            }

            QName qname = new QName("http://www.2n.cz/2013/event", "SubscriptionId");
            SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(qname);

            soapHeaderElement.addAttribute(
                    new QName("http://www.w3.org/2005/08/addressing", "IsReferenceParameter"), "true");
            if (handler.getSubscriptionID() != null) {
                soapHeaderElement.addTextNode(handler.getSubscriptionID());
            }
            soapMsg.saveChanges();
        } catch (Exception e) {
            logger.debug("An exception occurred while formatting a SOAP header : '{}'", e.getMessage());
        }
    }

    return true;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:31,代码来源:SOAPSubscriptionActionHandler.java

示例3: ebSetup

import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
public static void ebSetup(SOAPEnvelope envelope,
            String frparty,
            String toparty,
            String cpaId,
            String conversId,
            String service,
            String action
            ) {
       try {
           SOAPHeader header = envelope.getHeader();

     SOAPHeaderElement ebHeader = header.addHeaderElement(
     envelope.createName("MessageHeader", NS_PREFIX_EB, NS_URI_EB));
     ebHeader.setMustUnderstand(true);
     ebHeader.addAttribute(envelope.createName("version"), "1.0");

      SOAPElement ebFrom = ebHeader.addChildElement(
       envelope.createName("From", NS_PREFIX_EB, NS_URI_EB));
     SOAPElement ebPartyFrom = ebFrom.addChildElement(
       envelope.createName("PartyId", NS_PREFIX_EB, NS_URI_EB));
     ebPartyFrom.addTextNode(frparty);

     SOAPElement ebTo = ebHeader.addChildElement(
       envelope.createName("To", NS_PREFIX_EB, NS_URI_EB));
     SOAPElement ebPartyTo = ebTo.addChildElement(
       envelope.createName("PartyId", NS_PREFIX_EB, NS_URI_EB));
     ebPartyTo.addTextNode(toparty);

     SOAPElement ebCPAId = ebHeader.addChildElement(
       envelope.createName("CPAId", NS_PREFIX_EB, NS_URI_EB));
     ebCPAId.addTextNode(cpaId);

     SOAPElement ebConv = ebHeader.addChildElement(
       envelope.createName("ConversationId"
          , NS_PREFIX_EB, NS_URI_EB));
     ebConv.addTextNode(conversId);

     SOAPElement ebService = ebHeader.addChildElement(
       envelope.createName("Service", NS_PREFIX_EB, NS_URI_EB));
     ebService.addTextNode(service);

     SOAPElement ebAction = ebHeader.addChildElement(
       envelope.createName("Action", NS_PREFIX_EB, NS_URI_EB));
     ebAction.addTextNode(action);

     SOAPElement ebMesData = ebHeader.addChildElement(
       envelope.createName("MessageData", NS_PREFIX_EB, NS_URI_EB));

     SOAPElement ebMesId = ebMesData.addChildElement(
       envelope.createName("MessageId", NS_PREFIX_EB, NS_URI_EB));
     ebMesId.addTextNode(System.currentTimeMillis() + "");

     SOAPElement ebMesTime = ebMesData.addChildElement(
       envelope.createName("Timestamp", NS_PREFIX_EB, NS_URI_EB));
     ebMesTime.addTextNode(new Date().toString());

   } catch(Exception e) {
     e.printStackTrace();
   }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:61,代码来源:SOAPUtilServer.java

示例4: ebSetup

import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
private void ebSetup(SOAPEnvelope envelope,
            String frparty,
            String toparty,
            String cpaId,
            String conversId,
            String service,
            String action
            ) {
       try {
           SOAPHeader header = envelope.getHeader();

     SOAPHeaderElement ebHeader = header.addHeaderElement(
     envelope.createName("MessageHeader", NS_PREFIX_EB, NS_URI_EB));
     ebHeader.setMustUnderstand(true);
     ebHeader.addAttribute(envelope.createName("version"), "1.0");

      SOAPElement ebFrom = ebHeader.addChildElement(
       envelope.createName("From", NS_PREFIX_EB, NS_URI_EB));
     SOAPElement ebPartyFrom = ebFrom.addChildElement(
       envelope.createName("PartyId", NS_PREFIX_EB, NS_URI_EB));
     ebPartyFrom.addTextNode(frparty);

     SOAPElement ebTo = ebHeader.addChildElement(
       envelope.createName("To", NS_PREFIX_EB, NS_URI_EB));
     SOAPElement ebPartyTo = ebTo.addChildElement(
       envelope.createName("PartyId", NS_PREFIX_EB, NS_URI_EB));
     ebPartyTo.addTextNode(toparty);

     SOAPElement ebCPAId = ebHeader.addChildElement(
       envelope.createName("CPAId", NS_PREFIX_EB, NS_URI_EB));
     ebCPAId.addTextNode(cpaId);

     SOAPElement ebConv = ebHeader.addChildElement(
       envelope.createName("ConversationId"
          , NS_PREFIX_EB, NS_URI_EB));
     ebConv.addTextNode(conversId);

     SOAPElement ebService = ebHeader.addChildElement(
       envelope.createName("Service", NS_PREFIX_EB, NS_URI_EB));
     ebService.addTextNode(service);

     SOAPElement ebAction = ebHeader.addChildElement(
       envelope.createName("Action", NS_PREFIX_EB, NS_URI_EB));
     ebAction.addTextNode(action);

     SOAPElement ebMesData = ebHeader.addChildElement(
       envelope.createName("MessageData", NS_PREFIX_EB, NS_URI_EB));

     SOAPElement ebMesId = ebMesData.addChildElement(
       envelope.createName("MessageId", NS_PREFIX_EB, NS_URI_EB));
     ebMesId.addTextNode(System.currentTimeMillis() + "");

     SOAPElement ebMesTime = ebMesData.addChildElement(
       envelope.createName("Timestamp", NS_PREFIX_EB, NS_URI_EB));
     ebMesTime.addTextNode(new Date().toString());

   } catch(Exception e) {
     e.printStackTrace();
   }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:61,代码来源:SOAPUtilClient.java

示例5: getSOAPMessage

import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
/**
 * This method handles the conversion of an OM SOAP Envelope to a SAAJ SOAPMessage
 *
 * @param respOMSoapEnv
 * @return the SAAJ SOAPMessage
 * @throws SOAPException If an exception occurs during this conversion
 */
private SOAPMessage getSOAPMessage(org.apache.axiom.soap.SOAPEnvelope respOMSoapEnv)
        throws SOAPException {

    // Create the basic SOAP Message
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage response = mf.createMessage();
    SOAPPart sPart = response.getSOAPPart();
    javax.xml.soap.SOAPEnvelope env = sPart.getEnvelope();
    SOAPBody body = env.getBody();
    SOAPHeader header = env.getHeader();

    // Convert all header blocks
    org.apache.axiom.soap.SOAPHeader header2 = respOMSoapEnv.getHeader();
    if (header2 != null) {
        for (Iterator hbIter = header2.examineAllHeaderBlocks(); hbIter.hasNext();) {
            // Converting a single OM SOAP HeaderBlock to a SAAJ SOAP
            // HeaderBlock
            org.apache.axiom.soap.SOAPHeaderBlock hb = (org.apache.axiom.soap.SOAPHeaderBlock)
                    hbIter.next();
            final QName hbQName = hb.getQName();
            final SOAPHeaderElement headerEle = header.addHeaderElement(env.createName(hbQName
                    .getLocalPart(), hbQName.getPrefix(), hbQName.getNamespaceURI()));
            for (Iterator attribIter = hb.getAllAttributes(); attribIter.hasNext();) {
                OMAttribute attr = (OMAttribute)attribIter.next();
                final QName attrQName = attr.getQName();
                headerEle.addAttribute(env.createName(attrQName.getLocalPart(), attrQName
                        .getPrefix(), attrQName.getNamespaceURI()), attr.getAttributeValue());
            }
            final String role = hb.getRole();
            if (role != null) {
                headerEle.setActor(role);
            }
            headerEle.setMustUnderstand(hb.getMustUnderstand());

            toSAAJElement(headerEle, hb, response);
        }
    }

    // Convert the body
    toSAAJElement(body, respOMSoapEnv.getBody(), response);

    return response;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:51,代码来源:SOAPConnectionImpl.java

示例6: testSAAJ

import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
/**
 * The main goal of this test is to exercise the SAAJ classes and make sure
 * that no exceptions are thrown. We build a SOAP message, we send it to a
 * mock SOAP server, which simply echoes the message back to us, and then we
 * check to make sure that the returned message is the same as the sent
 * message. We perform that check for equality in a very shallow way because
 * we are not seriously concerned about the possibility that the SOAP message
 * might be garbled. The check for equality should be thought of as only a
 * sanity check.
 */
private void testSAAJ(String protocol) throws Exception {
  // Create the message
  MessageFactory factory = MessageFactory.newInstance(protocol);
  SOAPMessage requestMessage = factory.createMessage();

  // Add a header
  SOAPHeader header = requestMessage.getSOAPHeader();
  QName headerName = new QName("http://ws-i.org/schemas/conformanceClaim/", "Claim", "wsi");
  SOAPHeaderElement headerElement = header.addHeaderElement(headerName);
  headerElement.addAttribute(new QName("conformsTo"), "http://ws-i.org/profiles/basic/1.1/");

  // Add a body
  QName bodyName = new QName("http://wombat.ztrade.com", "GetLastTradePrice", "m");
  SOAPBody body = requestMessage.getSOAPBody();
  SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
  QName name = new QName("symbol");
  SOAPElement symbol = bodyElement.addChildElement(name);
  symbol.addTextNode("SUNW");

  // Add an attachment
  AttachmentPart attachment = requestMessage.createAttachmentPart();
  String stringContent =
      "Update address for Sunny Skies " + "Inc., to 10 Upbeat Street, Pleasant Grove, CA 95439";
  attachment.setContent(stringContent, "text/plain");
  attachment.setContentId("update_address");
  requestMessage.addAttachmentPart(attachment);

  // Add another attachment
  URL url = new URL("http://greatproducts.com/gizmos/img.jpg");
  // URL url = new URL("file:///etc/passwords");
  DataHandler dataHandler = new DataHandler(url);
  AttachmentPart attachment2 = requestMessage.createAttachmentPart(dataHandler);
  attachment2.setContentId("attached_image");
  requestMessage.addAttachmentPart(attachment2);

  // Send the message
  SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
  SOAPConnection connection = soapConnectionFactory.createConnection();
  URL endpoint = new URL("http://wombat.ztrade.com/quotes");

  // Get the response. Our mock url-fetch handler will echo back the request
  SOAPMessage responseMessage = connection.call(requestMessage, endpoint);
  connection.close();

  assertEquals(requestMessage, responseMessage);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:57,代码来源:SAAJTestServlet.java


注:本文中的javax.xml.soap.SOAPHeaderElement.addAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。