KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > axis > server > FlashAxisServiceServlet


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.net.axis.server;
9
10 import org.jboss.axis.transport.http.HTTPConstants;
11 import org.jboss.logging.Logger;
12
13 import javax.servlet.ServletException JavaDoc;
14 import javax.servlet.http.HttpServletRequest JavaDoc;
15 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
16 import javax.servlet.http.HttpServletResponse JavaDoc;
17 import java.io.IOException JavaDoc;
18
19 /**
20  * A AxisServlet that allows the Flash player/plugin to interact with the
21  * Axis SOAP engine despite the inability to generate the SOAPAction HTTP
22  * header. It spoofs the header by looking at the request parameters and
23  * generating a derived HttpServletRequestWrapper class to appear to migrate
24  * those that should actually be HTTP headers into the header. This class
25  * then just calls its base class's implementation of doPost().
26  *
27  * For example, if you were invoking the Hello World SOAP example, you would
28  * append:
29  *
30  * ?SOAPAction=\"Hello\"
31  *
32  * to the service context:
33  *
34  * /axisflash/flashservices/Hello
35  *
36  * <h3> Change History </h3>
37  * <ul>
38  * <li> jung, 02.05.2002: Outsourced the strings. </li>
39  * </ul>
40  * @author <a HREF="mailto:fbrier@multideck.com">Frederick N. Brier</a>
41  * @created 22.04.2002
42  * @version $Revision: 1.7.6.1 $
43  */

44 public class FlashAxisServiceServlet extends AxisServiceServlet
45 {
46    /**
47     * This is a spoofing class whose sole purpose is to make it appear that
48     * the HTTP "SOAPAction" parameter is actually an HTTP Header attribute.
49     */

50    public class FilteredHttpServletRequest extends HttpServletRequestWrapper JavaDoc
51    {
52       /** we keep the parameter here */
53       protected String JavaDoc soapAction;
54
55       /**
56        * Constructs an instance with the soapAction set to the value of the
57        * HTTP "SOAPAction" parameter.
58        * @param req - HttpServletRequest that is getting spoofed
59        * @exception IllegalArgumentException is thrown if either the request
60        * already had a SOAPAction header or if there is no SOAPAction
61        * parameter.
62        */

63       public FilteredHttpServletRequest(HttpServletRequest JavaDoc req)
64               throws IllegalArgumentException JavaDoc
65       {
66          super(req);
67
68          soapAction = (String JavaDoc)req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
69
70          if (null != soapAction)
71          {
72             // SOAPAction provided. Don't need spoofed request.
73
log.error(Constants.ERR_EXISTING_HEADER);
74             throw new IllegalArgumentException JavaDoc(Constants.ERR_EXISTING_HEADER);
75          }
76
77          soapAction = getParameter(HTTPConstants.HEADER_SOAP_ACTION);
78
79          if (null == soapAction)
80          {
81             log.error(Constants.ERR_MISSING_PARM);
82             throw new IllegalArgumentException JavaDoc(Constants.ERR_MISSING_PARM);
83          }
84
85          log.trace("FilteredHttpServletRequest.ctor(): Matched SOAPAction parameter");
86
87       } // of FilteredHttpServletRequest constructor
88

89       /**
90        * If there is a SOAPAction HTTP parameter, return that value instead of NULL.
91        * Otherwise, default to the base class behavior.
92        * @param name - a String specifying the header name
93        * @returns a String containing the value of the SOAPAction HTTP parameter if
94        * that is what is requested via the name parameter, otherwise returns the
95        * expected HTTP Header value, or null if the request does not have a header
96        * of that name
97        */

98
99       public String JavaDoc getHeader(String JavaDoc name)
100       {
101          log.trace("FlashAxisServiceServlet.FilteredHttpServletRequest.getHeader()");
102          if (name.equals(HTTPConstants.HEADER_SOAP_ACTION))
103          {
104             log.trace("getHeader(): Matched SOAPAction header request");
105             return soapAction;
106          }
107          else
108          {
109             log.trace("getHeader(): Not a SOAPAction header request, called base class method.");
110             return super.getHeader(name);
111          }
112       } // of method getHeader
113

114    } // of class FilteredHttpServletRequest
115

116    /**
117     * The instance logger for the service. Not using a class logger
118     * because we want to dynamically obtain the logger name from
119     * concrete sub-classes.
120     */

121    protected Logger log;
122
123    /**
124     * Creates new AxisServlet
125     */

126    public FlashAxisServiceServlet()
127    {
128       super();
129
130       log = Logger.getLogger(getClass());
131       log.trace("Constructing");
132    }
133
134    /**
135     * This method sits on top of the AxisService.doPost() acting as a filter
136     * by first creating a FilterHttpServletRequest and passing it to the base
137     * class implementation.
138     * @param req - an HttpServletRequest object that contains the request the
139     * client has made of the servlet
140     * @param resp - an HttpServletResponse object that contains the response
141     * the servlet sends to the client
142     * @exception IOException if an input or output error is detected when the
143     * servlet handles the request
144     * @exception ServletException if the request for the POST could not be
145     * handled
146     */

147    public void doPost(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
148            throws ServletException JavaDoc, IOException JavaDoc
149    {
150       HttpServletRequest JavaDoc newReq = req;
151       try
152       {
153          newReq = new FilteredHttpServletRequest(req);
154          log.trace("doPost(): Successfully created a FilteredHttpServletRequest object.");
155       }
156       catch (IllegalArgumentException JavaDoc e)
157       {
158          log.error("doPost(): Failed to create a FilteredHttpServletRequest object. Use original HttpServletRequest.");
159       }
160
161       super.doPost(newReq, res);
162    }
163
164 }
Popular Tags