Search in sources :

Example 56 with MessageFactory

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

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

the class SoapMultipartCheckerServlet method replyRequestedContentTypeInResponse.

private void replyRequestedContentTypeInResponse(final String requestedContentType, final HttpServletResponse resp) 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:not-important:1.0", "requestedContentType"));
    bodyElement.addTextNode(requestedContentType);
    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setHeader("Content-Type", "application/soap+xml; charset=utf-8");
    final OutputStream os = resp.getOutputStream();
    msg.writeTo(os);
    os.close();
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) OutputStream(java.io.OutputStream) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 58 with MessageFactory

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

the class SOAPBindingTestCase method testDocWrappedServiceMessageAccess.

@Test
@RunAsClient
public void testDocWrappedServiceMessageAccess() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    String reqEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + " <env:Header/>" + " <env:Body>" + "  <ns1:SubmitPO xmlns:ns1='" + targetNS + "'>" + "   <PurchaseOrder>Ferrari</PurchaseOrder>" + "  </ns1:SubmitPO>" + " </env:Body>" + "</env:Envelope>";
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
    URL wsdlURL = new URL(baseURL + "/DocWrappedService?wsdl");
    QName serviceName = new QName(targetNS, "DocWrappedService");
    QName portName = new QName(targetNS, "DocWrappedPort");
    Service service = Service.create(wsdlURL, serviceName);
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE);
    SOAPMessage resMsg = dispatch.invoke(reqMsg);
    QName qname = new QName(targetNS, "SubmitPOResponse");
    SOAPElement soapElement = (SOAPElement) resMsg.getSOAPBody().getChildElements(qname).next();
    soapElement = (SOAPElement) soapElement.getChildElements(new QName("PurchaseOrderAck")).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) Service(javax.xml.ws.Service) 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 59 with MessageFactory

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

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

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