1 7 package org.jboss.webservice.server; 8 9 11 import org.jboss.axis.AxisFault; 12 import org.jboss.axis.MessageContext; 13 import org.jboss.axis.handlers.soap.SOAPService; 14 import org.jboss.axis.message.SOAPEnvelopeAxisImpl; 15 import org.jboss.axis.providers.java.RPCInvocation; 16 import org.jboss.axis.providers.java.RPCProvider; 17 import org.jboss.axis.transport.http.HTTPConstants; 18 import org.jboss.deployment.DeploymentInfo; 19 import org.jboss.logging.Logger; 20 import org.jboss.mx.util.MBeanServerLocator; 21 import org.jboss.webservice.AxisServiceMBean; 22 import org.jboss.webservice.PortComponentInfo; 23 import org.jboss.webservice.handler.ServerHandlerChain; 24 import org.jboss.webservice.metadata.PortComponentMetaData; 25 import org.jboss.webservice.metadata.WebserviceDescriptionMetaData; 26 import org.jboss.webservice.metadata.serviceref.HandlerMetaData; 27 import org.jboss.webservice.metadata.serviceref.InitParamMetaData; 28 import org.w3c.dom.Document ; 29 30 import javax.management.MBeanServer ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.xml.namespace.QName ; 33 import javax.xml.rpc.handler.HandlerInfo ; 34 import java.lang.reflect.Method ; 35 import java.util.ArrayList ; 36 import java.util.Arrays ; 37 import java.util.HashMap ; 38 import java.util.HashSet ; 39 40 47 public abstract class InvokerProvider extends RPCProvider 48 { 49 50 static final long serialVersionUID = 3036485550614460123L; 51 private Logger log = Logger.getLogger(InvokerProvider.class); 53 54 protected MBeanServer server; 56 57 protected PortComponentInfo portComponentInfo; 59 protected ServerHandlerChain handlerChain; 61 62 70 public void initServiceDesc(SOAPService service, MessageContext msgContext) 71 throws AxisFault 72 { 73 log.debug("initServiceDesc: service=" + service.getName()); 74 75 try 76 { 77 server = MBeanServerLocator.locateJBoss(); 79 80 String wsID = (String )service.getOption(PortComponentMetaData.PARAMETER_WEBSERVICE_ID); 81 portComponentInfo = (PortComponentInfo)server.invoke(AxisServiceMBean.OBJECT_NAME, 82 "getPortComponentInfo", new Object []{wsID}, new String []{String .class.getName()}); 83 if (portComponentInfo == null) 84 throw new ServiceException("Cannot obtain port component info for: " + wsID); 85 86 initHandlerChain(); 88 } 89 catch (Exception e) 90 { 91 throw new ServiceException("Cannot initialize webservice", e); 92 } 93 94 super.initServiceDesc(service, msgContext); 96 } 97 98 101 private void initHandlerChain() throws Exception 102 { 103 ClassLoader cl = getContextClassLoader(); 104 105 HashSet handlerRoles = new HashSet (); 106 ArrayList handlerInfos = new ArrayList (); 107 108 HandlerMetaData[] handlers = portComponentInfo.getPortComponentMetaData().getHandlers(); 109 for (int i = 0; i < handlers.length; i++) 110 { 111 HandlerMetaData hMetaData = handlers[i]; 112 handlerRoles.addAll(Arrays.asList(hMetaData.getSoapRoles())); 113 114 Class hClass = cl.loadClass(hMetaData.getHandlerClass()); 115 116 HashMap hConfig = new HashMap (); 117 InitParamMetaData[] params = hMetaData.getInitParams(); 118 for (int j = 0; j < params.length; j++) 119 { 120 InitParamMetaData param = params[j]; 121 hConfig.put(param.getParamName(), param.getParamValue()); 122 } 123 QName [] hHeaders = hMetaData.getSoapHeaders(); 124 HandlerInfo info = new HandlerInfo (hClass, hConfig, hHeaders); 125 126 String serviceName = portComponentInfo.getPortComponentMetaData().getPortComponentName(); 127 log.debug("Adding server side handler to service '" + serviceName + "': " + info); 128 129 handlerInfos.add(info); 130 } 131 132 handlerChain = new ServerHandlerChain(handlerInfos, handlerRoles); 133 134 ClassLoader ccl = Thread.currentThread().getContextClassLoader(); 135 try 136 { 137 Thread.currentThread().setContextClassLoader(getContextClassLoader()); 138 139 if (handlerChain.getState() == ServerHandlerChain.STATE_CREATED) 140 { 141 handlerChain.init(null); 143 } 144 } 145 finally 146 { 147 Thread.currentThread().setContextClassLoader(ccl); 148 } 149 } 150 151 154 abstract protected ClassLoader getContextClassLoader(); 155 156 162 public void generateWSDL(MessageContext msgContext) throws AxisFault 163 { 164 HttpServletRequest req = (HttpServletRequest )msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); 165 if (req == null) 166 throw new IllegalStateException ("Cannot obtain HttpServletRequest from msg context"); 167 168 try 169 { 170 String resourcePath = (String )msgContext.getProperty(MessageContext.WSDLGEN_RESOURCE); 172 String requestURI = req.getRequestURI(); 173 174 WebserviceDescriptionMetaData webserviceDescription = portComponentInfo.getPortComponentMetaData().getWebserviceDescription(); 175 DeploymentInfo di = portComponentInfo.getDeploymentInfo(); 176 WSDLRequestHandler wsdlRequestHandler = new WSDLRequestHandler(webserviceDescription, di); 177 Document document = wsdlRequestHandler.getDocumentForPath(requestURI, resourcePath); 178 179 msgContext.setProperty("WSDL", document); 180 } 181 catch (Exception e) 182 { 183 log.error("Cannot process WSDL document", e); 184 } 185 } 186 187 public RPCInvocation createRPCInvocation(MessageContext msgContext, SOAPEnvelopeAxisImpl reqEnv, SOAPEnvelopeAxisImpl resEnv, Object obj) 188 { 189 RPCInvocation invocation = new JBossRPCInvocation(this, msgContext, reqEnv, resEnv, obj); 190 return invocation; 191 } 192 193 public PortComponentInfo getPortComponentInfo() 194 { 195 return portComponentInfo; 196 } 197 198 201 protected Class getServiceClass(String clsName, SOAPService service, MessageContext msgContext) 202 throws AxisFault 203 { 204 ClassLoader ccl = Thread.currentThread().getContextClassLoader(); 205 try 206 { 207 Thread.currentThread().setContextClassLoader(getContextClassLoader()); 210 211 String seiName = portComponentInfo.getPortComponentMetaData().getServiceEndpointInterface(); 212 return super.getServiceClass(seiName, service, msgContext); 213 } 214 finally 215 { 216 Thread.currentThread().setContextClassLoader(ccl); 217 } 218 } 219 220 224 protected String getServiceClassName(org.jboss.axis.Handler handler) 225 { 226 return portComponentInfo.getPortComponentMetaData().getServiceEndpointInterface(); 227 } 228 229 232 protected final Object invokeMethod(MessageContext msgContext, Method method, Object obj, Object [] argValues) throws Exception 233 { 234 ClassLoader ccl = Thread.currentThread().getContextClassLoader(); 235 try 236 { 237 Thread.currentThread().setContextClassLoader(getContextClassLoader()); 238 return invokeServiceEndpoint(msgContext, method, obj, argValues); 239 } 240 finally 241 { 242 Thread.currentThread().setContextClassLoader(ccl); 243 } 244 } 245 246 249 protected abstract Object invokeServiceEndpoint(MessageContext msgContext, Method method, Object obj, Object [] argValues) throws Exception ; 250 } 251 | Popular Tags |