Search in sources :

Example 1 with SoapMessage

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());
}
Also used : SoapMessage(org.springframework.ws.soap.SoapMessage)

Example 2 with SoapMessage

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"));
}
Also used : SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) QName(javax.xml.namespace.QName) SoapHeader(org.springframework.ws.soap.SoapHeader) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Test(org.junit.Test)

Example 3 with SoapMessage

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());
}
Also used : SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Test(org.junit.Test)

Example 4 with SoapMessage

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"));
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) DOMSource(javax.xml.transform.dom.DOMSource) SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeList(org.w3c.dom.NodeList) SOAPMessage(javax.xml.soap.SOAPMessage) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Test(org.junit.Test)

Example 5 with SoapMessage

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());
}
Also used : Locale(java.util.Locale) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) SoapBody(org.springframework.ws.soap.SoapBody) MessageContext(org.springframework.ws.context.MessageContext) StringSource(org.springframework.xml.transform.StringSource) Source(javax.xml.transform.Source) StringSource(org.springframework.xml.transform.StringSource) SoapMessage(org.springframework.ws.soap.SoapMessage) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) Test(org.junit.Test)

Aggregations

SoapMessage (org.springframework.ws.soap.SoapMessage)22 Test (org.junit.Test)8 SaajSoapMessage (org.springframework.ws.soap.saaj.SaajSoapMessage)7 SoapHeader (org.springframework.ws.soap.SoapHeader)4 WebServiceMessage (org.springframework.ws.WebServiceMessage)3 SoapBody (org.springframework.ws.soap.SoapBody)3 SoapHeaderElement (org.springframework.ws.soap.SoapHeaderElement)3 MessageAddressingProperties (org.springframework.ws.soap.addressing.core.MessageAddressingProperties)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Locale (java.util.Locale)2 QName (javax.xml.namespace.QName)2 Source (javax.xml.transform.Source)2 SoapEnvelope (org.springframework.ws.soap.SoapEnvelope)2 Attachment (com.consol.citrus.samples.todolist.model.Attachment)1 TodoEntry (com.consol.citrus.samples.todolist.model.TodoEntry)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringWriter (java.io.StringWriter)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1