Search in sources :

Example 21 with SOAPConnection

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

the class MultipartContentTypeTestCase method testSendMultipartSoapMessage.

@Test
@RunAsClient
public void testSendMultipartSoapMessage() throws Exception {
    final MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    final SOAPMessage msg = msgFactory.createMessage();
    final SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:ledegen:soap-attachment:1.0", "echoImage"));
    bodyElement.addTextNode("cid:" + IN_IMG_NAME);
    final AttachmentPart ap = msg.createAttachmentPart();
    ap.setDataHandler(getResource("saaj/jbws3857/" + IN_IMG_NAME));
    ap.setContentId(IN_IMG_NAME);
    msg.addAttachmentPart(ap);
    final SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
    final SOAPConnection connection = conFactory.createConnection();
    final SOAPMessage response = connection.call(msg, new URL("http://" + baseURL.getHost() + ":" + baseURL.getPort() + "/" + PROJECT_NAME + "/testServlet"));
    final String contentTypeWeHaveSent = getBodyElementTextValue(response);
    assertContentTypeStarts("multipart/related", contentTypeWeHaveSent);
}
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) URL(java.net.URL) SOAPBodyElement(javax.xml.soap.SOAPBodyElement) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 22 with SOAPConnection

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

the class WebResultTestCase method testMessageAccess.

@Test
@RunAsClient
public void testMessageAccess() 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:locateCustomer xmlns:ns1='" + targetNS + "'>" + "   <FirstName>Mickey</FirstName>" + "   <LastName>Mouse</LastName>" + "   <Address>" + "     <address>Wall Street</address>" + "   </Address>" + "  </ns1:locateCustomer>" + " </env:Body>" + "</env:Envelope>";
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
    URL epURL = baseURL;
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    QName qname = new QName(targetNS, "locateCustomerResponse");
    SOAPElement soapElement = (SOAPElement) resMsg.getSOAPBody().getChildElements(qname).next();
    soapElement = (SOAPElement) soapElement.getChildElements(new QName("CustomerRecord")).next();
    assertNotNull("Expected CustomerRecord", soapElement);
}
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 23 with SOAPConnection

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

the class AbstractClient method performSOAPCall.

protected static void performSOAPCall(String endpointAddress) throws SOAPException, MalformedURLException {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();
    SOAPConnection con = conFac.createConnection();
    QName echo = new QName("http://org.jboss.ws/bus", "echo");
    SOAPElement element = soapFac.createElement(echo);
    element.addTextNode("John");
    msg.getSOAPBody().addChildElement(element);
    SOAPMessage response = con.call(msg, new URL(endpointAddress));
    assert (response != null);
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPFactory(javax.xml.soap.SOAPFactory) URL(java.net.URL)

Example 24 with SOAPConnection

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

the class JBWS3084CxfTestCase method testSoapConnectionGet.

@Test
@RunAsClient
public void testSoapConnectionGet() throws Exception {
    final String serviceURL = baseURL + "/greetMe";
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPConnection con = conFac.createConnection();
    URL endpoint = new URL(serviceURL);
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage msg = msgFactory.createMessage();
    msg.getSOAPBody().addBodyElement(new QName("http://www.jboss.org/jbossws/saaj", "greetMe"));
    SOAPMessage response = con.call(msg, endpoint);
    QName greetMeResp = new QName("http://www.jboss.org/jbossws/saaj", "greetMeResponse");
    Iterator<?> sayHiRespIterator = response.getSOAPBody().getChildElements(greetMeResp);
    SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
    assertNotNull(soapElement);
    assertEquals(1, response.countAttachments());
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) 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 25 with SOAPConnection

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

the class ProviderMessageTestCase method testProviderMessageNullResponse.

@Test
@RunAsClient
public void testProviderMessageNullResponse() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgStringForNullResponse.getBytes()));
    URL epURL = baseURL;
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    if (resMsg != null) {
        SOAPPart soapPart = resMsg.getSOAPPart();
        // verify there's either nothing in the reply or at least the response body is empty
        if (soapPart != null && soapPart.getEnvelope() != null && soapPart.getEnvelope().getBody() != null) {
            SOAPBody soapBody = soapPart.getEnvelope().getBody();
            assertFalse(soapBody.getChildElements().hasNext());
        }
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPPart(javax.xml.soap.SOAPPart) 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)

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