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); } }
headers.addHeader("SOAPAction", serverURI + "VerifyEmail"); soapMessage.saveChanges();
headers.addHeader("SOAPAction", serverURI + "VerifyEmail"); soapMessage.saveChanges();
headers.addHeader("SOAPAction", serverURI + "VerifyEmail"); soapMessage.saveChanges();
/** * Gets soap message. * * @return the soap message * @throws SOAPException the soap exception */ public SOAPMessage getSOAPMessage() throws SOAPException { this.soapMessage.saveChanges(); return this.soapMessage; }
@Override public String toString() { String output = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); this.soapMessage.saveChanges(); this.soapMessage.writeTo(out); output = out.toString(this.charset); out.close(); } catch (IOException ioe) { } catch (SOAPException se) { } return output; }
private HttpEntity createHttpEntityFromSOAPMessage(SOAPMessage soapMessage, String characterEncoding) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); soapMessage.saveChanges(); soapMessage.writeTo(out); return new StringEntity(new String(out.toByteArray(), characterEncoding), characterEncoding); } catch (SOAPException | IOException e) { throw new ConditionalException(e.getMessage()); } }
private SOAPMessage createResponse(Object body) throws InvocationTargetException { try { SOAPMessage soapMessage = factory.createMessage(); soapMessage.getSOAPBody().addDocument((Document) body); soapMessage.saveChanges(); return soapMessage; } catch (SOAPException e) { throw new InvocationTargetException(e); } }
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; }
private void saveChanges(final MessageContext context) { try { final SOAPMessage message = ((SOAPMessageContext) context).getMessage(); if (message != null) { message.saveChanges(); } } catch (final SOAPException e) { throw new ServerRuntimeException("Unable to save changes to SOAPMessage : " + e.toString()); } }
private void transportHeaders(Packet packet, boolean inbound, SOAPMessage msg) throws SOAPException { Map<String, List<String>> headers = getTransportHeaders(packet, inbound); if (headers != null) { addSOAPMimeHeaders(msg.getMimeHeaders(), headers); } if (msg.saveRequired()) msg.saveChanges(); } }
private void transportHeaders(Packet packet, boolean inbound, SOAPMessage msg) throws SOAPException { Map<String, List<String>> headers = getTransportHeaders(packet, inbound); if (headers != null) { addSOAPMimeHeaders(msg.getMimeHeaders(), headers); } if (msg.saveRequired()) msg.saveChanges(); } }
private void transportHeaders(Packet packet, boolean inbound, SOAPMessage msg) throws SOAPException { Map<String, List<String>> headers = getTransportHeaders(packet, inbound); if (headers != null) { addSOAPMimeHeaders(msg.getMimeHeaders(), headers); } if (msg.saveRequired()) msg.saveChanges(); } }
private static SOAPMessage createSOAPRequest(FileInputStream requestFile, String serverURI, String serviceName) throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); MimeHeaders headers = new MimeHeaders(); SOAPMessage soapMessage = messageFactory.createMessage(headers, requestFile); requestFile.close(); String authorization = new sun.misc.BASE64Encoder().encode((username+":"+password).getBytes()); headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", serverURI + serviceName); headers.addHeader("Authorization", "Basic " + authorization); soapMessage.saveChanges(); return soapMessage; }
SOAPMessage soapMessage = soapContext.getMessage(); SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope(); SOAPHeader soapHeader = soapEnvelope.getHeader(); /* If no header, add one */ if (soapHeader == null) { soapHeader = soapEnvelope.addHeader(); } /* Add a soap header, name as AUTH_ID_KEY */ Name name = soapEnvelope.createName(AUTH_ID_KEY); SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(name); soapHeaderElement.addTextNode(authId); soapMessage.saveChanges();
try { SOAPMessage saajMessage = saajSoapMessage.getSaajMessage(); saajMessage.getSOAPPart().getEnvelope().removeNamespaceDeclaration("SOAP-ENV"); saajMessage.getSOAPPart().getEnvelope().addNamespaceDeclaration("ims", "http://www.imsglobal.org/services/lis/cmsv1p0/wsdl11/sync/imscms_v1p"); saajMessage.getSOAPPart().getEnvelope().setPrefix("soapenv"); saajMessage.getSOAPHeader().setPrefix("soapenv"); saajMessage.getSOAPBody().setPrefix("soapenv"); saajMessage.saveChanges(); } catch (SOAPException e) { e.printStackTrace(); }
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage message = messageFactory.createMessage(); SOAPPart SOAPPart = message.getSOAPPart(); SOAPEnvelope envelope = SOAPPart.getEnvelope(); SOAPBody body = envelope.getBody(); SOAPElement bodyElement = body.addChildElement(envelope.createName("echo", "req", "http://localhost:8080/axis2/services/MyService/")); bodyElement.addChildElement("category").addTextNode("classifieds"); message.saveChanges(); SOAPPart SOAPpartbefore = message.getSOAPPart(); SOAPEnvelope reqenv = SOAPpartbefore.getEnvelope(); System.out.println(reqenv.toString());
public SOAPMessage readAsSOAPMessageSax2Dom(final SOAPVersion soapVersion, final Message message) throws SOAPException { SOAPMessage msg = soapVersion.getMessageFactory().createMessage(); SAX2DOMEx s2d = new SAX2DOMEx(msg.getSOAPPart()); try { message.writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER); } catch (SAXException e) { throw new SOAPException(e); } addAttachmentsToSOAPMessage(msg, message); if (msg.saveRequired()) msg.saveChanges(); return msg; }
public SOAPMessage readAsSOAPMessageSax2Dom(final SOAPVersion soapVersion, final Message message) throws SOAPException { SOAPMessage msg = soapVersion.getMessageFactory().createMessage(); SAX2DOMEx s2d = new SAX2DOMEx(msg.getSOAPPart()); try { message.writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER); } catch (SAXException e) { throw new SOAPException(e); } addAttachmentsToSOAPMessage(msg, message); if (msg.saveRequired()) msg.saveChanges(); return msg; }
public SOAPMessage readAsSOAPMessageSax2Dom(final SOAPVersion soapVersion, final Message message) throws SOAPException { SOAPMessage msg = soapVersion.getMessageFactory().createMessage(); SAX2DOMEx s2d = new SAX2DOMEx(msg.getSOAPPart()); try { message.writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER); } catch (SAXException e) { throw new SOAPException(e); } addAttachmentsToSOAPMessage(msg, message); if (msg.saveRequired()) msg.saveChanges(); return msg; }