1   /*
2    * $Id: AxisServletWithSecurityTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.soap.axis;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.providers.http.HttpConnector;
15  import org.mule.providers.http.servlet.MuleReceiverServlet;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.umo.UMOMessage;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.mortbay.http.HttpContext;
23  import org.mortbay.http.SocketListener;
24  import org.mortbay.jetty.Server;
25  import org.mortbay.jetty.servlet.ServletHandler;
26  import org.mortbay.util.InetAddrPort;
27  
28  public class AxisServletWithSecurityTestCase extends FunctionalTestCase
29  {
30      public static final int HTTP_PORT = 18088;
31  
32      private Server httpServer;
33  
34      // @Override
35      protected void suitePostSetUp() throws Exception
36      {
37          httpServer = new Server();
38          SocketListener socketListener = new SocketListener(new InetAddrPort(HTTP_PORT));
39          httpServer.addListener(socketListener);
40  
41          HttpContext context = httpServer.getContext("/");
42          context.setRequestLog(null);
43  
44          ServletHandler handler = new ServletHandler();
45          handler.addServlet("MuleReceiverServlet", "/services/*", MuleReceiverServlet.class
46              .getName());
47  
48          context.addHandler(handler);
49          httpServer.start();
50      }
51  
52      // @Override
53      protected void suitePostTearDown() throws Exception
54      {
55          httpServer.stop();
56      }
57  
58      public void testSecurityWithServletsUsingGet() throws Exception
59      {
60          Map props = new HashMap();
61          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
62          MuleClient client = new MuleClient();
63          UMOMessage result = client.send("http://ross:ross@localhost:" + HTTP_PORT
64                                          + "/services/mycomponent?method=echo", "test", props);
65  
66          assertNotNull(result);
67          assertTrue(result.getPayload() instanceof byte[]);
68      }
69     
70      protected String getConfigResources()
71      {
72          return "axis-servlet-security-config.xml";
73      }
74  }