use of org.springframework.ws.soap.SoapMessage in project webservices-axiom by apache.
the class TestCreateWebServiceMessageFromInputStreamMTOM method runTest.
@Override
protected void runTest(SoapMessageFactory messageFactory) throws Throwable {
SoapMessage message = messageFactory.createWebServiceMessage(new TransportInputStreamImpl(MTOMSample.SAMPLE1));
assertNotNull(message.getEnvelope());
}
use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testCustomSoapHeader.
@Test
public void testCustomSoapHeader() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
mapper.setReplyHeaderNames("x:attr", "x:elem");
SoapMessage soapMessage = mock(SoapMessage.class);
SoapHeader soapHeader = mock(SoapHeader.class);
@SuppressWarnings("unchecked") Iterator<QName> attrIterator = mock(Iterator.class);
QName attribute = new QName("http://x", "attr", "x");
@SuppressWarnings("unchecked") Iterator<SoapHeaderElement> elementIterator = mock(Iterator.class);
SoapHeaderElement soapHeaderElement = mock(SoapHeaderElement.class);
QName element = new QName("http://x", "elem", "x");
when(soapMessage.getSoapHeader()).thenReturn(soapHeader);
when(soapHeader.getAllAttributes()).thenReturn(attrIterator);
when(attrIterator.hasNext()).thenReturn(true).thenReturn(false);
when(attrIterator.next()).thenReturn(attribute);
when(soapHeader.getAttributeValue(attribute)).thenReturn("attrValue");
when(soapHeader.examineAllHeaderElements()).thenReturn(elementIterator);
when(elementIterator.hasNext()).thenReturn(true).thenReturn(false);
when(elementIterator.next()).thenReturn(soapHeaderElement);
when(soapHeaderElement.getName()).thenReturn(element);
Map<String, Object> headers = mapper.toHeadersFromReply(soapMessage);
assertEquals(2, headers.size());
assertEquals("attrValue", headers.get("x:attr"));
assertSame(soapHeaderElement, headers.get("x:elem"));
}
use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testExtractStandardHeadersNullSoapAction.
@Test
public void testExtractStandardHeadersNullSoapAction() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
SoapMessage soapMessage = mock(SoapMessage.class);
when(soapMessage.getSoapAction()).thenReturn(null);
assertTrue(mapper.extractStandardHeaders(soapMessage).isEmpty());
}
use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testRealSoapHeader.
@Test
public void testRealSoapHeader() throws Exception {
String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Header>" + "<auth>" + "<username>user</username>" + "<password>pass</password>" + "</auth>" + "<bar>BAR</bar>" + "<baz>BAZ</baz>" + "<qux>qux</qux>" + "</soapenv:Header>" + "<soapenv:Body>" + "<foo>foo</foo>" + "</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();
String authHeader = "auth";
mapper.setRequestHeaderNames(authHeader, "ba*");
Map<String, Object> headers = mapper.toHeadersFromRequest(soapMessage);
assertNotNull(headers.get(authHeader));
assertThat(headers.get(authHeader), instanceOf(SoapHeaderElement.class));
SoapHeaderElement header = (SoapHeaderElement) headers.get(authHeader);
DOMSource source = (DOMSource) header.getSource();
NodeList nodeList = source.getNode().getChildNodes();
assertEquals("username", nodeList.item(0).getNodeName());
assertEquals("user", nodeList.item(0).getFirstChild().getNodeValue());
assertEquals("password", nodeList.item(1).getNodeName());
assertEquals("pass", nodeList.item(1).getFirstChild().getNodeValue());
header = (SoapHeaderElement) headers.get("bar");
assertNotNull(header);
source = (DOMSource) header.getSource();
nodeList = source.getNode().getChildNodes();
assertEquals("BAR", nodeList.item(0).getNodeValue());
header = (SoapHeaderElement) headers.get("baz");
assertNotNull(header);
source = (DOMSource) header.getSource();
nodeList = source.getNode().getChildNodes();
assertEquals("BAZ", nodeList.item(0).getNodeValue());
assertNull(headers.get("qux"));
}
use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.
the class WebServiceInboundGatewayJavaConfigTests method testWebServiceInboundGatewayJavaConfig.
@Test
public void testWebServiceInboundGatewayJavaConfig() throws Exception {
MessageContext context = mock(MessageContext.class);
SoapMessage request = mock(SoapMessage.class);
SoapMessage response = mock(SoapMessage.class);
SoapBody soapBody = mock(SoapBody.class);
String input = "<hello/>";
Source payloadSource = new StringSource(input);
StringWriter output = new StringWriter();
Result payloadResult = new StreamResult(output);
when(context.getResponse()).thenReturn(response);
when(response.getPayloadResult()).thenReturn(payloadResult);
when(response.getSoapBody()).thenReturn(soapBody);
when(context.getRequest()).thenReturn(request);
when(request.getPayloadSource()).thenReturn(payloadSource);
this.messageReceiver.receive(context);
verify(soapBody).addServerOrReceiverFault(eq("503 Service Unavailable"), any(Locale.class));
this.wsGateway.start();
this.messageReceiver.receive(context);
assertTrue(output.toString().endsWith(input));
context = mock(MessageContext.class);
request = mock(SoapMessage.class);
payloadSource = new StringSource("<order/>");
when(context.getRequest()).thenReturn(request);
when(request.getPayloadSource()).thenReturn(payloadSource);
this.messageReceiver.receive(context);
Message<?> receive = this.webserviceRequestsQueue.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(Element.class));
Element order = (Element) receive.getPayload();
assertEquals("order", order.getLocalName());
}
Aggregations