List of usage examples for javax.xml.soap SOAPMessage getSOAPBody
public SOAPBody getSOAPBody() throws SOAPException
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyVisibleNamespaces_soapDom_targetMatch() throws Exception { String xml = "<part xmlns:produce='urn:example:produce'>" + " <lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:fish='urn:example:fish' xmlns='urn:example:meal'/>" + "</part>"; Element source = XmlUtil.getElement(XmlUtil.parseText(xml), "urn:example:meal", "lunch"); String targetXml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body>" + " <other:Operation xmlns:produce='urn:example:produce' xmlns:meal='urn:example:meal'" + " xmlns:other='urn:example:other'>" + " <lunch />" + " </other:Operation>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(targetXml); SOAPElement operation = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:other", "Operation"); SOAPElement target = SoapUtil.getElement(operation, "lunch"); // in the WS4EE stack, target contains the *visible* namespace after parsing target.removeNamespaceDeclaration("produce"); target.removeNamespaceDeclaration("meal"); // perform the copy SoapUtil.copyVisibleNamespaces(target, source); List prefixes = IteratorUtils.toList(target.getNamespacePrefixes()); // prefixed declaration assertTrue(prefixes.contains("fish")); assertEquals("urn:example:fish", target.getNamespaceURI("fish")); // parent prefixed declaration assertFalse(prefixes.contains("produce")); assertEquals("urn:example:produce", target.getNamespaceURI("produce")); // default declaration (reassigned) assertFalse(prefixes.contains("meal")); assertEquals("urn:example:meal", target.getNamespaceURI("meal")); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildElement_soapDom() throws Exception { String xml = "<meal:lunch xmlns:meal='urn:example:meal'>" + " <padding />" + "</meal:lunch>"; Element source = XmlUtil.parseText(xml); SOAPMessage message = MessageFactory.newInstance().createMessage(); SOAPElement parent = message.getSOAPBody().addChildElement("lunch", "meal", "urn:example:meal"); // perform the copy SoapUtil.copyChildElement(parent, XmlUtil.getElement(source, "padding")); SOAPElement padding = SoapUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix());//ww w . j ava2s.c om // reload message = writeAndRead(message); parent = SoapUtil.getElement(message.getSOAPBody(), "urn:example:meal", "lunch"); padding = SoapUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyAttributes_domSoap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:fish='urn:example:fish'>" + " <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch"); Element target = XmlUtil.createElement("detail"); // perform the copy SoapUtil.copyAttributes(target, source); // qualified attributes assertEquals("0.1lb", target.getAttributeNS("urn:example:produce", "lettuce")); assertEquals("0.25lb", target.getAttributeNS("urn:example:fish", "fillet")); // local attribute assertEquals("1200", target.getAttribute("time")); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyNamespaces_domSoap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:produce='urn:example:produce'>" + " <meal:lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:fish='urn:example:fish' xmlns:meal='urn:example:meal'/>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); Element target = XmlUtil.createElement("detail"); // perform the copy SoapUtil.copyNamespaces(target, source); // prefixed declaration assertEquals("urn:example:fish", XmlUtil.getNamespaceURI("fish", target)); assertEquals("urn:example:meal", XmlUtil.getNamespaceURI("meal", target)); // parent prefixed declaration assertNull(XmlUtil.getNamespaceURI("produce", target)); assertNull(XmlUtil.getNamespaceURI("soap", target)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyVisibleNamespaces_domSoap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:produce='urn:example:produce'>" + " <meal:lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' xmlns=''" + " xmlns:fish='urn:example:fish' xmlns:meal='urn:example:meal'/>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); Element target = XmlUtil.createElement("detail"); // perform the copy SoapUtil.copyVisibleNamespaces(target, source); // prefixed declaration assertEquals("urn:example:fish", XmlUtil.getNamespaceURI("fish", target)); assertEquals("urn:example:meal", XmlUtil.getNamespaceURI("meal", target)); // parent prefixed declaration assertEquals("urn:example:produce", XmlUtil.getNamespaceURI("produce", target)); assertEquals(SOAPConstants.URI_NS_SOAP_ENVELOPE, XmlUtil.getNamespaceURI("soap", target)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyVisibleNamespaces_domSoap_targetMatch() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:produce='urn:example:produce'>" + " <meal:lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:fish='urn:example:fish' xmlns:meal='urn:example:meal'/>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); String targetXml = "<detail xmlns:produce='urn:example:produce'>" + " <other:target xmlns:other='urn:example:other'/>" + "</detail>"; Element target = XmlUtil.getElement(XmlUtil.parseText(targetXml), "urn:example:other", "target"); // perform the copy SoapUtil.copyVisibleNamespaces(target, source); // prefixed declaration assertEquals("urn:example:fish", target.getAttributeNS(BpelConstants.NS_XMLNS, "fish")); assertEquals("urn:example:meal", target.getAttributeNS(BpelConstants.NS_XMLNS, "meal")); // parent prefixed declaration assertNull(target.getAttributeNodeNS(BpelConstants.NS_XMLNS, "produce")); assertEquals(SOAPConstants.URI_NS_SOAP_ENVELOPE, target.getAttributeNS(BpelConstants.NS_XMLNS, "soap")); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildNodes_domSoap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:fish='urn:example:fish'>" + " <meal:lunch xmlns:produce='urn:example:produce'" + " xmlns:meal='urn:example:meal'>" + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>" + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " </meal:lunch>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); Element target = XmlUtil.createElement("detail"); // perform the copy SoapUtil.copyChildNodes(target, source); // local element Element time = XmlUtil.getElement(target, "time"); assertNull(time.getPrefix());/*w w w .j a v a2s . c o m*/ // qualified, prefixed element Element lettuce = XmlUtil.getElement(target, "urn:example:produce", "lettuce"); assertEquals("produce", lettuce.getPrefix()); // parent qualified, prefixed element Element fillet = XmlUtil.getElement(target, "urn:example:fish", "fillet"); assertEquals("fish", fillet.getPrefix()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testGetPrefix_soap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:produce='urn:example:produce'>" + " <meal:lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' xmlns=''" + " xmlns:fish='urn:example:fish' xmlns:meal='urn:example:meal'/>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement elem = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); // prefixed declaration assertEquals("fish", SoapUtil.getPrefix("urn:example:fish", elem)); assertEquals("meal", SoapUtil.getPrefix("urn:example:meal", elem)); // parent prefixed declaration assertEquals("produce", SoapUtil.getPrefix("urn:example:produce", elem)); assertEquals("soap", SoapUtil.getPrefix(SOAPConstants.URI_NS_SOAP_ENVELOPE, elem)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopy_soapDom_noOverride() throws Exception { String xml = "<part xmlns:produce='urn:example:produce'>" + " <lunch produce:lettuce='0.1lb' fish:fillet='0.25lb'" + " xmlns:fish='urn:example:fish' xmlns='urn:example:meal'/>" + "</part>"; Element source = XmlUtil.parseText(xml); /*//from w ww .j a va 2 s.c o m * here, notice the 'urn:example:meal' namespace (the default namespace in the source) is mapped * to prefix 'fish' which the source maps to namespace 'urn:example:fish' */ // <soap:Envelope xmlns:soap='${SOAPConstants.URI_NS_SOAP_ENVELOPE}'> // <soap:Body>" // <fish:Operation xmlns:fish='urn:example:meal'> // <part /> // </fish:Operation> // </soap:Body>" // </soap:Envelope> SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPElement operation = soapMessage.getSOAPBody().addChildElement("Operation", "fish", "urn:example:meal"); SOAPElement part = SoapUtil.addChildElement(operation, "part"); // perform the copy SoapUtil.copy(part, source); soapMessage = writeAndRead(soapMessage); // retrieve relevant elements operation = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "Operation"); part = SoapUtil.getElement(operation, "part"); SOAPElement lunch = SoapUtil.getElement(part, "urn:example:meal", "lunch"); // prefixed declaration assertEquals("urn:example:fish", lunch.getNamespaceURI("fish")); // parent prefixed declaration assertEquals("urn:example:produce", lunch.getNamespaceURI("produce")); // default declaration (reassigned) assertEquals("urn:example:meal", lunch.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopy_domSoap_qualifiedNoPrefix() throws Exception { String xml = "<soapenv:Envelope xmlns:soapenv='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soapenv:Body>" + " <response xmlns='" + BpelConstants.NS_EXAMPLES + "'>" + " <return>" + " <amount>0.0</amount>" + " <branch>140</branch>" + " <capital>10419.18</capital>" + " <status>1</status>" + " <transaction xmlns:xsi='" + BpelConstants.NS_XML_SCHEMA_INSTANCE + "' xsi:nil='true'/>" + " </return>" + " </response>" + " </soapenv:Body>" + "</soapenv:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), BpelConstants.NS_EXAMPLES, "response"); Element target = XmlUtil.createElement("detail"); // perform the copy SoapUtil.copy(target, source);/* w w w . j a va 2 s . co m*/ target = XmlUtilTest.writeAndRead(target); // namespaces assertEquals(SOAPConstants.URI_NS_SOAP_ENVELOPE, target.getAttributeNS(BpelConstants.NS_XMLNS, "soapenv")); // child elements Element returnElem = XmlUtil.getElement(target, BpelConstants.NS_EXAMPLES, "return"); // namespaces assertEquals(BpelConstants.NS_EXAMPLES, returnElem.getAttributeNS(BpelConstants.NS_XMLNS, "xmlns")); // child elements assertEquals("0.0", DatatypeUtil.toString(XmlUtil.getElement(returnElem, BpelConstants.NS_EXAMPLES, "amount"))); assertEquals("140", DatatypeUtil.toString(XmlUtil.getElement(returnElem, BpelConstants.NS_EXAMPLES, "branch"))); assertEquals("10419.18", DatatypeUtil.toString(XmlUtil.getElement(returnElem, BpelConstants.NS_EXAMPLES, "capital"))); assertEquals("1", DatatypeUtil.toString(XmlUtil.getElement(returnElem, BpelConstants.NS_EXAMPLES, "status"))); Element transactionElem = XmlUtil.getElement(returnElem, BpelConstants.NS_EXAMPLES, "transaction"); // namespaces assertEquals(BpelConstants.NS_XML_SCHEMA_INSTANCE, transactionElem.getAttributeNS(BpelConstants.NS_XMLNS, "xsi")); // attributes assertEquals("true", transactionElem.getAttributeNS(BpelConstants.NS_XML_SCHEMA_INSTANCE, "nil")); }