Search in sources :

Example 11 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project jbossws-cxf by jbossws.

the class WebMethodTestCase method testLegalMessageAccess.

@Test
@RunAsClient
public void testLegalMessageAccess() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    String reqEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + " <env:Header/>" + " <env:Body>" + "  <ns1:echoString xmlns:ns1='" + targetNS + "'>" + "   <arg0>Hello</arg0>" + "  </ns1:echoString>" + " </env:Body>" + "</env:Envelope>";
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
    URL epURL = new URL(baseURL + "/TestService");
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    QName qname = new QName(targetNS, "echoStringResponse");
    SOAPElement soapElement = (SOAPElement) resMsg.getSOAPBody().getChildElements(qname).next();
    soapElement = (SOAPElement) soapElement.getChildElements(new QName("return")).next();
    assertEquals("Hello", soapElement.getValue());
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 12 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project jbossws-cxf by jbossws.

the class WebMethodTestCase method testIllegalMessageAccess.

@Test
@RunAsClient
public void testIllegalMessageAccess() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    String reqEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + " <env:Header/>" + " <env:Body>" + "  <ns1:noWebMethod xmlns:ns1='" + targetNS + "'>" + "   <String_1>Hello</String_1>" + "  </ns1:noWebMethod>" + " </env:Body>" + "</env:Envelope>";
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
    URL epURL = new URL(baseURL + "/TestService");
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    SOAPFault soapFault = resMsg.getSOAPBody().getFault();
    assertNotNull("Expected SOAPFault", soapFault);
    String faultString = soapFault.getFaultString();
    assertTrue(faultString, faultString.indexOf("noWebMethod") > 0);
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPFault(javax.xml.soap.SOAPFault) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 13 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project jbossws-cxf by jbossws.

the class SOAPBindingTestCase method testNamespacedDocWrappedServiceMessageAccess.

@Test
@RunAsClient
public void testNamespacedDocWrappedServiceMessageAccess() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    String purchaseNamespace = "http://namespace/purchase";
    String resultNamespace = "http://namespace/result";
    String stringNamespace = "http://namespace/string";
    String reqEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + " <env:Header/>" + " <env:Body>" + "  <ns1:SubmitNamespacedPO xmlns:ns1='" + targetNS + "'>" + "   <ns2:NamespacedPurchaseOrder xmlns:ns2='" + purchaseNamespace + "'>Ferrari</ns2:NamespacedPurchaseOrder>" + "   <ns3:NamespacedString xmlns:ns3='" + stringNamespace + "'>message</ns3:NamespacedString>" + "  </ns1:SubmitNamespacedPO>" + " </env:Body>" + "</env:Envelope>";
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
    URL epURL = new URL(baseURL + "/DocWrappedService");
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    QName qname = new QName(targetNS, "SubmitNamespacedPOResponse");
    SOAPElement soapElement = (SOAPElement) resMsg.getSOAPBody().getChildElements(qname).next();
    soapElement = (SOAPElement) soapElement.getChildElements(new QName(resultNamespace, "NamespacedPurchaseOrderAck")).next();
    assertEquals("Ferrari", soapElement.getValue());
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 14 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project jbossws-cxf by jbossws.

the class JBWS3084TestCase method doTestSoapConnection.

private void doTestSoapConnection(boolean disableChunking) throws Exception {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();
    if (disableChunking) {
        // this is the custom header checked by ServiceImpl
        msg.getMimeHeaders().addHeader("Transfer-Encoding-Disabled", "true");
        // this is a hint to SOAPConnection that the chunked encoding is not needed
        msg.getMimeHeaders().addHeader("Transfer-Encoding", "disabled");
    }
    QName sayHi = new QName("http://www.jboss.org/jbossws/saaj", "sayHello");
    msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
    AttachmentPart ap1 = msg.createAttachmentPart();
    char[] content = new char[16 * 1024];
    Arrays.fill(content, 'A');
    ap1.setContent(new String(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();
    final String serviceURL = baseURL.toString();
    URL endpoint = new URL(serviceURL);
    SOAPMessage response = con.call(msg, endpoint);
    QName sayHiResp = new QName("http://www.jboss.org/jbossws/saaj", "sayHelloResponse");
    Iterator<?> sayHiRespIterator = response.getSOAPBody().getChildElements(sayHiResp);
    SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
    assertNotNull(soapElement);
    assertEquals(2, response.countAttachments());
    String[] values = response.getMimeHeaders().getHeader("Transfer-Encoding-Disabled");
    if (disableChunking) {
        // this means that the ServiceImpl executed the code branch verifying
        // that chunking was disabled
        assertNotNull(values);
        assertTrue(values.length == 1);
    } else {
        assertNull(values);
    }
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPConnection(javax.xml.soap.SOAPConnection) AttachmentPart(javax.xml.soap.AttachmentPart) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPFactory(javax.xml.soap.SOAPFactory) URL(java.net.URL) SOAPElement(javax.xml.soap.SOAPElement)

Example 15 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project cxf by apache.

the class ProviderRPCClientServerTest method testSWA.

@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());
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPConnection(javax.xml.soap.SOAPConnection) AttachmentPart(javax.xml.soap.AttachmentPart) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPFactory(javax.xml.soap.SOAPFactory) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SOAPConnection (javax.xml.soap.SOAPConnection)28 SOAPMessage (javax.xml.soap.SOAPMessage)28 URL (java.net.URL)16 MessageFactory (javax.xml.soap.MessageFactory)13 Test (org.junit.Test)12 SOAPConnectionFactory (javax.xml.soap.SOAPConnectionFactory)11 SOAPElement (javax.xml.soap.SOAPElement)11 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)11 JBossWSTest (org.jboss.wsf.test.JBossWSTest)11 QName (javax.xml.namespace.QName)10 SOAPException (javax.xml.soap.SOAPException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)5 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AttachmentPart (javax.xml.soap.AttachmentPart)4 SOAPBody (javax.xml.soap.SOAPBody)4 SOAPFactory (javax.xml.soap.SOAPFactory)3 Node (org.w3c.dom.Node)3 FSException (com.sun.identity.federation.common.FSException)2