Refine search
@Test public void sendString() throws Exception { when(context.getResponse()).thenReturn(response); when(context.getRequest()).thenReturn(request); when(request.getPayloadSource()).thenReturn(stringSource); when(response.getPayloadResult()).thenReturn(stringResult); gateway.invoke(context); assertTrue(output.toString().endsWith(input)); }
/** Returns the request payload as {@code Source}. */ private Source getRequestPayload(MessageContext messageContext) { WebServiceMessage request = messageContext.getRequest(); return request != null ? request.getPayloadSource() : null; }
private void createStreamWriter() throws XMLStreamException { if (streamWriter == null) { WebServiceMessage response = messageContext.getResponse(); streamWriter = getStreamWriter(response.getPayloadResult()); if (streamWriter == null) { // as a final resort, use a stream, and transform that at endDocument() os = new ByteArrayOutputStream(); streamWriter = getOutputFactory().createXMLStreamWriter(os); } } } }
@Override public Object doExtractData(WebServiceMessage message) throws IOException, TransformerException { if (!SimpleWebServiceOutboundGateway.this.extractPayload) { return message; } else { Source payloadSource = message.getPayloadSource(); if (payloadSource != null && this.result != null) { this.transform(payloadSource, this.result); if (this.result instanceof StringResult) { return this.result.toString(); } else if (this.result instanceof DOMResult) { return ((DOMResult) this.result).getNode(); } else { return this.result; } } return payloadSource; } }
private void transformMessage(WebServiceMessage message, Transformer transformer) throws TransformerException { ByteArrayOutputStream os = new ByteArrayOutputStream(); transformer.transform(message.getPayloadSource(), new StreamResult(os)); ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); transform(new StreamSource(is), message.getPayloadResult()); }
@Before public void setup() { gateway.setRequestChannel(requestChannel); gateway.setReplyChannel(replyChannel); gateway.setBeanFactory(mock(BeanFactory.class)); gateway.start(); when(context.getResponse()).thenReturn(response); when(response.getPayloadResult()).thenReturn(payloadResult); when(context.getRequest()).thenReturn(request); }
/** * Emulate the Spring WS MessageDispatcherServlet by calling the gateway * with a DOMSource object representing the payload of the original SOAP * 'echoRequest' message. Expect an 'echoResponse' DOMSource object * to be returned in synchronous fashion, which the MessageDispatcherServlet * would in turn wrap in a SOAP envelope and return to the client. */ @Test public void testSendAndReceive() throws Exception { String xml = "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>"; DomPoxMessageFactory messageFactory = new DomPoxMessageFactory(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(new InputSource(new StringReader(xml))); Transformer transformer = TransformerFactory.newInstance().newTransformer(); DomPoxMessage request = new DomPoxMessage(document, transformer, "text/xml"); MessageContext messageContext = new DefaultMessageContext(request, messageFactory); gateway.invoke(messageContext); Object reply = messageContext.getResponse().getPayloadSource(); assertThat(reply, is(instanceOf(DOMSource.class))); DOMSource replySource = (DOMSource) reply; Element element = (Element) replySource.getNode().getFirstChild(); assertThat(element.getTagName(), equalTo("echoResponse")); } }
@Override public void doWithMessageInternal(WebServiceMessage message, Object payload) throws IOException, TransformerException { Source source = this.extractSource(payload); transform(source, message.getPayloadResult()); if (message instanceof MimeMessage && payload instanceof MimeMessage) { copyAttachments((MimeMessage) payload, (MimeMessage) message); } }
private String getMessageContent(WebServiceMessage message) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); message.writeTo(bos); return bos.toString("UTF-8"); }
/** Returns the request payload as {@code Source}. */ private Source getRequestPayload(MessageContext messageContext) { WebServiceMessage request = messageContext.getRequest(); return request != null ? request.getPayloadSource() : null; }
private void createStreamWriter() throws XMLStreamException { if (streamWriter == null) { WebServiceMessage response = messageContext.getResponse(); streamWriter = getStreamWriter(response.getPayloadResult()); if (streamWriter == null) { // as a final resort, use a stream, and transform that at endDocument() os = new ByteArrayOutputStream(); streamWriter = getOutputFactory().createXMLStreamWriter(os); } } } }
public WebServiceMessage createWebServiceMessage() { WebServiceMessage message = mock(WebServiceMessage.class); Source source = mock(Source.class); when(message.getPayloadSource()).thenReturn(source); return message; }
private void transformMessage(WebServiceMessage message, Transformer transformer) throws TransformerException { ByteArrayOutputStream os = new ByteArrayOutputStream(); transformer.transform(message.getPayloadSource(), new StreamResult(os)); ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); transform(new StreamSource(is), message.getPayloadResult()); }
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { transformer.transform(requestPayload, message.getPayloadResult()); if (requestCallback != null) { requestCallback.doWithMessage(message); } } }, new SourceExtractorMessageExtractor<T>(responseExtractor));
private String getMessageContent(WebServiceMessage message) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); message.writeTo(bos); return bos.toString("UTF-8"); }
@Override protected void doInvoke(MessageContext messageContext) throws Exception { WebServiceMessage request = messageContext.getRequest(); Assert.notNull(request, "Invalid message context: request was null."); (this.extractPayload) ? request.getPayloadSource() : request); messageContext.setResponse((WebServiceMessage) replyPayload); "The actual type was [" + replyPayload.getClass().getName() + "]"); WebServiceMessage response = messageContext.getResponse(); this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult());
/** Returns the request payload as {@code Source}. */ private Source getRequestPayload(MessageContext messageContext) { WebServiceMessage request = messageContext.getRequest(); return request != null ? request.getPayloadSource() : null; }
private void createStreamWriter() throws XMLStreamException { if (streamWriter == null) { WebServiceMessage response = messageContext.getResponse(); streamWriter = getStreamWriter(response.getPayloadResult()); if (streamWriter == null) { // as a final resort, use a stream, and transform that at endDocument() os = new ByteArrayOutputStream(); streamWriter = getOutputFactory().createXMLStreamWriter(os); } } } }
private Source extractSource(Object requestPayload) throws IOException, TransformerException { Source source = null; if (requestPayload instanceof Source) { source = (Source) requestPayload; Object o = SimpleWebServiceOutboundGateway.this.sourceExtractor.extractData(source); Assert.isInstanceOf(Source.class, o); source = (Source) o; } else if (requestPayload instanceof String) { source = new StringSource((String) requestPayload); } else if (requestPayload instanceof Document) { source = new DOMSource((Document) requestPayload); } else if (requestPayload instanceof WebServiceMessage) { source = ((WebServiceMessage) requestPayload).getPayloadSource(); } else { throw new MessagingException("Unsupported payload type '" + requestPayload.getClass() + "'. " + this.getClass().getName() + " only supports 'java.lang.String', '" + Source.class.getName() + "', '" + Document.class.getName() + "' and '" + WebServiceMessage.class.getName() + "'. " + "Consider either using the '" + MarshallingWebServiceOutboundGateway.class.getName() + "' or a Message Transformer."); } return source; }
private void transformMessage(WebServiceMessage message, Transformer transformer) throws TransformerException { ByteArrayOutputStream os = new ByteArrayOutputStream(); transformer.transform(message.getPayloadSource(), new StreamResult(os)); ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); transform(new StreamSource(is), message.getPayloadResult()); }