use of jakarta.xml.soap.SOAPBody in project tomee by apache.
the class Increment method handleMessage.
public boolean handleMessage(SOAPMessageContext mc) {
try {
final SOAPMessage message = mc.getMessage();
final SOAPBody body = message.getSOAPBody();
final String localName = body.getFirstChild().getLocalName();
if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
final Node responseNode = body.getFirstChild();
final Node returnNode = responseNode.getFirstChild();
final Node intNode = returnNode.getFirstChild();
final int value = new Integer(intNode.getNodeValue());
intNode.setNodeValue(Integer.toString(value + 1));
}
return true;
} catch (SOAPException e) {
return false;
}
}
use of jakarta.xml.soap.SOAPBody 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.SOAPBody 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.SOAPBody in project openmq by eclipse-ee4j.
the class UMSService method createSOAPFaultMessage.
/**
* Create a soap fault message and set its error code and error string as specified in the parameter.
*/
public static SOAPMessage createSOAPFaultMessage(Throwable t, String faultCode, String faultString) {
SOAPMessage soapFault = null;
try {
MessageFactory mf = MessageFactory.newInstance();
soapFault = mf.createMessage();
SOAPEnvelope env = soapFault.getSOAPPart().getEnvelope();
SOAPBody body = env.getBody();
SOAPFault faultElement = body.addFault();
String soapNs = env.getElementName().getPrefix();
String fcode = soapNs + ":" + faultCode;
faultElement.setFaultCode(fcode);
faultElement.setFaultString(faultString);
Detail detail = faultElement.getDetail();
if (detail == null) {
detail = faultElement.addDetail();
}
Name stname = MessageUtil.createJMSName("StackTrace");
SOAPElement entryEle = detail.addDetailEntry(stname);
// get stack trace
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
t.printStackTrace(ps);
ps.close();
String trace = baos.toString("utf8");
entryEle.setValue(trace);
soapFault.saveChanges();
} catch (Exception e) {
e.printStackTrace();
}
return soapFault;
}
use of jakarta.xml.soap.SOAPBody in project eclipselink by eclipse-ee4j.
the class SOAPResponseWriter method generateResponse.
public SOAPMessage generateResponse(Operation op, boolean useSOAP12, Object result) throws SOAPException {
MessageFactory messageFactory = null;
if (useSOAP12) {
messageFactory = MessageFactory.newInstance(SOAP_1_2_PROTOCOL);
} else {
messageFactory = MessageFactory.newInstance();
}
SOAPMessage message = messageFactory.createMessage();
message.getSOAPPart().getEnvelope().addNamespaceDeclaration(SCHEMA_PREFIX, W3C_XML_SCHEMA_NS_URI);
message.getSOAPPart().getEnvelope().addNamespaceDeclaration(SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI);
SOAPBody body = message.getSOAPPart().getEnvelope().getBody();
XMLDescriptor descriptor = resultDescriptors.get(op.getName());
SOAPResponse response = null;
try {
@SuppressWarnings({ "unchecked" }) Class<? extends SOAPResponse> cls = descriptor.getJavaClass();
response = cls.getConstructor().newInstance();
} catch (ReflectiveOperationException ie) {
throw new SOAPException(ie);
}
response.setResult(result);
SOAPAttachmentHandler attachmentHandler = new SOAPAttachmentHandler();
XMLMarshaller marshaller = dbwsAdapter.getXMLContext().createMarshaller();
marshaller.setAttachmentMarshaller(attachmentHandler);
marshaller.marshal(response, body);
if (attachmentHandler.hasAttachments()) {
// add attachments to message
for (String id : attachmentHandler.getAttachments().keySet()) {
DataHandler attachment = attachmentHandler.getAttachments().get(id);
AttachmentPart part = message.createAttachmentPart(attachment);
part.setContentType(attachment.getContentType());
String contentId = "<" + id.substring(4) + ">";
part.setContentId(contentId);
part.setMimeHeader("Content-Transfer-Encoding", "binary");
message.addAttachmentPart(part);
}
}
message.saveChanges();
return message;
}
Aggregations