Search in sources :

Example 61 with MessageFactory

use of javax.xml.soap.MessageFactory 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 62 with MessageFactory

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

the class ClientSOAPHandler method handleOutbound.

protected boolean handleOutbound(final SOAPMessageContext msgContext) {
    try {
        SOAPFault fault = null;
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage resMessage = factory.createMessage();
        fault = resMessage.getSOAPBody().addFault();
        fault.setFaultString("this is an exception thrown by client outbound");
        throw new SOAPFaultException(fault);
    } catch (SOAPException e) {
    // ignore
    }
    return true;
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 63 with MessageFactory

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

the class ProviderMessageTestCase method getRequestMessage.

private SOAPMessage getRequestMessage() throws SOAPException, IOException {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgString.getBytes()));
    return reqMsg;
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 64 with MessageFactory

use of javax.xml.soap.MessageFactory 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)

Example 65 with MessageFactory

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

the class ProviderPayloadTestCase method testProviderMessage.

@Test
@RunAsClient
public void testProviderMessage() throws Exception {
    String reqEnvStr = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + "  <env:Body>" + reqString + "</env:Body>" + "</env:Envelope>";
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnvStr.getBytes()));
    URL epURL = baseURL;
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
    SOAPHeader soapHeader = resEnv.getHeader();
    if (soapHeader != null)
        soapHeader.detachNode();
    Node responseBody = DOMUtils.getFirstChildElement(resEnv.getBody());
    assertEquals("wrong namespace: " + responseBody.getNamespaceURI(), "http://org.jboss.ws/provider", responseBody.getNamespaceURI());
    assertEquals("wrong localPart: " + responseBody.getLocalName(), "somePayload", responseBody.getLocalName());
    String responseString = DOMUtils.getTextContent(responseBody);
    assertEquals("wrong content: " + responseString, "Hello:Inbound:LogicalSourceHandler:Outbound:LogicalSourceHandler", responseString);
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) SOAPHeader(javax.xml.soap.SOAPHeader) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Aggregations

MessageFactory (javax.xml.soap.MessageFactory)70 SOAPMessage (javax.xml.soap.SOAPMessage)65 URL (java.net.URL)24 InputStream (java.io.InputStream)22 QName (javax.xml.namespace.QName)22 SOAPException (javax.xml.soap.SOAPException)22 Test (org.junit.Test)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 SOAPBody (javax.xml.soap.SOAPBody)18 SOAPPart (javax.xml.soap.SOAPPart)17 StreamSource (javax.xml.transform.stream.StreamSource)14 SOAPConnection (javax.xml.soap.SOAPConnection)13 IOException (java.io.IOException)11 SOAPElement (javax.xml.soap.SOAPElement)11 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)10 JBossWSTest (org.jboss.wsf.test.JBossWSTest)10 NodeList (org.w3c.dom.NodeList)9 AttachmentPart (javax.xml.soap.AttachmentPart)8 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)8 Element (org.w3c.dom.Element)8