javax.xml.soap.SOAPBodyElement Java Examples
The following examples show how to use
javax.xml.soap.SOAPBodyElement.
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: SoapRequestParser.java From development with Apache License 2.0 | 6 votes |
public static SOAPBodyElement getChildNode(SOAPBodyElement element, String name) throws SOAPException { @SuppressWarnings("unchecked") Iterator<SOAPBodyElement> elements = element.getChildElements(); while (elements.hasNext()) { SOAPBodyElement childNode = elements.next(); if (childNode.getNodeName().contains(name)) { return childNode; } } throw new SOAPException("Child element: " + name + " not found."); }
Example #2
Source File: BodyImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public SOAPBodyElement addBodyElement(Name name) throws SOAPException { SOAPBodyElement newBodyElement = (SOAPBodyElement) ElementFactory.createNamedElement( ((SOAPDocument) getOwnerDocument()).getDocument(), name.getLocalName(), name.getPrefix(), name.getURI()); if (newBodyElement == null) { newBodyElement = createBodyElement(name); } addNode(newBodyElement); return newBodyElement; }
Example #3
Source File: BodyImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public SOAPBodyElement addBodyElement(QName qname) throws SOAPException { SOAPBodyElement newBodyElement = (SOAPBodyElement) ElementFactory.createNamedElement( ((SOAPDocument) getOwnerDocument()).getDocument(), qname.getLocalPart(), qname.getPrefix(), qname.getNamespaceURI()); if (newBodyElement == null) { newBodyElement = createBodyElement(qname); } addNode(newBodyElement); return newBodyElement; }
Example #4
Source File: BodyImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override protected SOAPElement convertToSoapElement(Element element) { final Node soapNode = getSoapDocument().findIfPresent(element); if ((soapNode instanceof SOAPBodyElement) && //this check is required because ElementImpl currently // implements SOAPBodyElement !(soapNode.getClass().equals(ElementImpl.class))) { return (SOAPElement) soapNode; } else { return replaceElementWithSOAPElement( element, (ElementImpl) createBodyElement(NameImpl .copyElementName(element))); } }
Example #5
Source File: MdwRpcWebServiceAdapter.java From mdw with Apache License 2.0 | 5 votes |
/** * Populate the SOAP request message. */ protected SOAPMessage createSoapRequest(Object requestObj) throws ActivityException { try { MessageFactory messageFactory = getSoapMessageFactory(); SOAPMessage soapMessage = messageFactory.createMessage(); Map<Name,String> soapReqHeaders = getSoapRequestHeaders(); if (soapReqHeaders != null) { SOAPHeader header = soapMessage.getSOAPHeader(); for (Name name : soapReqHeaders.keySet()) { header.addHeaderElement(name).setTextContent(soapReqHeaders.get(name)); } } SOAPBody soapBody = soapMessage.getSOAPBody(); Document requestDoc = null; if (requestObj instanceof String) { requestDoc = DomHelper.toDomDocument((String)requestObj); } else { Variable reqVar = getProcessDefinition().getVariable(getAttributeValue(REQUEST_VARIABLE)); XmlDocumentTranslator docRefTrans = (XmlDocumentTranslator)getPackage().getTranslator(reqVar.getType()); requestDoc = docRefTrans.toDomDocument(requestObj); } SOAPBodyElement bodyElem = soapBody.addBodyElement(getOperation()); String requestLabel = getRequestLabelPartName(); if (requestLabel != null) { SOAPElement serviceNameElem = bodyElem.addChildElement(requestLabel); serviceNameElem.addTextNode(getRequestLabel()); } SOAPElement requestDetailsElem = bodyElem.addChildElement(getRequestPartName()); requestDetailsElem.addTextNode("<![CDATA[" + DomHelper.toXml(requestDoc) + "]]>"); return soapMessage; } catch (Exception ex) { throw new ActivityException(ex.getMessage(), ex); } }
Example #6
Source File: SoapRequestParser.java From development with Apache License 2.0 | 5 votes |
public static SOAPBodyElement getServiceParam(SOAPMessageContext context, String serviceName, String paramName) throws SOAPException { SOAPMessage soapMessage = context.getMessage(); SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); @SuppressWarnings("unchecked") Iterator<SOAPBodyElement> elements = soapBody.getChildElements(); while (elements.hasNext()) { SOAPBodyElement element = elements.next(); if (element.getNodeName().contains(serviceName)) { @SuppressWarnings("unchecked") Iterator<SOAPBodyElement> params = element.getChildElements(); while (params.hasNext()) { SOAPBodyElement param = params.next(); if (paramName.equals(param.getNodeName())) { return param; } } } } throw new SOAPException("Soap message param " + paramName + " not found."); }
Example #7
Source File: SAAJTestServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 5 votes |
private static void assertSOAPBodiesAreEqual(SOAPMessage expected, SOAPMessage actual) throws Exception { SOAPBody expectedBody = expected.getSOAPBody(); SOAPBody actualBody = actual.getSOAPBody(); SOAPBodyElement expectedElement = (SOAPBodyElement) expectedBody.getChildElements().next(); SOAPBodyElement actualElement = (SOAPBodyElement) actualBody.getChildElements().next(); String expectedQN = expectedElement.getElementQName().toString(); String actualQN = actualElement.getElementQName().toString(); assertEquals(expectedQN, actualQN); }
Example #8
Source File: Tr064Comm.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Sets all required namespaces and prepares the SOAP message to send. * Creates skeleton + body data. * * @param bodyData * is attached to skeleton to form entire SOAP message * @return ready to send SOAP message */ private SOAPMessage constructTr064Msg(SOAPBodyElement bodyData) { SOAPMessage soapMsg = null; try { MessageFactory msgFac; msgFac = MessageFactory.newInstance(); soapMsg = msgFac.createMessage(); soapMsg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); soapMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8"); SOAPPart part = soapMsg.getSOAPPart(); // valid for entire SOAP msg String namespace = "s"; // create suitable fbox envelope SOAPEnvelope envelope = part.getEnvelope(); envelope.setPrefix(namespace); envelope.removeNamespaceDeclaration("SOAP-ENV"); // delete standard namespace which was already set envelope.addNamespaceDeclaration(namespace, "http://schemas.xmlsoap.org/soap/envelope/"); Name nEncoding = envelope.createName("encodingStyle", namespace, "http://schemas.xmlsoap.org/soap/encoding/"); envelope.addAttribute(nEncoding, "http://schemas.xmlsoap.org/soap/encoding/"); // create empty header SOAPHeader header = envelope.getHeader(); header.setPrefix(namespace); // create body with command based on parameter SOAPBody body = envelope.getBody(); body.setPrefix(namespace); body.addChildElement(bodyData); // bodyData already prepared. Needs only be added } catch (Exception e) { logger.error("Error creating SOAP message for fbox request with data {}", bodyData); e.printStackTrace(); } return soapMsg; }
Example #9
Source File: SAAJTestServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 4 votes |
/** * 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); }
Example #10
Source File: TestMtomProviderImpl.java From cxf with Apache License 2.0 | 4 votes |
public SOAPMessage invoke(final SOAPMessage request) { try { System.out.println("=== Received client request ==="); // create the SOAPMessage SOAPMessage message = MessageFactory.newInstance().createMessage(); SOAPPart part = message.getSOAPPart(); SOAPEnvelope envelope = part.getEnvelope(); SOAPBody body = envelope.getBody(); SOAPBodyElement testResponse = body .addBodyElement(envelope.createName("testXopResponse", null, "http://cxf.apache.org/mime/types")); SOAPElement name = testResponse.addChildElement("name", null, "http://cxf.apache.org/mime/types"); name.setTextContent("return detail + call detail"); SOAPElement attachinfo = testResponse.addChildElement( "attachinfo", null, "http://cxf.apache.org/mime/types"); SOAPElement include = attachinfo.addChildElement("Include", "xop", "http://www.w3.org/2004/08/xop/include"); int fileSize = 0; try (InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl")) { for (int i = pre.read(); i != -1; i = pre.read()) { fileSize++; } } int count = 50; byte[] data = new byte[fileSize * count]; for (int x = 0; x < count; x++) { this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize); } DataHandler dh = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream")); // create the image attachment AttachmentPart attachment = message.createAttachmentPart(dh); attachment.setContentId("mtom_xop.wsdl"); message.addAttachmentPart(attachment); System.out .println("Adding attachment: " + attachment.getContentId() + ":" + attachment.getSize()); // add the reference to the image attachment include.addAttribute(envelope.createName("href"), "cid:" + attachment.getContentId()); return message; } catch (Exception e) { e.printStackTrace(); } return null; }
Example #11
Source File: BodyImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | votes |
protected abstract SOAPBodyElement createBodyElement(Name name);
Example #12
Source File: BodyImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | votes |
protected abstract SOAPBodyElement createBodyElement(QName name);