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);
}
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();
}
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());
}
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);
}
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);
}
Aggregations