use of jakarta.xml.soap.SOAPPart in project openmq by eclipse-ee4j.
the class SOAPtoJMSServlet method generateResponseMessage.
/**
* Add a MessageStatus element with the value of "published" to
* the soapMessage.
*/
public SOAPMessage generateResponseMessage(SOAPMessage soapMessage) {
try {
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody soapBody = envelope.getBody();
soapBody.addChildElement("MessageStatus").addTextNode("published");
soapMessage.saveChanges();
} catch (SOAPException soape) {
soape.printStackTrace();
}
return soapMessage;
}
use of jakarta.xml.soap.SOAPPart in project openmq by eclipse-ee4j.
the class SendSOAPMessage method sendMessage.
/**
* send a simple soap message with JAXM API.
*/
public void sendMessage(String url) {
try {
/**
* Construct a default SOAP message factory.
*/
MessageFactory mf = MessageFactory.newInstance();
/**
* Create a SOAP message object.
*/
SOAPMessage soapMessage = mf.createMessage();
/**
* Get SOAP part.
*/
SOAPPart soapPart = soapMessage.getSOAPPart();
/**
* Get SOAP envelope.
*/
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
/**
* Get SOAP body.
*/
SOAPBody soapBody = soapEnvelope.getBody();
/**
* Add child element with the specified name.
*/
SOAPElement element = soapBody.addChildElement("HelloWorld");
/**
* Add text message
*/
element.addTextNode("Welcome to SunOne Web Services!");
soapMessage.saveChanges();
/**
* Construct a default SOAP connection factory.
*/
SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
/**
* Get SOAP connection.
*/
SOAPConnection soapConnection = connectionFactory.createConnection();
/**
* Send SOAP message.
*/
SOAPMessage resp = soapConnection.call(soapMessage, url);
/**
* Print response to the std output.
*/
resp.writeTo(System.out);
/**
* close the connection
*/
soapConnection.close();
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
} catch (SOAPException soape) {
soape.printStackTrace();
}
}
use of jakarta.xml.soap.SOAPPart in project openmq by eclipse-ee4j.
the class SendSOAPMessageWithJMS method send.
/**
* Send SOAP message with JMS API.
*/
public void send() throws Exception {
/**
* Construct a default SOAP message factory.
*/
MessageFactory mf = MessageFactory.newInstance();
/**
* Create a SOAP message object.
*/
SOAPMessage soapMessage = mf.createMessage();
/**
* Get SOAP part.
*/
SOAPPart soapPart = soapMessage.getSOAPPart();
/**
* Get SOAP envelope.
*/
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
/**
* Get SOAP body.
*/
SOAPBody soapBody = soapEnvelope.getBody();
/**
* Create a name object. with name space http://www.sun.com/imq.
*/
Name name = soapEnvelope.createName("HelloWorld", "hw", "http://www.sun.com/imq");
/**
* Add child element with the above name.
*/
SOAPElement element = soapBody.addChildElement(name);
/**
* Add another child element.
*/
element.addTextNode("Welcome to SunOne Web Services.");
/**
* Create an atachment with activation API.
*/
URL url = new URL("https://projects.eclipse.org/projects/ee4j.openmq/contact");
DataHandler dh = new DataHandler(url);
AttachmentPart ap = soapMessage.createAttachmentPart(dh);
/**
* set content type/ID.
*/
ap.setContentType("text/html");
ap.setContentId("cid-001");
/**
* add the attachment to the SOAP message.
*/
soapMessage.addAttachmentPart(ap);
soapMessage.saveChanges();
/**
* Convert SOAP to JMS message.
*/
Message message = MessageTransformer.SOAPMessageIntoJMSMessage(soapMessage, session);
/**
* publish JMS message.
*/
msgProducer.send(message);
}
use of jakarta.xml.soap.SOAPPart in project metro-jax-ws by eclipse-ee4j.
the class SimpleHandler method doSomeWork.
protected void doSomeWork(SOAPMessageContext context) {
if (dosomething) {
try {
SOAPMessage message = context.getMessage();
SOAPPart sp = message.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
} catch (SOAPException e) {
e.printStackTrace();
}
}
}
Aggregations