1   /*
2    * $Id: AxisServletWithSecurityTestCase.java 12305 2008-07-11 20:13:23Z dandiep $
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.transport.soap.axis;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.transport.http.HttpConnector;
17  import org.mule.transport.servlet.MuleReceiverServlet;
18  
19  import java.beans.ExceptionListener;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.mortbay.jetty.Server;
24  import org.mortbay.jetty.nio.SelectChannelConnector;
25  import org.mortbay.jetty.servlet.ServletHandler;
26  
27  public class AxisServletWithSecurityTestCase extends FunctionalTestCase
28  {
29      public static final int HTTP_PORT = 18088;
30  
31      private Server httpServer;
32  
33      protected String getConfigResources()
34      {
35          return "axis-servlet-security-config.xml";
36      }
37  
38      // @Override
39      protected void doSetUp() throws Exception
40      {
41          httpServer = new Server();
42          SelectChannelConnector conn = new SelectChannelConnector();
43          conn.setPort(HTTP_PORT);
44          httpServer.addConnector(conn);
45  
46          ServletHandler handler = new ServletHandler();
47          handler.addServletWithMapping(MuleReceiverServlet.class, "/services/*");
48          
49          httpServer.addHandler(handler);
50          
51          httpServer.start();
52      }
53  
54      // @Override
55      protected void doTearDown() throws Exception
56      {
57          if (httpServer != null)
58          {
59              httpServer.stop();
60              httpServer.destroy();
61          }
62      }
63  
64      public void testSecurityWithServletsUsingGet() throws Exception
65      {
66          Map props = new HashMap();
67          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
68          MuleClient client = new MuleClient();
69          MuleMessage result = client.send("http://ross:ross@localhost:" + HTTP_PORT
70                                          + "/services/mycomponent?method=echo", "test", props);
71          
72          ExceptionListener exceptionListener = 
73              muleContext.getRegistry().lookupConnector("servletConnector").getExceptionListener();
74          assertTrue(exceptionListener instanceof UnitTestExceptionStrategy);
75          
76          UnitTestExceptionStrategy utExStrat = (UnitTestExceptionStrategy)exceptionListener;
77          assertEquals(1, utExStrat.getMessagingExceptions().size());
78          
79          assertNotNull(result);
80          // assertTrue(result.getPayload() instanceof byte[]);
81      }
82  }