KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > transport > http > QSListHandler


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.transport.http;
18
19 import java.io.PrintWriter JavaDoc;
20 import java.net.HttpURLConnection JavaDoc;
21
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23
24 import org.apache.axis.AxisFault;
25 import org.apache.axis.MessageContext;
26 import org.apache.axis.server.AxisServer;
27 import org.apache.axis.utils.Admin;
28 import org.apache.axis.utils.Messages;
29 import org.apache.axis.utils.XMLUtils;
30 import org.w3c.dom.Document JavaDoc;
31
32 /**
33  * The QSListHandler class is a handler which lists the AXIS Server's
34  * configuration when the query string "list" is encountered in an AXIS servlet
35  * invocation.
36  *
37  * @author Curtiss Howard (code mostly from AxisServlet class)
38  * @author Doug Davis (dug@us.ibm.com)
39  * @author Steve Loughran
40  */

41
42 public class QSListHandler extends AbstractQueryStringHandler {
43      /**
44       * Performs the action associated with this particular query string
45       * handler.
46       *
47       * @param msgContext a MessageContext object containing message context
48       * information for this query string handler.
49       * @throws AxisFault if an error occurs.
50       */

51      
52      public void invoke (MessageContext msgContext) throws AxisFault {
53           // Obtain objects relevant to the task at hand from the provided
54
// MessageContext's bag.
55

56           boolean enableList = ((Boolean JavaDoc) msgContext.getProperty
57                (HTTPConstants.PLUGIN_ENABLE_LIST)).booleanValue();
58           AxisServer engine = (AxisServer) msgContext.getProperty
59                (HTTPConstants.PLUGIN_ENGINE);
60           PrintWriter JavaDoc writer = (PrintWriter JavaDoc) msgContext.getProperty
61                (HTTPConstants.PLUGIN_WRITER);
62           HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc)
63                msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETRESPONSE);
64           
65           if (enableList) {
66                Document JavaDoc doc = Admin.listConfig (engine);
67                
68                if (doc != null) {
69                     response.setContentType ("text/xml");
70                     XMLUtils.DocumentToWriter (doc, writer);
71                }
72                
73                else {
74                     //error code is 404
75

76                     response.setStatus (HttpURLConnection.HTTP_NOT_FOUND);
77                     response.setContentType ("text/html");
78                     
79                     writer.println ("<h2>" + Messages.getMessage ("error00") +
80                          "</h2>");
81                     writer.println ("<p>" + Messages.getMessage ("noDeploy00") +
82                          "</p>");
83                }
84           }
85           
86           else {
87                // list not enable, return error
88
//error code is, what, 401
89

90                response.setStatus (HttpURLConnection.HTTP_FORBIDDEN);
91                response.setContentType ("text/html");
92                
93                writer.println ("<h2>" + Messages.getMessage ("error00") +
94                     "</h2>");
95                writer.println ("<p><i>?list</i> " +
96                     Messages.getMessage ("disabled00") + "</p>");
97           }
98      }
99 }
100
Popular Tags