Java Code Examples for javax.xml.soap.SOAPFactory#newInstance()
The following examples show how to use
javax.xml.soap.SOAPFactory#newInstance() .
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: ProviderRPCClientServerTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testSWA() throws Exception { SOAPFactory soapFac = SOAPFactory.newInstance(); MessageFactory msgFac = MessageFactory.newInstance(); SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance(); SOAPMessage msg = msgFac.createMessage(); QName sayHi = new QName("http://apache.org/hello_world_rpclit", "sayHiWAttach"); msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi)); AttachmentPart ap1 = msg.createAttachmentPart(); ap1.setContent("Attachment content", "text/plain"); msg.addAttachmentPart(ap1); AttachmentPart ap2 = msg.createAttachmentPart(); ap2.setContent("Attachment content - Part 2", "text/plain"); msg.addAttachmentPart(ap2); msg.saveChanges(); SOAPConnection con = conFac.createConnection(); URL endpoint = new URL("http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1"); SOAPMessage response = con.call(msg, endpoint); QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse"); assertNotNull(response.getSOAPBody().getChildElements(sayHiResp)); assertEquals(2, response.countAttachments()); }
Example 2
Source File: ReferenceParametersAddingHandler.java From cxf with Apache License 2.0 | 6 votes |
@Override public boolean handleMessage(SOAPMessageContext context) { // we are interested only in outbound messages here if (!(Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) { return true; } if (params == null) { return true; } try { SOAPFactory factory = SOAPFactory.newInstance(); for (Object o : params.getAny()) { SOAPElement elm = factory.createElement((Element)o); context.getMessage().getSOAPHeader() .addChildElement(SOAPFactory.newInstance().createElement(elm)); } } catch (SOAPException e) { throw new RuntimeException(e); } return true; }
Example 3
Source File: EchoServiceImpl.java From cxf with Apache License 2.0 | 6 votes |
private SOAPFaultException wrapToSoapFault(Exception ex) throws Exception { SOAPFactory fac = null; try { fac = SOAPFactory.newInstance(); String message = ex.getMessage(); SOAPFault sf = fac.createFault(message, new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Server")); sf.setFaultString("TestSOAPFaultException"); // add detail makes CXF goes in a infinite loop sf.addDetail().addDetailEntry(new QName("urn:echo", "entry")).addTextNode("SOAPFaultException"); return new SOAPFaultException(sf); } catch (Exception e2) { throw e2; } }
Example 4
Source File: AdManagerJaxWsHeaderHandler.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Constructs a SOAP header object ready to be attached to a JAX-WS client. * * @param headerData a map of SOAP header element names to values * @param adManagerServiceDescriptor the descriptor of which service's headers are being created * @return a SOAP header object */ private SOAPElement constructSoapHeader( Map<String, Object> headerData, AdManagerServiceDescriptor adManagerServiceDescriptor) { String requestHeaderNamespace = adManagerApiConfiguration.getNamespacePrefix() + "/" + adManagerServiceDescriptor.getVersion(); try { SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement requestHeader = soapFactory.createElement(REQUEST_HEADER_LOCAL_PART, "ns1", requestHeaderNamespace); for (String headerElementName : headerData.keySet()) { if (headerData.get(headerElementName) != null) { SOAPElement newElement = requestHeader.addChildElement(headerElementName, "ns1", requestHeaderNamespace); newElement.addTextNode(headerData.get(headerElementName).toString()); } } return requestHeader; } catch (SOAPException e) { throw new ServiceException("Unexpected exception.", e); } }
Example 5
Source File: SOAPUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static SOAPFaultException newSOAPFaultException(String reasonText, Throwable cause) { try { SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(); soapFault.setFaultString(reasonText); SOAPFaultException except = new SOAPFaultException(soapFault); except.initCause(cause); return except; } catch (SOAPException ex) { throw new IllegalArgumentException(ex); } }
Example 6
Source File: AdWordsJaxWsHeaderHandler.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Constructs a SOAP header object ready to be attached to a JAX-WS client. * * @param headerData a map of SOAP header element names to values * @param adWordsServiceDescriptor the descriptor of which service's headers * are being created * @return a SOAP header object */ private SOAPElement constructSoapHeader(Map<String, Object> headerData, AdWordsServiceDescriptor adWordsServiceDescriptor) { String requestHeaderNamespace = adWordsApiConfiguration.getNamespacePrefix() + "/" + adWordsServiceDescriptor.getPackageGroup() + "/" + adWordsServiceDescriptor.getVersion(); String requestElementsNamespace = adWordsApiConfiguration.getNamespacePrefix() + "/cm/" + adWordsServiceDescriptor.getVersion(); try { SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement requestHeader = soapFactory.createElement(new QName(requestHeaderNamespace, REQUEST_HEADER_LOCAL_PART)); for (String headerElementName : headerData.keySet()) { if (headerData.get(headerElementName) != null) { SOAPElement newElement = requestHeader.addChildElement(headerElementName, null, requestElementsNamespace); newElement.addTextNode(headerData.get(headerElementName).toString()); } } return requestHeader; } catch (SOAPException e) { throw new ServiceException( "Unexpected exception constructing SOAP header for: " + adWordsServiceDescriptor, e); } }
Example 7
Source File: TreasuryXTeeServiceImpl.java From j-road with Apache License 2.0 | 5 votes |
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { callback.doWithMessage(message); SOAPMessage extractedMessage = SOAPUtil.extractSoapMessage(message); try { Node operation = SOAPUtil.getFirstNonTextChild(extractedMessage.getSOAPBody()); SOAPFactory factory = SOAPFactory.newInstance(); SOAPElement p1 = factory.createElement("p1"); p1.addAttribute(factory.createName("href"), "cid:manus"); operation.appendChild(operation.getOwnerDocument().importNode(p1, true)); } catch (SOAPException e) { throw new RuntimeException(e); } }
Example 8
Source File: AbstractTypeTestClient5.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testStructWithAnyArrayLax() throws Exception { if (!shouldRunTest("StructWithAnyArrayLax")) { return; } SOAPFactory factory = SOAPFactory.newInstance(); SOAPElement elem = factory.createElement("StringElementQualified", "x1", "http://apache.org/type_test/types1"); elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1"); elem.addTextNode("This is the text of the node"); StructWithAnyArrayLax x = new StructWithAnyArrayLax(); x.setName("Name x"); x.setAddress("Some Address x"); x.getAny().add(elem); elem = factory.createElement("StringElementQualified", "x1", "http://apache.org/type_test/types1"); elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1"); elem.addTextNode("This is the text of the node for the second struct"); StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax(); yOrig.setName("Name y"); yOrig.setAddress("Some Other Address y"); yOrig.getAny().add(elem); Holder<StructWithAnyArrayLax> y = new Holder<>(yOrig); Holder<StructWithAnyArrayLax> z = new Holder<>(); StructWithAnyArrayLax ret; if (testDocLiteral) { ret = docClient.testStructWithAnyArrayLax(x, y, z); } else if (testXMLBinding) { ret = xmlClient.testStructWithAnyArrayLax(x, y, z); } else { ret = rpcClient.testStructWithAnyArrayLax(x, y, z); } if (!perfTestOnly) { assertEqualsStructWithAnyArrayLax(x, y.value); assertEqualsStructWithAnyArrayLax(yOrig, z.value); assertEqualsStructWithAnyArrayLax(x, ret); } }
Example 9
Source File: AbstractTypeTestClient5.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testStructWithAnyArrayLaxComplex() throws Exception { if (!shouldRunTest("StructWithAnyArrayLaxComplex")) { return; } SOAPFactory factory = SOAPFactory.newInstance(); SOAPElement elem = factory.createElement("AnonTypeElementQualified", "x1", "http://apache.org/type_test/types1"); elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1"); SOAPElement floatElem = factory.createElement("varFloat", "x1", "http://apache.org/type_test/types1"); floatElem.addTextNode("12.76"); elem.addChildElement(floatElem); SOAPElement intElem = factory.createElement("varInt", "x1", "http://apache.org/type_test/types1"); intElem.addTextNode("56"); elem.addChildElement(intElem); SOAPElement stringElem = factory.createElement("varString", "x1", "http://apache.org/type_test/types1"); stringElem.addTextNode("test string"); elem.addChildElement(stringElem); StructWithAnyArrayLax x = new StructWithAnyArrayLax(); x.setName("Name x"); x.setAddress("Some Address x"); x.getAny().add(elem); StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax(); yOrig.setName("Name y"); yOrig.setAddress("Some Other Address y"); yOrig.getAny().add(elem); Holder<StructWithAnyArrayLax> y = new Holder<>(yOrig); Holder<StructWithAnyArrayLax> z = new Holder<>(); StructWithAnyArrayLax ret; if (testDocLiteral) { ret = docClient.testStructWithAnyArrayLax(x, y, z); } else if (testXMLBinding) { ret = xmlClient.testStructWithAnyArrayLax(x, y, z); } else { ret = rpcClient.testStructWithAnyArrayLax(x, y, z); } if (!perfTestOnly) { assertEqualsStructWithAnyArrayLax(x, y.value); assertEqualsStructWithAnyArrayLax(yOrig, z.value); assertEqualsStructWithAnyArrayLax(x, ret); } }
Example 10
Source File: AbstractTypeTestClient5.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testStructWithAnyStrictComplex() throws Exception { if (!shouldRunTest("StructWithAnyStrictComplex")) { return; } SOAPFactory factory = SOAPFactory.newInstance(); SOAPElement elem = factory.createElement("AnonTypeElementQualified", "x1", "http://apache.org/type_test/types1"); elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1"); SOAPElement floatElem = factory.createElement("varFloat", "x1", "http://apache.org/type_test/types1"); floatElem.addTextNode("12.5"); elem.addChildElement(floatElem); SOAPElement intElem = factory.createElement("varInt", "x1", "http://apache.org/type_test/types1"); intElem.addTextNode("34"); elem.addChildElement(intElem); SOAPElement stringElem = factory.createElement("varString", "x1", "http://apache.org/type_test/types1"); stringElem.addTextNode("test string within any"); elem.addChildElement(stringElem); StructWithAnyStrict x = new StructWithAnyStrict(); x.setName("Name x"); x.setAddress("Some Address x"); x.setAny(elem); elem = factory.createElement("AnonTypeElementQualified", "x1", "http://apache.org/type_test/types1"); elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1"); floatElem = factory.createElement("varFloat", "x1", "http://apache.org/type_test/types1"); floatElem.addTextNode("12.76"); elem.addChildElement(floatElem); intElem = factory.createElement("varInt", "x1", "http://apache.org/type_test/types1"); intElem.addTextNode("56"); elem.addChildElement(intElem); stringElem = factory.createElement("varString", "x1", "http://apache.org/type_test/types1"); stringElem.addTextNode("test string"); elem.addChildElement(stringElem); StructWithAnyStrict yOrig = new StructWithAnyStrict(); yOrig.setName("Name y"); yOrig.setAddress("Some Address y"); yOrig.setAny(elem); Holder<StructWithAnyStrict> y = new Holder<>(yOrig); Holder<StructWithAnyStrict> z = new Holder<>(); StructWithAnyStrict ret; if (testDocLiteral) { ret = docClient.testStructWithAnyStrict(x, y, z); } else if (testXMLBinding) { ret = xmlClient.testStructWithAnyStrict(x, y, z); } else { ret = rpcClient.testStructWithAnyStrict(x, y, z); } if (!perfTestOnly) { assertEqualsStructWithAnyStrict(x, y.value); assertEqualsStructWithAnyStrict(yOrig, z.value); assertEqualsStructWithAnyStrict(x, ret); } }
Example 11
Source File: HWDOMSourcePayloadProvider.java From cxf with Apache License 2.0 | 4 votes |
public DOMSource invoke(DOMSource request) { QName qn = (QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION); if (qn == null) { throw new RuntimeException("No Operation Name"); } DOMSource response = new DOMSource(); Node n = request.getNode(); if (n instanceof Document) { n = ((Document)n).getDocumentElement(); } if (n.getLocalName().equals(sayHi.getLocalPart())) { response.setNode(sayHiResponse); } else if (n.getLocalName().equals(greetMe.getLocalPart())) { Element el = DOMUtils.getFirstElement(n); String s = DOMUtils.getContent(el); if ("throwFault".equals(s.trim())) { try { SOAPFactory f = SOAPFactory.newInstance(); SOAPFault soapFault = f.createFault(); soapFault.setFaultString("Test Fault String ****"); Detail detail = soapFault.addDetail(); detail = soapFault.getDetail(); QName qName = new QName("http://www.Hello.org/greeter", "TestFault", "ns"); DetailEntry de = detail.addDetailEntry(qName); qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns"); SOAPElement errorElement = de.addChildElement(qName); errorElement.setTextContent("errorcode"); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { e.printStackTrace(); } } response.setNode(greetMeResponse); } return response; }
Example 12
Source File: AbstractTypeTestClient5.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testStructWithAnyStrict() throws Exception { if (!shouldRunTest("StructWithAnyStrict")) { return; } SOAPFactory factory = SOAPFactory.newInstance(); SOAPElement elem = factory.createElement("StringElementQualified", "x1", "http://apache.org/type_test/types1"); elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1"); elem.addTextNode("This is the text of the node"); StructWithAnyStrict x = new StructWithAnyStrict(); x.setName("Name x"); x.setAddress("Some Address x"); x.setAny(elem); elem = factory.createElement("StringElementQualified", "x1", "http://apache.org/type_test/types1"); elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1"); elem.addTextNode("This is the text of the second node"); StructWithAnyStrict yOrig = new StructWithAnyStrict(); yOrig.setName("Name y"); yOrig.setAddress("Some Address y"); yOrig.setAny(elem); Holder<StructWithAnyStrict> y = new Holder<>(yOrig); Holder<StructWithAnyStrict> z = new Holder<>(); StructWithAnyStrict ret; if (testDocLiteral) { ret = docClient.testStructWithAnyStrict(x, y, z); } else if (testXMLBinding) { ret = xmlClient.testStructWithAnyStrict(x, y, z); } else { ret = rpcClient.testStructWithAnyStrict(x, y, z); } if (!perfTestOnly) { assertEqualsStructWithAnyStrict(x, y.value); assertEqualsStructWithAnyStrict(yOrig, z.value); assertEqualsStructWithAnyStrict(x, ret); } }
Example 13
Source File: SAAJFactory.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }
Example 14
Source File: SAAJFactory.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }
Example 15
Source File: SAAJFactory.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }
Example 16
Source File: SAAJFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }
Example 17
Source File: SAAJFactory.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }
Example 18
Source File: SAAJFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }
Example 19
Source File: SAAJFactory.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }
Example 20
Source File: SAAJFactory.java From TencentKona-8 with GNU General Public License v2.0 | 2 votes |
/** * Creates a new <code>SOAPFactory</code> object that is an instance of * the specified implementation, this method uses the SAAJMetaFactory to * locate the implementation class and create the SOAPFactory instance. * * @return a new instance of a <code>SOAPFactory</code> * * @param protocol a string constant representing the protocol of the * specified SOAP factory implementation. May be * either <code>DYNAMIC_SOAP_PROTOCOL</code>, * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same * as) <code>SOAP_1_1_PROTOCOL</code>, or * <code>SOAP_1_2_PROTOCOL</code>. * * @exception SOAPException if there was an error creating the * specified <code>SOAPFactory</code> * @see SAAJMetaFactory */ public SOAPFactory createSOAPFactory(String protocol) throws SOAPException { return SOAPFactory.newInstance(protocol); }