SOAPPart soapPart = message.getSOAPPart(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbFactory.newDocumentBuilder(); Document document = builder.parse("file:///template.xml"); DOMSource domSource = new DOMSource(document); soapPart.setContent(domSource);
public void write(Object obj, T output) { dest = (SOAPMessage)output; try { if (DOMSource.class.isAssignableFrom(obj.getClass())) { DOMSource src = (DOMSource)obj; dest.getSOAPPart().setContent(src); } else if (SAXSource.class.isAssignableFrom(obj.getClass())) { SAXSource src = (SAXSource)obj; dest.getSOAPPart().setContent(src); } else if (StreamSource.class.isAssignableFrom(obj.getClass())) { StreamSource src = (StreamSource)obj; dest.getSOAPPart().setContent(src); } } catch (SOAPException se) { //TODO } }
MessageFactory mf = MessageFactory.newInstance(); SOAPMessage message = mf.createMessage(); SOAPPart soapPart = message.getSOAPPart(); FileInputStream is = new FileInputStream(file); soapPart.setContent(new StreamSource(is));
URL wsdlLocation = new URL("your_wsdl_target"); QName apiName = new QName("your_service_target", "your_service_name"); your_service_name api = new your_service_name(wsdlLocation, apiName); api.addPort(your_service_name, SOAPBinding.SOAP12HTTP_BINDING, "your_service_target/name"); QName port_name = new QName("your_service_target", "port_name"); Dispatch<SOAPMessage> disp = api.createDispatch(port_name, SOAPMessage.class, Service.Mode.MESSAGE); String xml = "Your SOAP MESSAGE"; MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage request = mf.createMessage(); SOAPPart part = request.getSOAPPart(); StreamSource source = new StreamSource(new StringReader(xml)); part.setContent(source); request.saveChanges(); SOAPMessage response = disp.invoke(request); StringWriter sw = new StringWriter(); TransformerFactory.newInstance().newTransformer().transform(new DOMSource(response.getSOAPPart()), new StreamResult(sw)); org.json.JSONObject xmlJSONObj = XML.toJSONObject(sw.toString()); return xmlJSONObj.toString(2);
String testFileName = (String) mc.getProperty("USE_TEST_FILE"); InputStream instream = <read file as an input stream> SOAPMessageContext smc = (SOAPMessageContext) mc; SOAPMessage message = smc.getMessage(); SOAPPart soapPart = message.getSOAPPart(); soapPart.setContent(new StreamSource(instream)); smc.setMessage(message); return false;
public static SOAPMessage buildSOAPMessage(final String soapAction, final String soapPartAsString) { SOAPMessage soapMessage = null; try { soapMessage = SOAPUtil.getMessageFactory().createMessage(); final MimeHeaders hd = soapMessage.getMimeHeaders(); hd.addHeader("SOAPAction", soapAction); final SOAPPart soapPart = soapMessage.getSOAPPart(); soapPart.setContent(new StreamSource(new ByteArrayInputStream(soapPartAsString.getBytes()))); soapMessage.saveChanges(); } catch (final Exception e) { throw new RuntimeException("Exception while building a SOAPMessage", e); } return soapMessage; }
soapPart.setContent(source);
newMsg = messageFactory.createMessage(); SOAPPart soapPart = newMsg.getSOAPPart(); soapPart.setContent(domSource); SOAPEnvelope newEnv = soapPart.getEnvelope(); SOAPEnvelope oldEnv = msg.getSOAPPart().getEnvelope();
soapPart.setContent(source);
soapPart.setContent(source);
soapPart.setContent(source);
private static SOAPMessage createRequest(String msg) { SOAPMessage request = null; try { MessageFactory msgFactory = MessageFactory .newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); request = msgFactory.createMessage(); SOAPPart msgPart = request.getSOAPPart(); SOAPEnvelope envelope = msgPart.getEnvelope(); SOAPBody body = envelope.getBody(); javax.xml.transform.stream.StreamSource _msg = new javax.xml.transform.stream.StreamSource( new java.io.StringReader(msg)); msgPart.setContent(_msg); request.saveChanges(); } catch (Exception ex) { ex.printStackTrace(); } return request; }
soapPart.setContent(source);
soapPart.setContent(ss);
public StreamSource invoke(StreamSource request) { QName qn = (QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION); if (qn == null) { throw new RuntimeException("No Operation Name"); } StreamSource response = new StreamSource(); try { SOAPMessage msg = factory.createMessage(); msg.getSOAPPart().setContent(request); SOAPBody body = msg.getSOAPBody(); Node n = body.getFirstChild(); while (n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); } if (n.getLocalName().equals(sayHi.getLocalPart())) { response.setInputStream(sayHiInputStream); } else if (n.getLocalName().equals(greetMe.getLocalPart())) { response.setInputStream(greetMeInputStream); } } catch (Exception ex) { ex.printStackTrace(); } return response; }
public SAXSource invoke(SAXSource request) { QName qn = (QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION); if (qn == null) { throw new RuntimeException("No Operation Name"); } SAXSource response = new SAXSource(); try { SOAPMessage msg = factory.createMessage(); msg.getSOAPPart().setContent(request); SOAPBody body = msg.getSOAPBody(); Node n = body.getFirstChild(); while (n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); } if (n.getLocalName().equals(sayHi.getLocalPart())) { response.setInputSource(sayHiInputSource); } else if (n.getLocalName().equals(greetMe.getLocalPart())) { response.setInputSource(greetMeInputSource); } } catch (Exception ex) { ex.printStackTrace(); } return response; }
public DOMSource invoke(DOMSource request) { QName qn = (QName)ctx.getMessageContext().get(MessageContext.WSDL_OPERATION); if (qn == null) { throw new RuntimeException("No Operation Name"); } //XMLUtils.writeTo(request, System.out); DOMSource response = new DOMSource(); try { SOAPMessage msg = factory.createMessage(); msg.getSOAPPart().setContent(request); SOAPBody body = msg.getSOAPBody(); Node n = body.getFirstChild(); while (n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); } if (n.getLocalName().equals(sayHi.getLocalPart())) { response.setNode(sayHiResponse.getSOAPPart()); } else if (n.getLocalName().equals(greetMe.getLocalPart())) { response.setNode(greetMeResponse.getSOAPPart()); } } catch (Exception ex) { ex.printStackTrace(); } return response; } }
public SOAPMessage invoke(SOAPMessage request) { try { String responseText = "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<SOAP-ENV:Body>" + "<ns2:FooResponse xmlns:ns2=\"http://cxf.apache.org/soapheader/inband\">" + "<ns2:Return>Foo Response Body</ns2:Return>" + "</ns2:FooResponse>" + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>\n"; // Create a SOAP request message MessageFactory soapmsgfactory = MessageFactory.newInstance(); SOAPMessage responseMessage = soapmsgfactory.createMessage(); StreamSource responseMessageSrc = null; responseMessageSrc = new StreamSource(new StringReader(responseText)); responseMessage.getSOAPPart().setContent(responseMessageSrc); responseMessage.saveChanges(); return responseMessage; } catch (Exception e) { throw new WebServiceException(e); } }
responseMessage.getSOAPPart().setContent(responseMessageSrc); responseMessage.saveChanges();
public void handleMessage(Message message) { LOG.entering(getClass().getName(), "handleMessage"); // Capturing the soap envelope. In case of WSS was activated, decrypted envelope is captured. if (!MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false) && isApplicationMessage(message) && (getManager().getStore() != null || (getManager().getDestinationPolicy() != null && getManager() .getDestinationPolicy().getRetryPolicy() != null))) { CachedOutputStream saved = new CachedOutputStream(); SOAPMessage soapMessage = message.getContent(SOAPMessage.class); if (soapMessage != null) { try { javax.xml.transform.Source envelope = soapMessage.getSOAPPart().getContent(); StaxUtils.copy(envelope, saved); saved.flush(); // create a new source part from cos InputStream is = saved.getInputStream(); // close old saved content closeOldSavedContent(message); // keep References to clean-up tmp files in RMDeliveryInterceptor setCloseable(message, saved, is); StreamSource source = new StreamSource(is); soapMessage.getSOAPPart().setContent(source); // when WSS was activated, saved content still contains soap headers to be removed message.put(RMMessageConstants.SAVED_CONTENT, removeUnnecessarySoapHeaders(saved)); } catch (SOAPException | IOException | XMLStreamException e) { throw new Fault(e); } } } }