KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ws > axis > JAxisServlet


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004-2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JAxisServlet.java,v 1.6 2005/05/27 15:01:22 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.ws.axis;
26
27 import java.io.PrintWriter JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import javax.xml.namespace.QName JavaDoc;
35 import org.apache.axis.AxisEngine;
36 import org.apache.axis.AxisFault;
37 import org.apache.axis.ConfigurationException;
38 import org.apache.axis.description.OperationDesc;
39 import org.apache.axis.description.ServiceDesc;
40 import org.apache.axis.server.AxisServer;
41 import org.apache.axis.transport.http.AxisServlet;
42 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
43
44 /**
45  * JOnAS AxisServlet version (add multiple AxisEngine in ServletContext).
46  * @author Guillaume Sauthier
47  * @deprecated in JOnAS 4.3.0 (since Axis add this feature in their codebase)
48  */

49 public class JAxisServlet extends AxisServlet {
50
51     /**
52      * This method lists the available services; it is called when there is
53      * nothing to execute on a GET
54      * @param response HTTP response
55      * @param writer writer
56      * @param request HTTP request
57      * @throws ConfigurationException cannot find axis WSDDConfiguration
58      * @throws AxisFault cannot find endpoint URL
59      */

60     protected void reportAvailableServices(HttpServletResponse JavaDoc response,
61                                            PrintWriter JavaDoc writer,
62                                            HttpServletRequest JavaDoc request) throws
63             ConfigurationException, AxisFault {
64         AxisEngine engine = getEngine();
65
66         response.setContentType("text/html; charset=utf-8");
67         writer.println("<h2>And now... Some Services</h2>");
68
69         Iterator JavaDoc i;
70         try {
71             i = engine.getConfig().getDeployedServices();
72         } catch (ConfigurationException configException) {
73             //turn any internal configuration exceptions back into axis faults
74
//if that is what they are
75
if (configException.getContainedException() instanceof AxisFault) {
76                 throw (AxisFault) configException.getContainedException();
77             } else {
78                 throw configException;
79             }
80         }
81
82         // Before calling super method, add the WSDL in ServletContext
83
InitialContext JavaDoc iCtx;
84         AxisServer axisServer = getEngine();
85         org.objectweb.jonas_ws.deployment.api.ServiceDesc serviceDesc = null;
86         try {
87             iCtx = new InitialContext JavaDoc();
88             serviceDesc = (org.objectweb.jonas_ws.deployment.api.ServiceDesc) iCtx.lookup("java:comp/jonas/" + axisServer.getName() + "/dd");
89         } catch (NamingException JavaDoc e) {
90             throw new AxisFault("Servlet name not found : " + axisServer.getName(), e);
91         }
92
93         writer.println("<ul>");
94         while (i.hasNext()) {
95             ServiceDesc sd = (ServiceDesc) i.next();
96             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
97             sb.append("<li>");
98             String JavaDoc name = sd.getName();
99             sb.append(name);
100             sb.append(" <a HREF=\"");
101             String JavaDoc endpointURL = null;
102             try {
103                 endpointURL = serviceDesc.getWSDL().getLocation(new QName JavaDoc(name)).toExternalForm();
104             } catch (WSDeploymentDescException e) {
105                 throw new AxisFault("Cannot find endpoint URL for server " + axisServer.getName() + " and port " + name, e);
106             }
107             sb.append(endpointURL);
108             sb.append("?jwsdl\"><i>(wsdl)</i></a></li>");
109             writer.println(sb.toString());
110             ArrayList JavaDoc operations = sd.getOperations();
111             if (!operations.isEmpty()) {
112                 writer.println("<ul>");
113                 for (Iterator JavaDoc it = operations.iterator(); it.hasNext();) {
114                     OperationDesc desc = (OperationDesc) it.next();
115                     writer.println("<li>" + desc.getName());
116                 }
117                 writer.println("</ul>");
118             }
119         }
120         writer.println("</ul>");
121     }
122
123 }
Popular Tags