001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004-2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JAxisServlet.java 7679 2005-11-17 17:10:03Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.ws.axis;
025:
026: import java.io.PrintWriter;
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import javax.naming.InitialContext;
030: import javax.naming.NamingException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033: import javax.xml.namespace.QName;
034: import org.apache.axis.AxisEngine;
035: import org.apache.axis.AxisFault;
036: import org.apache.axis.ConfigurationException;
037: import org.apache.axis.description.OperationDesc;
038: import org.apache.axis.description.ServiceDesc;
039: import org.apache.axis.server.AxisServer;
040: import org.apache.axis.transport.http.AxisServlet;
041:
042: import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
043: import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
044:
045: /**
046: * JOnAS AxisServlet version.
047: * When displaying the port list, This class set the right URL.
048: * @author Guillaume Sauthier
049: */
050: public class JAxisServlet extends AxisServlet {
051:
052: /**
053: * This method lists the available services; it is called when there is
054: * nothing to execute on a GET
055: * @param response HTTP response
056: * @param writer writer
057: * @param request HTTP request
058: * @throws ConfigurationException cannot find axis WSDDConfiguration
059: * @throws AxisFault cannot find endpoint URL
060: */
061: protected void reportAvailableServices(
062: HttpServletResponse response, PrintWriter writer,
063: HttpServletRequest request) throws ConfigurationException,
064: AxisFault {
065: AxisEngine engine = getEngine();
066:
067: response.setContentType("text/html; charset=utf-8");
068: writer.println("<h2>And now... Some Services</h2>");
069:
070: Iterator i;
071: try {
072: i = engine.getConfig().getDeployedServices();
073: } catch (ConfigurationException configException) {
074: //turn any internal configuration exceptions back into axis faults
075: //if that is what they are
076: if (configException.getContainedException() instanceof AxisFault) {
077: throw (AxisFault) configException
078: .getContainedException();
079: } else {
080: throw configException;
081: }
082: }
083:
084: // Before calling super method, add the WSDL in ServletContext
085: InitialContext iCtx;
086: AxisServer axisServer = getEngine();
087: org.objectweb.jonas_ws.deployment.api.ServiceDesc serviceDesc = null;
088: try {
089: iCtx = new InitialContext();
090: serviceDesc = (org.objectweb.jonas_ws.deployment.api.ServiceDesc) iCtx
091: .lookup("java:comp/jonas/" + axisServer.getName()
092: + "/dd");
093: } catch (NamingException e) {
094: log.debug(
095: "Cannot find ServiceDesc in context 'java:comp/jonas/"
096: + axisServer.getName() + "/dd'", e);
097: throw new AxisFault("Servlet name not found : "
098: + axisServer.getName(), e);
099: }
100:
101: writer.println("<ul>");
102: while (i.hasNext()) {
103: ServiceDesc sd = (ServiceDesc) i.next();
104: StringBuffer sb = new StringBuffer();
105: sb.append("<li>");
106: String name = sd.getName();
107: sb.append(name);
108: sb.append(" <a href=\"");
109: String endpointURL = null;
110: QName portName = getWsdlPortName(serviceDesc, name);
111: try {
112: endpointURL = serviceDesc.getWSDL().getLocation(
113: portName).toExternalForm();
114: } catch (WSDeploymentDescException e) {
115: throw new AxisFault(
116: "Cannot find endpoint URL for server "
117: + axisServer.getName() + " and port "
118: + name, e);
119: }
120: sb.append(endpointURL);
121: sb.append("?jwsdl\"><i>(wsdl)</i></a></li>");
122: writer.println(sb.toString());
123: ArrayList operations = sd.getOperations();
124: if (!operations.isEmpty()) {
125: writer.println("<ul>");
126: for (Iterator it = operations.iterator(); it.hasNext();) {
127: OperationDesc desc = (OperationDesc) it.next();
128: writer.println("<li>" + desc.getName());
129: }
130: writer.println("</ul>");
131: }
132: }
133: writer.println("</ul>");
134: }
135:
136: /**
137: * @param serviceDesc JOnAS ServiceDesc
138: * @param axisServiceName the axis service name is linked to the J2EE port-component name
139: * @return Returns the wsdl:port name
140: */
141: private QName getWsdlPortName(
142: org.objectweb.jonas_ws.deployment.api.ServiceDesc serviceDesc,
143: String axisServiceName) {
144: QName wsdlPortName = null;
145: for (Iterator p = serviceDesc.getPortComponents().iterator(); p
146: .hasNext()
147: || wsdlPortName == null;) {
148: PortComponentDesc pcd = (PortComponentDesc) p.next();
149: if (axisServiceName.equals(pcd.getServiceName())) {
150: wsdlPortName = pcd.getQName();
151: }
152: }
153: return wsdlPortName;
154: }
155:
156: }
|