Java Code Examples for javax.xml.soap.MessageFactory#newInstance()

The following examples show how to use javax.xml.soap.MessageFactory#newInstance() . 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: DeviceDiscovery.java    From onvif with Apache License 2.0 6 votes vote down vote up
private static Collection<String> parseSoapResponseForUrls(byte[] data)
    throws SOAPException, IOException {
  // System.out.println(new String(data));
  final Collection<String> urls = new ArrayList<>();
  MessageFactory factory = MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION);
  final MimeHeaders headers = new MimeHeaders();
  headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE);
  SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data));
  SOAPBody body = message.getSOAPBody();
  for (Node node : getNodeMatching(body, ".*:XAddrs")) {
    if (node.getTextContent().length() > 0) {
      urls.addAll(Arrays.asList(node.getTextContent().split(" ")));
    }
  }
  return urls;
}
 
Example 2
Source File: MailTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void addSoapAttachement() {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        AttachmentPart a = message.createAttachmentPart();
        a.setContentType("binary/octet-stream");
        message.addAttachmentPart(a);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: MailTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void addSoapAttachement() {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        AttachmentPart a = message.createAttachmentPart();
        a.setContentType("binary/octet-stream");
        message.addAttachmentPart(a);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: SaajEmptyNamespaceTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
    String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage msg = mFactory.createMessage();
    msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
    return msg;
}
 
Example 5
Source File: XmlTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void test() throws Exception {

        File file = new File("message.xml");
        file.deleteOnExit();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage msg = createMessage(mf);

        // Save the soap message to file
        try (FileOutputStream sentFile = new FileOutputStream(file)) {
            msg.writeTo(sentFile);
        }

        // See if we get the image object back
        try (FileInputStream fin = new FileInputStream(file)) {
            SOAPMessage newMsg = mf.createMessage(msg.getMimeHeaders(), fin);

            newMsg.writeTo(new ByteArrayOutputStream());

            Iterator<?> i = newMsg.getAttachments();
            while (i.hasNext()) {
                AttachmentPart att = (AttachmentPart) i.next();
                Object obj = att.getContent();
                if (!(obj instanceof StreamSource)) {
                    fail("Got incorrect attachment type [" + obj.getClass() + "], " +
                         "expected [javax.xml.transform.stream.StreamSource]");
                }
            }
        }

    }
 
Example 6
Source File: SaajEmptyNamespaceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
    String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage msg = mFactory.createMessage();
    msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
    return msg;
}
 
Example 7
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
    String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage msg = mFactory.createMessage();
    msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
    return msg;
}
 
Example 8
Source File: MailTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void addSoapAttachement() {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        AttachmentPart a = message.createAttachmentPart();
        a.setContentType("binary/octet-stream");
        message.addAttachmentPart(a);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: ArcherAuthenticatingRestConnection.java    From FortifyBugTrackerUtility with MIT License 5 votes vote down vote up
public Long addValueToValuesList(Long valueListId, String value) {
	LOG.info("[Archer] Adding value '"+value+"' to value list id "+valueListId);
	// Adding items to value lists is not supported via REST API, so we need to revert to SOAP API
	// TODO Simplify this method?
	// TODO Make this method more fail-safe (like checking for the correct response element)?
	Long result = null;
	try {
		MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody body = envelope.getBody();
        SOAPElement bodyElement = body.addChildElement(envelope.createName("CreateValuesListValue", "", "http://archer-tech.com/webservices/"));
        bodyElement.addChildElement("sessionToken").addTextNode(tokenProviderRest.getToken());
        bodyElement.addChildElement("valuesListId").addTextNode(valueListId+"");
        bodyElement.addChildElement("valuesListValueName").addTextNode(value);
        message.saveChanges();
 
        SOAPMessage response = executeRequest(HttpMethod.POST, 
        		getBaseResource().path("/ws/field.asmx")
        		.request()
        		.header("SOAPAction", "\"http://archer-tech.com/webservices/CreateValuesListValue\"")
        		.accept("text/xml"),
        		Entity.entity(message, "text/xml"), SOAPMessage.class);
        @SuppressWarnings("unchecked")
		Iterator<Object> it = response.getSOAPBody().getChildElements();
        while (it.hasNext()){
        	Object o = it.next();
        	if ( o instanceof SOAPElement ) {	
        		result = new Long(((SOAPElement)o).getTextContent());
        	}
          }
        System.out.println(response);
	} catch (SOAPException e) {
		throw new RuntimeException("Error executing SOAP request", e);
	}
	return result;
}
 
Example 10
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
    String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage msg = mFactory.createMessage();
    msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
    return msg;
}
 
Example 11
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
    String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage msg = mFactory.createMessage();
    msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
    return msg;
}
 
Example 12
Source File: MailTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void addSoapAttachement() {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        AttachmentPart a = message.createAttachmentPart();
        a.setContentType("binary/octet-stream");
        message.addAttachmentPart(a);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
}
 
Example 13
Source File: SaajEmptyNamespaceTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
    String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage msg = mFactory.createMessage();
    msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
    return msg;
}
 
Example 14
Source File: SaajEmptyNamespaceTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
    String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage msg = mFactory.createMessage();
    msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
    return msg;
}
 
Example 15
Source File: SAAJFactory.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
* Creates a new <code>MessageFactory</code> object that is an instance
* of the specified implementation.  May be a dynamic message factory,
* a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
* message factory creates messages based on the MIME headers specified
* as arguments to the <code>createMessage</code> method.
*
* This method uses the SAAJMetaFactory to locate the implementation class
* and create the MessageFactory instance.
*
* @return a new instance of a <code>MessageFactory</code>
*
* @param protocol  a string constant representing the class of the
*                   specified message factory implementation. May be
*                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
*                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
*                   as) <code>SOAP_1_1_PROTOCOL</code>, or
*                   <code>SOAP_1_2_PROTOCOL</code>.
*
* @exception SOAPException if there was an error in creating the
*            specified implementation of  <code>MessageFactory</code>.
* @see SAAJMetaFactory
*/
   public MessageFactory createMessageFactory(String protocol) throws SOAPException {
           return MessageFactory.newInstance(protocol);
   }
 
Example 16
Source File: SAAJFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
* Creates a new <code>MessageFactory</code> object that is an instance
* of the specified implementation.  May be a dynamic message factory,
* a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
* message factory creates messages based on the MIME headers specified
* as arguments to the <code>createMessage</code> method.
*
* This method uses the SAAJMetaFactory to locate the implementation class
* and create the MessageFactory instance.
*
* @return a new instance of a <code>MessageFactory</code>
*
* @param protocol  a string constant representing the class of the
*                   specified message factory implementation. May be
*                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
*                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
*                   as) <code>SOAP_1_1_PROTOCOL</code>, or
*                   <code>SOAP_1_2_PROTOCOL</code>.
*
* @exception SOAPException if there was an error in creating the
*            specified implementation of  <code>MessageFactory</code>.
* @see SAAJMetaFactory
*/
   public MessageFactory createMessageFactory(String protocol) throws SOAPException {
           return MessageFactory.newInstance(protocol);
   }
 
Example 17
Source File: SAAJFactory.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
* Creates a new <code>MessageFactory</code> object that is an instance
* of the specified implementation.  May be a dynamic message factory,
* a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
* message factory creates messages based on the MIME headers specified
* as arguments to the <code>createMessage</code> method.
*
* This method uses the SAAJMetaFactory to locate the implementation class
* and create the MessageFactory instance.
*
* @return a new instance of a <code>MessageFactory</code>
*
* @param protocol  a string constant representing the class of the
*                   specified message factory implementation. May be
*                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
*                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
*                   as) <code>SOAP_1_1_PROTOCOL</code>, or
*                   <code>SOAP_1_2_PROTOCOL</code>.
*
* @exception SOAPException if there was an error in creating the
*            specified implementation of  <code>MessageFactory</code>.
* @see SAAJMetaFactory
*/
   public MessageFactory createMessageFactory(String protocol) throws SOAPException {
           return MessageFactory.newInstance(protocol);
   }
 
Example 18
Source File: SAAJFactory.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
* Creates a new <code>MessageFactory</code> object that is an instance
* of the specified implementation.  May be a dynamic message factory,
* a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
* message factory creates messages based on the MIME headers specified
* as arguments to the <code>createMessage</code> method.
*
* This method uses the SAAJMetaFactory to locate the implementation class
* and create the MessageFactory instance.
*
* @return a new instance of a <code>MessageFactory</code>
*
* @param protocol  a string constant representing the class of the
*                   specified message factory implementation. May be
*                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
*                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
*                   as) <code>SOAP_1_1_PROTOCOL</code>, or
*                   <code>SOAP_1_2_PROTOCOL</code>.
*
* @exception SOAPException if there was an error in creating the
*            specified implementation of  <code>MessageFactory</code>.
* @see SAAJMetaFactory
*/
   public MessageFactory createMessageFactory(String protocol) throws SOAPException {
           return MessageFactory.newInstance(protocol);
   }
 
Example 19
Source File: SAAJFactory.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
* Creates a new <code>MessageFactory</code> object that is an instance
* of the specified implementation.  May be a dynamic message factory,
* a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
* message factory creates messages based on the MIME headers specified
* as arguments to the <code>createMessage</code> method.
*
* This method uses the SAAJMetaFactory to locate the implementation class
* and create the MessageFactory instance.
*
* @return a new instance of a <code>MessageFactory</code>
*
* @param protocol  a string constant representing the class of the
*                   specified message factory implementation. May be
*                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
*                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
*                   as) <code>SOAP_1_1_PROTOCOL</code>, or
*                   <code>SOAP_1_2_PROTOCOL</code>.
*
* @exception SOAPException if there was an error in creating the
*            specified implementation of  <code>MessageFactory</code>.
* @see SAAJMetaFactory
*/
   public MessageFactory createMessageFactory(String protocol) throws SOAPException {
           return MessageFactory.newInstance(protocol);
   }
 
Example 20
Source File: SAAJFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
* Creates a new <code>MessageFactory</code> object that is an instance
* of the specified implementation.  May be a dynamic message factory,
* a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
* message factory creates messages based on the MIME headers specified
* as arguments to the <code>createMessage</code> method.
*
* This method uses the SAAJMetaFactory to locate the implementation class
* and create the MessageFactory instance.
*
* @return a new instance of a <code>MessageFactory</code>
*
* @param protocol  a string constant representing the class of the
*                   specified message factory implementation. May be
*                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
*                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
*                   as) <code>SOAP_1_1_PROTOCOL</code>, or
*                   <code>SOAP_1_2_PROTOCOL</code>.
*
* @exception SOAPException if there was an error in creating the
*            specified implementation of  <code>MessageFactory</code>.
* @see SAAJMetaFactory
*/
   public MessageFactory createMessageFactory(String protocol) throws SOAPException {
           return MessageFactory.newInstance(protocol);
   }