KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > server > PortComponentLinkServlet


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

7 package org.jboss.webservice.server;
8
9 // $Id: PortComponentLinkServlet.java,v 1.3.4.1 2004/11/16 11:42:23 tdiesler Exp $
10

11 import org.jboss.logging.Logger;
12 import org.jboss.mx.util.MBeanServerLocator;
13 import org.jboss.webservice.AxisServiceMBean;
14 import org.jboss.webservice.PortComponentInfo;
15
16 import javax.management.MBeanServer JavaDoc;
17 import javax.servlet.ServletException JavaDoc;
18 import javax.servlet.http.HttpServlet JavaDoc;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23
24 /**
25  * A servlet that reports the serviceURL for a given service ID.
26  * <p/>
27  * See {@link org.jboss.webservice.AxisService} for details on the registry of
28  * {@link PortComponentInfo} objects.
29  * <p/>
30  * When the web service client ENC is setup, it may contain port-component-link
31  * entries that point to service endpoints in the same top level deployment.
32  * The final serviceURL of those endpoints will become available after the
33  * reference to the javax.xml.rpc.Service is bound to JNDI.
34  * <p/>
35  * When the client does a lookup of the javax.xml.rpc.Service from JNDI the ObjectFactory
36  * will contact this servlet for the final serviceURL. It is acceptable that the client
37  * wsdl does not contain the correct serviceURL if the client is using the port-component-link element.
38  *
39  * @author Thomas.Diesler@jboss.org
40  * @since 29-May-2004
41  */

42 public class PortComponentLinkServlet extends HttpServlet JavaDoc
43 {
44    // provide logging
45
private static final Logger log = Logger.getLogger(PortComponentLinkServlet.class);
46
47    /**
48     * Get the serviceURL as string for a given serviceID.
49     */

50    protected void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws ServletException JavaDoc, IOException JavaDoc
51    {
52       String JavaDoc serviceID = req.getParameter("serviceID");
53       if (serviceID == null)
54          throw new IllegalArgumentException JavaDoc("Cannot obtain request parameter 'serviceID'");
55
56       PortComponentInfo pcInfo = null;
57       try
58       {
59          MBeanServer JavaDoc server = MBeanServerLocator.locateJBoss();
60          pcInfo = (PortComponentInfo)server.invoke(AxisServiceMBean.OBJECT_NAME, "getPortComponentInfo",
61                  new Object JavaDoc[]{serviceID}, new String JavaDoc[]{String JavaDoc.class.getName()});
62       }
63       catch (Exception JavaDoc e)
64       {
65          throw new ServletException JavaDoc(e);
66       }
67
68       if (pcInfo == null)
69          throw new IllegalStateException JavaDoc("Cannot resolve port-component-link: " + serviceID);
70
71       res.setContentType("text/plain");
72       PrintWriter JavaDoc out = res.getWriter();
73
74       String JavaDoc serviceEndpointURL = pcInfo.getServiceEndpointURL();
75       out.println(serviceEndpointURL);
76
77       log.debug("Resolved " + serviceID + " to: " + serviceEndpointURL);
78
79       out.close();
80    }
81 }
82
Popular Tags