1 7 package org.jboss.webservice.server; 8 9 11 import org.jboss.axis.AxisEngine; 12 import org.jboss.axis.AxisFault; 13 import org.jboss.axis.ConfigurationException; 14 import org.jboss.axis.MessageContext; 15 import org.jboss.axis.description.OperationDesc; 16 import org.jboss.axis.description.ServiceDesc; 17 import org.jboss.axis.server.AxisServer; 18 import org.jboss.axis.transport.http.AxisServlet; 19 import org.jboss.axis.utils.XMLUtils; 20 import org.jboss.logging.Logger; 21 import org.jboss.mx.util.MBeanProxy; 22 import org.jboss.mx.util.MBeanProxyCreationException; 23 import org.jboss.mx.util.MBeanServerLocator; 24 import org.jboss.webservice.AxisServiceMBean; 25 import org.jboss.webservice.PortComponentInfo; 26 import org.w3c.dom.Document ; 27 28 import javax.management.MBeanServer ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import java.io.PrintWriter ; 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 35 43 public abstract class AbstractServlet extends AxisServlet 44 { 45 protected final Logger log = Logger.getLogger(AbstractServlet.class); 47 48 54 protected String getTransportURL(HttpServletRequest req, String serviceName) 55 { 56 return req.getRequestURI(); 57 } 58 59 protected void setupHTMLResponseHeader(HttpServletResponse res, PrintWriter writer) 60 { 61 writer.println("<head>"); 62 writer.println("<meta http-equiv='Content-Type content='text/html; charset=iso-8859-1'>"); 63 writer.println("<title>JBossWS</title>"); 64 writer.println("<link rel='stylesheet' HREF='/ws4ee/styles.css'>"); 65 writer.println("</head>"); 66 } 67 68 72 protected void reportAvailableServices(HttpServletResponse res, PrintWriter writer, HttpServletRequest req) 73 throws ConfigurationException, AxisFault 74 { 75 AxisEngine engine = getEngine(); 76 77 res.setContentType("text/html"); 78 setupHTMLResponseHeader(res, writer); 79 writer.println("<h2>And now... Some Services</h2>"); 80 writer.println("<ul>"); 81 82 AxisServiceMBean axisService = null; 84 try 85 { 86 MBeanServer server = MBeanServerLocator.locateJBoss(); 87 axisService = (AxisServiceMBean)MBeanProxy.get(AxisServiceMBean.class, AxisServiceMBean.OBJECT_NAME, server); 88 } 89 catch (MBeanProxyCreationException e) 90 { 91 throw new IllegalStateException ("Cannot obtain: " + AxisServiceMBean.OBJECT_NAME); 92 } 93 94 Iterator it = engine.getConfig().getDeployedServices(); 95 while (it.hasNext()) 96 { 97 ServiceDesc sd = (ServiceDesc)it.next(); 98 String serviceName = sd.getName(); 99 100 PortComponentInfo pcInfo = axisService.getPortComponentInfo(serviceName); 101 String serviceURL = null; 102 if (pcInfo != null) 103 { 104 serviceURL = pcInfo.getServiceEndpointURL(); 105 } 106 else 107 { 108 serviceURL = getWebappBase(req) + "/services/" + serviceName; 109 } 110 111 StringBuffer sb = new StringBuffer ("<li>" + serviceName + "<a HREF='" + serviceURL + "?wsdl'> <i>(wsdl)</i></a></li>"); 112 113 ArrayList operations = sd.getOperations(); 114 if (!operations.isEmpty()) 115 { 116 sb.append("<ul>"); 117 for (Iterator itOp = operations.iterator(); itOp.hasNext();) 118 { 119 OperationDesc desc = (OperationDesc)itOp.next(); 120 sb.append("<li>" + desc.getName() + "</li>"); 121 } 122 sb.append("</ul>"); 123 } 124 writer.println(sb.toString()); 125 } 126 writer.println("</ul>"); 127 } 128 129 132 protected void processWsdlRequest(MessageContext msgContext, HttpServletResponse res, PrintWriter writer) 133 throws AxisFault 134 { 135 String serviceURL = (String )msgContext.getProperty(MessageContext.TRANS_URL); 136 137 AxisEngine engine = getEngine(); 138 engine.generateWSDL(msgContext); 139 140 Document doc = (Document )msgContext.getProperty("WSDL"); 141 if (doc == null) 142 throw new AxisFault("Cannot get wsdl document for service: " + serviceURL); 143 144 res.setContentType("text/xml"); 145 XMLUtils.DocumentToWriter(doc, writer); 146 } 147 148 151 public AxisServer getEngine() throws AxisFault 152 { 153 try 154 { 155 MBeanServer server = MBeanServerLocator.locateJBoss(); 156 axisServer = (AxisServer)server.getAttribute(AxisServiceMBean.OBJECT_NAME, "AxisServer"); 157 } 158 catch (Exception e) 159 { 160 log.warn("Cannot access AxisService, using default server config"); 161 axisServer = super.getEngine(); 162 } 163 164 return axisServer; 165 } 166 } 167 | Popular Tags |