View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis.functional;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.junit.Rule;
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  public class AxisSoapHeadersTestCase extends FunctionalTestCase
24  {
25  
26      private static final String EXPECTED_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><echoResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><echoReturn xsi:type=\"xsd:string\">Test Message</echoReturn></echoResponse></soapenv:Body></soapenv:Envelope>";
27  
28      @Rule
29      public DynamicPort dynamicPort1 = new DynamicPort("port1");
30  
31      @Rule
32      public DynamicPort dynamicPort2 = new DynamicPort("port2");
33  
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "axis-soapheader-test.xml";
39      }
40  
41      @Test
42      public void testSoapRequest() throws Exception
43      {
44  
45          MuleClient client = new MuleClient(muleContext);
46          Map<String, Object> properties = new HashMap<String, Object>();
47          properties.put("http.method", "POST");
48  
49          DefaultMuleMessage soapRequest = null;
50          soapRequest = new DefaultMuleMessage(
51              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
52              + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:mule=\"http://www.muleumo.org/providers/soap/1.0\">"
53              + "<soapenv:Header>"
54              + "<Action>storeModuleInformation</Action>"
55              + // this should be ignored
56                "<mule:header>"
57              + "<mule:MULE_REPLYTO>http://localhost:62182/reply</mule:MULE_REPLYTO>"
58              + "</mule:header>"
59              + "</soapenv:Header>"
60              + "<soapenv:Body><echo soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><value0 xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">Test Message</value0></echo></soapenv:Body>"
61              + "</soapenv:Envelope>", muleContext);
62  
63          MuleMessage reply = client.send("http://localhost:" + dynamicPort1.getNumber() + "/services/component", soapRequest, properties);
64  
65          // Put this in so that no spurious exceptions are thrown
66          // TODO research and see why sometimes we get 404 or Connection refused
67          // errors without this line. Note that the test completes even when the
68          // exceptions are thrown.
69          Thread.sleep(2000);
70  
71          assertEquals(EXPECTED_RESPONSE, reply.getPayloadAsString());
72      }
73  
74  }