List of usage examples for javax.xml.soap MessageFactory newInstance
public static MessageFactory newInstance() throws SOAPException
From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java
private SOAPMessage createSOAPMessage(Element elem) throws Exception { String prefix = "uddi"; MessageFactory msgFactory = MessageFactory.newInstance(); SOAPFactory factory = SOAPFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPPart soapPart = message.getSOAPPart(); SOAPBody soapBody = soapPart.getEnvelope().getBody(); //Create the outer body element String uddins = IRegistry.UDDI_V2_NAMESPACE; Name bodyName = factory.createName(elem.getNodeName(), prefix, uddins); SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName); bodyElement.addNamespaceDeclaration(prefix, uddins); appendAttributes(bodyElement, elem.getAttributes(), factory); appendElements(bodyElement, elem.getChildNodes(), factory); return message; }
From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java
public Element send(Element request, URL endpointURL) throws RegistryException { log.debug("Request message:" + XMLUtils.toString(request)); if ("true".equalsIgnoreCase(debugProp)) System.out.println("Request Element:" + XMLUtils.toString(request)); Element response = null;//ww w . j a v a 2 s . c om try { MessageFactory msgFactory = MessageFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPPart soapPart = message.getSOAPPart(); SOAPBody soapBody = soapPart.getEnvelope().getBody(); soapBody.addChildElement(getSOAPElement(soapBody, request)); //There seems to be a bug in the Saaj/Axis implementation that requires //message to be written to an output stream ByteArrayOutputStream by = new ByteArrayOutputStream(); message.writeTo(by); //Does not do anything by.close(); if ("true".equalsIgnoreCase(debugProp)) message.writeTo(System.out); //Make the SAAJ Call now SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); SOAPMessage soapResponse = connection.call(message, endpointURL); if ("true".equalsIgnoreCase(debugProp)) { System.out.println("Response is:"); soapResponse.writeTo(System.out); } soapBody = soapResponse.getSOAPBody(); boolean hasFault = soapBody.hasFault(); if (hasFault) { SOAPFault soapFault = soapBody.getFault(); String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString(); throw new RegistryException(faultStr); } response = getFirstChildElement(soapBody); } catch (Exception ex) { ex.printStackTrace(); log.error(ex); throw new RegistryException(ex); } log.debug("Response message:" + XMLUtils.getText(response)); return response; }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testRemoveAttributes_soap() 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>"; ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes()); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream); SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch"); // remove the attributes SoapUtil.removeAttributes(element);//from www . j a va2s . co m // verify remotion with the dom & saaj apis assertFalse(element.hasAttribute("time")); assertFalse(element.hasAttributeNS("urn:example:produce", "lettuce")); assertFalse(element.hasAttributeNS("urn:example:fish", "fillet")); // namespaces should still be there // prefixed declaration assertEquals("produce", SoapUtil.getPrefix("urn:example:produce", element)); // parent prefixed declaration assertEquals("fish", SoapUtil.getPrefix("urn:example:fish", element)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testRemoveChildNodes_soap() 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>"; ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes()); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream); SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); // remove the child nodes element.removeContents();//from www .j a v a 2 s.co m // verify remotion assertFalse(element.getChildElements().hasNext()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testRemoveNamespaces_soap() 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>"; ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes()); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream); SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch"); // remove namespaces SoapUtil.removeNamespaces(element);//w w w. java 2 s.c o m // verify remotion assertFalse(element.getNamespacePrefixes().hasNext()); // attributes should still be there // qualified attributes assertEquals("0.1lb", element.getAttributeNS("urn:example:produce", "lettuce")); assertEquals("0.25lb", element.getAttributeNS("urn:example:fish", "fillet")); // local attribute assertEquals("1200", element.getAttribute("time")); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildNodes_soapDom() throws Exception { String xml = "<lunch xmlns:produce='urn:example:produce'" + " xmlns='urn:example:meal'>" + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>" + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " <padding xmlns=''/>" + "</lunch>"; Element source = XmlUtil.parseText(xml); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail")); // perform the copy SoapUtil.copyChildNodes(target, source); // qualified, prefixless element SOAPElement time = SoapUtil.getElement(target, "urn:example:meal", "time"); assertEquals(SoapUtil.DEFAULT_NAMESPACE_PREFIX, time.getPrefix()); // qualified, prefixed element SOAPElement lettuce = SoapUtil.getElement(target, "urn:example:produce", "lettuce"); assertEquals("produce", lettuce.getPrefix()); // parent qualified, prefixed element SOAPElement fillet = SoapUtil.getElement(target, "urn:example:fish", "fillet"); assertEquals("fish", fillet.getPrefix()); // local element SOAPElement padding = SoapUtil.getElement(target, "padding"); assertNull(padding.getPrefix());//from w w w . ja va2s. c o m assertNull(padding.getNamespaceURI()); }
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());/*from w ww . j a v a 2 s. co m*/ // 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 testCopyChildElement_domSoap() throws Exception { // <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'> // <padding /> // </meal:lunch> // </soap:Body> // </soap:Envelope> SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); body.addNamespaceDeclaration("fish", "urn:example:fish"); Name lunchName = envelope.createName("lunch", "meal", "urn:example:meal"); SOAPElement lunch = body.addBodyElement(lunchName); lunch.addNamespaceDeclaration("produce", "urn:example:produce"); lunch.addNamespaceDeclaration("meal", "urn:example:meal"); SOAPElement source = SoapUtil.addChildElement(lunch, "padding"); Element parent = XmlUtil.createElement("urn:example:meal", "lunch"); // perform the copy SoapUtil.copyChildElement(parent, source); Element padding = XmlUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix());//from w w w . j a v a2s . c o m // reload // parent = writeAndRead(parent); padding = XmlUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
private static SOAPMessage parseSoap(String xmlString) throws IOException, SOAPException { ByteArrayInputStream sourceStream = new ByteArrayInputStream(xmlString.getBytes()); return MessageFactory.newInstance().createMessage(null, sourceStream); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
private static SOAPMessage writeAndRead(SOAPMessage soapMessage) throws SOAPException, IOException { // write to memory sink ByteArrayOutputStream soapSink = new ByteArrayOutputStream(); soapMessage.writeTo(soapSink);// w w w . jav a 2 s . co m soapSink.writeTo(System.out); System.out.println(); // read from memory source return MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(soapSink.toByteArray())); }