Java Code Examples for javax.xml.soap.SOAPHeaderElement#addAttribute()

The following examples show how to use javax.xml.soap.SOAPHeaderElement#addAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelatesToHeader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 2
Source File: RelatesToHeader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: RelatesToHeader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: RelatesToHeader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: RelatesToHeader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: RelatesToHeader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: RelatesToHeader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: RelatesToHeader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: TestMustUnderstandHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public boolean handleMessage(SOAPMessageContext ctx) {

        boolean continueProcessing = true;

        try {
            Object b = ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            boolean outbound = (Boolean)b;
            SOAPMessage msg = ctx.getMessage();
            if (isServerSideHandler()) {
                if (outbound) {
                    QName qname = new QName("http://cxf.apache.org/mu", "MU");
                    SOAPPart soapPart = msg.getSOAPPart();
                    SOAPEnvelope envelope = soapPart.getEnvelope();
                    SOAPHeader header = envelope.getHeader();
                    if (header == null) {
                        header = envelope.addHeader();
                    }


                    SOAPHeaderElement headerElement
                        = header.addHeaderElement(envelope.createName("MU", "ns1", qname.getNamespaceURI()));

                    // QName soapMustUnderstand = new QName("http://schemas.xmlsoap.org/soap/envelope/",
                    // "mustUnderstand");
                    Name name = SOAPFactory.newInstance()
                        .createName("mustUnderstand", "soap", "http://schemas.xmlsoap.org/soap/envelope/");
                    headerElement.addAttribute(name, "1");
                } else {
                    getHandlerInfoList(ctx).add(getHandlerId());
                }
            }
        } catch (SOAPException e) {
            e.printStackTrace();
        }
        return continueProcessing;
    }
 
Example 10
Source File: SAAJTestServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}