Refine search
import javax.xml.bind.*; import javax.xml.soap.*; public class Demo { public static void main(String[] args) throws Exception { MessageFactory mf = MessageFactory.newInstance(); SOAPMessage message = mf.createMessage(); SOAPBody body = message.getSOAPBody(); Foo foo = new Foo(); foo.setBar("Hello World"); JAXBContext jc = JAXBContext.newInstance(Foo.class); Marshaller marshaller = jc.createMarshaller(); marshaller.marshal(foo, body); message.saveChanges(); message.writeTo(System.out); } }
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); Source sourceContent = soapResponse.getSOAPPart().getContent(); System.out.print("\nResponse SOAP Message = "); StreamResult result = new StreamResult(System.out);
private SOAPMessage initSOAPMessage(InputStream is) throws SOAPException, IOException { SOAPMessage msg = null; if (is != null) { msg = SAAJFactoryResolver.createMessageFactory(null).createMessage(null, is); } else { msg = SAAJFactoryResolver.createMessageFactory(null).createMessage(); } msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD); msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSI, WSDLConstants.NS_SCHEMA_XSI); return msg; } }
+ "</soapenv:Body>" + "</soapenv:Envelope>"; SOAPMessage message = MessageFactory.newInstance() .createMessage(new MimeHeaders(), new ByteArrayInputStream(soap.getBytes("UTF-8"))); SoapMessage soapMessage = new SaajSoapMessage(message); DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
soapFault = binding.getMessageFactory().createMessage() .getSOAPPart().getEnvelope().getBody().addFault(); } catch (Throwable t2) {
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); Source sourceContent = soapResponse.getSOAPPart().getContent(); System.out.print("\nResponse SOAP Message = "); StreamResult result = new StreamResult(System.out);
@Test public void testDoNotOverriderSoapAction() throws Exception { MimeHeaders mimeHeaders = new MimeHeaders(); String testSoapAction = "fooAction"; mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, testSoapAction); String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"></soapenv:Envelope>"; SOAPMessage message = MessageFactory.newInstance() .createMessage(mimeHeaders, new ByteArrayInputStream(soap.getBytes())); SaajSoapMessage soapMessage = new SaajSoapMessage(message); DefaultSoapHeaderMapper headerMapper = new DefaultSoapHeaderMapper(); headerMapper.fromHeadersToRequest(new MessageHeaders(null), soapMessage); assertEquals(testSoapAction, soapMessage.getSoapAction()); }
version = ((SoapMessage)msg).getVersion(); soapMessage = SAAJFactoryResolver.createMessageFactory(version).createMessage(); msg.setContent(SOAPMessage.class, soapMessage); soapFault.setFaultActor(sf.getFault().getFaultActor()); if (sf.getFault().hasDetail()) { Node nd = soapMessage.getSOAPPart().importNode(sf.getFault().getDetail(), true); nd = nd.getFirstChild(); if (sf.hasDetails()) { soapFault.addDetail(); Node nd = soapMessage.getSOAPPart().importNode(sf.getDetail(), true); nd = nd.getFirstChild(); while (nd != null) {
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart();
SaajSoapMessage message = new SaajSoapMessage(MessageFactory.newInstance().createMessage());
MessageFactory mf = MessageFactory.newInstance(); SOAPMessage message = mf.createMessage(); SOAPPart soapPart = message.getSOAPPart(); FileInputStream is = new FileInputStream(file); soapPart.setContent(new StreamSource(is));
public static SOAPMessage createDefaultSoapMessage(String responseMessage, String requestMessage) { try { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1"); SOAPBodyElement payload = body.addBodyElement(payloadName); SOAPElement message = payload.addChildElement("responseType"); message.addTextNode(responseMessage + " Request was " + requestMessage); return soapMessage; } catch (SOAPException e) { e.printStackTrace(); throw new RuntimeException(e); } }
/** * Creates a SOAP message for SOAP 1.2 or 1.1 * * @param soapVersion * SOAP version * @return Version depending SOAP message * @throws SOAPException * if an error occurs. */ public static SOAPMessage getSoapMessageForProtocol(String soapVersion) throws SOAPException { return MessageFactory.newInstance(soapVersion).createMessage(); }
try { MessageFactory factory = saajOut.getFactory(message); soapMessage = factory.createMessage(); SOAPPart part = soapMessage.getSOAPPart(); if (o instanceof Source) { StaxUtils.copy((Source)o, new SAAJStreamWriter(part)); DocumentFragment frag = soapMessage.getSOAPPart().createDocumentFragment(); try { Node body = SAAJUtils.getBody(soapMessage); message.put(SAAJOutInterceptor.ORIGINAL_XML_WRITER, origWriter); W3CDOMStreamWriter writer = new SAAJStreamWriter(soapMessage.getSOAPPart());
private SOAPMessage createSOAPMessage(Element elem) throws Exception { String prefix = ""; MessageFactory msgFactory = MessageFactory.newInstance(); SOAPFactory factory = SOAPFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPPart soapPart = message.getSOAPPart(); SOAPBody soapBody = soapPart.getEnvelope().getBody(); //Create the outer body element Name bodyName = factory.createName(elem.getNodeName(), prefix, UDDI_V2_NAMESPACE); SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName); bodyElement.addNamespaceDeclaration(prefix, UDDI_V2_NAMESPACE); appendAttributes(bodyElement, elem.getAttributes(), factory); appendElements(bodyElement, elem.getChildNodes(), factory); return message; }
/** * Create a SOAP 1.2 Message * * @return * @throws SOAPException */ public static SOAPMessage createSOAP12() throws SOAPException { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage soapMessage = messageFactory.createMessage(); return soapMessage; }
private static SOAPMessage createSOAPRequest(String documentId, String fileToUpdate) throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); String serverURI = "urn:WSFS"; // change form "WSFS" to "urn:WSFS" SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("urn", serverURI); // this line will add namespece in your envelope ...
private SOAPMessage createSoapMessage( SOAPVersion soapVersion, String contentId ) throws SOAPException { String soapProtocol = SOAPConstants.SOAP_1_2_PROTOCOL; if ( isSoap11( soapVersion ) ) soapProtocol = SOAPConstants.SOAP_1_1_PROTOCOL; MessageFactory messageFactory = MessageFactory.newInstance( soapProtocol ); SOAPMessage message = messageFactory.createMessage(); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody body = envelope.getBody(); envelope.createName( "response", CommonNamespaces.WMS_PREFIX, CommonNamespaces.WMSNS ); Name name = envelope.createName( "response", CommonNamespaces.WMS_PREFIX, CommonNamespaces.WMSNS ); SOAPBodyElement bodyElement = body.addBodyElement( name ); bodyElement.setTextContent( contentId ); return message; }
/** * Create a SOAP 1.2 Message * * @return * * @throws SOAPException */ public static SOAPMessage createSOAP12() throws SOAPException { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage soapMessage = messageFactory.createMessage(); return soapMessage; }
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; }