SOAPMessage msg = messageContext.getMessage(); ByteArrayOutputStream out = new ByteArrayOutputStream(); msg.writeTo(out); String strMsg = new String(out.toByteArray());
public static String getSoapMessageAsString(SOAPMessageContext context) { try { final ByteArrayOutputStream os = new ByteArrayOutputStream(); context.getMessage().writeTo(os); os.close(); return new String(os.toByteArray(), Charset.forName("UTF-8")); } catch (Exception e) { return null; } } }
message.writeTo(out); out.println(""); // just to add a newline } catch (Exception e) {
static SOAPMessageContext getSoapMessageContext(String soapMessage, String wsdlOperation, boolean serverRequest) throws SOAPException, IOException { SOAPMessageContext soapMessageContext = mock(SOAPMessageContext.class); when(soapMessageContext.get(MessageContext.WSDL_OPERATION)).thenReturn(new QName("", wsdlOperation)); SOAPMessage soapMessage1 = mock(SOAPMessage.class); when(soapMessageContext.getMessage()).thenReturn(soapMessage1); when(soapMessageContext.containsKey(MessageContext.SERVLET_CONTEXT)).thenReturn(serverRequest); doAnswer(invocation -> { invocation.<OutputStream>getArgument(0).write(soapMessage.getBytes(StandardCharsets.UTF_8)); return null; }).when(soapMessage1).writeTo(any()); return soapMessageContext; } }
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); } }
soapMessage.writeTo(System.out); System.out.println();
soapMessage.writeTo(System.out); System.out.println();
Farm farm = new Farm(); farm.getHorse().add(new Horse()); farm.getHorse().get(0).setName("glue factory"); farm.getHorse().get(0).setHeight(BigInteger.valueOf(123)); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Marshaller marshaller = JAXBContext.newInstance(Farm.class).createMarshaller(); marshaller.marshal(farm, document); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); soapMessage.getSOAPBody().addDocument(document); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); soapMessage.writeTo(outputStream); String output = new String(outputStream.toByteArray());
private void logSOAPMessage(SOAPMessage message){ ByteArrayOutputStream bout = new ByteArrayOutputStream(); message.writeTo(bout); String msg = bout.toString("UTF-8"); _LOG.info(":: Logging SOAP Message :: " + msg); }
SOAPMessage response = connection.call(sm, endpoint); ByteArrayOutputStream os = new ByteArrayOutputStream(); response.writeTo(os); String responseXml = new String(os.toByteArray()); // work with responseXml here...
OutputStream os = new ByteArrayOutputStream(); javax.xml.soap.SOAPMessage soapMsg = context.getMessage(); soapMsg.writeTo(os); Logger LOG = Logger.getLogger(SOAPLoggingHandler.class); // Assuming SOAPLoggingHandler is the class name LOG.info(os.toString());
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 void log(SOAPMessage message) { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); message.writeTo(stream); logger.info(new String(stream.toByteArray(), "utf-8")); } catch (SOAPException|IOException e) { logger.error(e.getMessage(), e); } } }
private void log(SOAPMessage message) { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); message.writeTo(stream); logger.info(new String(stream.toByteArray(), "utf-8")); } catch (SOAPException|IOException e) { logger.error(e.getMessage(), e); } } }
@Converter public static String soapMessageToString(final SOAPMessage soapMessage, Exchange exchange) throws SOAPException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); soapMessage.writeTo(baos); return baos.toString(IOHelper.getCharsetName(exchange)); }
SOAPMessage soapMsg = soapMessageCtx.getMessage(); NodeList credentials = soapMsg .getSOAPBody() .getElementsByTagNameNS("http://rsi.chase.com/model", "Credential"); int len = credentials.length(); for(int i = 0; i < len; i++) { credentials.item(i).setTextContent("new credential content goes here..."); } ByteArrayOutputStream out = new ByteArrayOutputStream(); soapMsg.writeTo(out); // ...
@Converter public static InputStream soapMessageToInputStream(final SOAPMessage soapMessage, Exchange exchange) throws SOAPException, IOException { CachedOutputStream cos = new CachedOutputStream(exchange); soapMessage.writeTo(cos); InputStream in = cos.getInputStream(); return in; }
private void sendResponse(Endpoint endpoint, OutputStream output, boolean isFault) throws SOAPException, IOException { CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext(); SOAPMessage resMessage = msgContext.getSOAPMessage(); if (resMessage == null) { ROOT_LOGGER.debug("Null response message"); return; } resMessage.writeTo(output); }