use of org.springframework.ws.WebServiceMessageFactory in project spring-integration by spring-projects.
the class WebServiceOutboundGatewayParserTests method simpleGatewayWithCustomMessageFactory.
@Test
public void simpleGatewayWithCustomMessageFactory() {
AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomMessageFactory", AbstractEndpoint.class);
assertEquals(EventDrivenConsumer.class, endpoint.getClass());
Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate"));
WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory");
assertEquals(factory, accessor.getPropertyValue("messageFactory"));
}
use of org.springframework.ws.WebServiceMessageFactory in project spring-integration by spring-projects.
the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithAllInOneMarshallerAndMessageFactory.
@Test
public void marshallingGatewayWithAllInOneMarshallerAndMessageFactory() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("marshallingWebServiceOutboundGatewayParserTests.xml", this.getClass());
AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithAllInOneMarshallerAndMessageFactory");
assertEquals(EventDrivenConsumer.class, endpoint.getClass());
Object gateway = TestUtils.getPropertyValue(endpoint, "handler");
Marshaller marshaller = context.getBean("marshallerAndUnmarshaller", Marshaller.class);
assertSame(marshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.marshaller", Marshaller.class));
assertSame(marshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.unmarshaller", Unmarshaller.class));
WebServiceMessageFactory messageFactory = (WebServiceMessageFactory) context.getBean("messageFactory");
assertEquals(messageFactory, TestUtils.getPropertyValue(gateway, "webServiceTemplate.messageFactory"));
context.close();
}
use of org.springframework.ws.WebServiceMessageFactory in project spring-integration by spring-projects.
the class SimpleWebServiceOutboundGatewayTests method testAttachments.
@Test
public void testAttachments() throws Exception {
String uri = "http://www.example.org";
SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(uri);
gateway.setBeanFactory(mock(BeanFactory.class));
final SettableListenableFuture<WebServiceMessage> requestFuture = new SettableListenableFuture<>();
ClientInterceptorAdapter interceptorAdapter = new ClientInterceptorAdapter() {
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
requestFuture.set(messageContext.getRequest());
return super.handleRequest(messageContext);
}
};
gateway.setInterceptors(interceptorAdapter);
gateway.afterPropertiesSet();
WebServiceMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance());
MimeMessage webServiceMessage = (MimeMessage) messageFactory.createWebServiceMessage();
String request = "<test>foo</test>";
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(new StringSource(request), webServiceMessage.getPayloadResult());
webServiceMessage.addAttachment("myAttachment", new ByteArrayResource("my_data".getBytes()), "text/plain");
try {
gateway.handleMessage(new GenericMessage<>(webServiceMessage));
fail("Expected MessageHandlingException");
} catch (MessageHandlingException e) {
// expected
}
WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS);
assertNotNull(requestMessage);
assertThat(requestMessage, instanceOf(MimeMessage.class));
transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringResult stringResult = new StringResult();
transformer.transform(requestMessage.getPayloadSource(), stringResult);
assertEquals(request, stringResult.toString());
Attachment myAttachment = ((MimeMessage) requestMessage).getAttachment("myAttachment");
assertNotNull(myAttachment);
assertEquals("text/plain", myAttachment.getContentType());
assertEquals("my_data", StreamUtils.copyToString(myAttachment.getInputStream(), Charset.forName("UTF-8")));
}
use of org.springframework.ws.WebServiceMessageFactory in project spring-integration by spring-projects.
the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithSeparateMarshallerAndUnmarshallerAndMessageFactory.
@Test
public void marshallingGatewayWithSeparateMarshallerAndUnmarshallerAndMessageFactory() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("marshallingWebServiceOutboundGatewayParserTests.xml", this.getClass());
AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithSeparateMarshallerAndUnmarshallerAndMessageFactory");
assertEquals(EventDrivenConsumer.class, endpoint.getClass());
Object gateway = TestUtils.getPropertyValue(endpoint, "handler");
Marshaller marshaller = context.getBean("marshaller", Marshaller.class);
Unmarshaller unmarshaller = context.getBean("unmarshaller", Unmarshaller.class);
assertSame(marshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.marshaller", Marshaller.class));
assertSame(unmarshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.unmarshaller", Unmarshaller.class));
WebServiceMessageFactory messageFactory = context.getBean("messageFactory", WebServiceMessageFactory.class);
assertEquals(messageFactory, TestUtils.getPropertyValue(gateway, "webServiceTemplate.messageFactory"));
context.close();
}
use of org.springframework.ws.WebServiceMessageFactory in project spring-integration by spring-projects.
the class WebServiceOutboundGatewayParserTests method simpleGatewayWithCustomSourceExtractorAndMessageFactory.
@Test
public void simpleGatewayWithCustomSourceExtractorAndMessageFactory() {
AbstractEndpoint endpoint = context.getBean("gatewayWithCustomSourceExtractorAndMessageFactory", AbstractEndpoint.class);
SourceExtractor<?> sourceExtractor = (SourceExtractor<?>) context.getBean("sourceExtractor");
assertEquals(EventDrivenConsumer.class, endpoint.getClass());
Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
assertEquals(sourceExtractor, accessor.getPropertyValue("sourceExtractor"));
accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate"));
WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory");
assertEquals(factory, accessor.getPropertyValue("messageFactory"));
}
Aggregations