1 2 24 25 package com.sun.enterprise.webservice; 26 27 import java.util.Collection ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 31 import java.io.File ; 32 33 import javax.servlet.*; 34 import javax.servlet.http.*; 35 36 import com.sun.enterprise.Switch; 37 import com.sun.enterprise.ComponentInvocation; 38 import com.sun.enterprise.InvocationManager; 39 import com.sun.enterprise.deployment.WebServicesDescriptor; 40 import com.sun.enterprise.deployment.WebService; 41 import com.sun.enterprise.deployment.WebServiceEndpoint; 42 import com.sun.enterprise.deployment.WebBundleDescriptor; 43 import com.sun.enterprise.deployment.WebComponentDescriptor; 44 45 import com.sun.enterprise.webservice.monitoring.WebServiceEngineImpl; 46 import com.sun.enterprise.webservice.monitoring.JAXRPCEndpointImpl; 47 48 import com.sun.enterprise.security.jauth.ServerAuthConfig; 49 50 51 import com.sun.xml.rpc.spi.JaxRpcObjectFactory; 53 import com.sun.xml.rpc.spi.runtime.Implementor; 54 import com.sun.xml.rpc.spi.runtime.ImplementorCache; 55 import com.sun.xml.rpc.spi.runtime.ImplementorCacheDelegate; 56 import com.sun.xml.rpc.spi.runtime.RuntimeEndpointInfo; 57 import com.sun.xml.rpc.spi.runtime.ServletDelegate; 58 import com.sun.xml.rpc.spi.runtime.ServletSecondDelegate; 59 import com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate; 60 61 62 import java.util.logging.Logger ; 63 import java.util.logging.Level ; 64 import com.sun.logging.LogDomains; 65 66 72 public class ServletWebServiceDelegate extends ServletSecondDelegate { 73 74 private static Logger logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 75 76 private WebServiceEndpoint endpoint_; 77 78 private ServletConfig servletConfig_; 79 80 private ServletDelegate rpcDelegate_; 81 82 private JaxRpcObjectFactory rpcFactory_; 83 84 private WebServiceEngineImpl wsEngine_; 85 private JAXRPCEndpointImpl endpointImpl_; 86 87 public ServletWebServiceDelegate (ServletDelegate firstDelegate) { 88 rpcDelegate_ = firstDelegate; 89 rpcFactory_ = JaxRpcObjectFactory.newInstance(); 90 wsEngine_ = WebServiceEngineImpl.getInstance(); 91 } 92 93 94 public void postInit(ServletConfig servletConfig) throws ServletException { 95 96 servletConfig_ = servletConfig; 97 String servletName = "unknown"; 98 99 try { 100 InvocationManager invManager = 101 Switch.getSwitch().getInvocationManager(); 102 ComponentInvocation inv = invManager.getCurrentInvocation(); 103 Object containerContext = inv.getContainerContext(); 104 105 WebBundleDescriptor webBundle = (WebBundleDescriptor) 106 Switch.getSwitch().getDescriptorFor(containerContext); 107 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 108 servletName = servletConfig.getServletName(); 109 WebComponentDescriptor webComponent = 110 webBundle.getWebComponentByCanonicalName(servletName); 111 112 if( webComponent != null ) { 113 WebServicesDescriptor webServices = webBundle.getWebServices(); 114 Collection endpoints = 115 webServices.getEndpointsImplementedBy(webComponent); 116 endpoint_ = (WebServiceEndpoint) endpoints.iterator().next(); 119 registerEndpoint(classLoader); 120 121 SystemHandlerDelegate securityHandlerDelegate = null; 125 if (!endpoint_.hasAuthMethod()) { 126 try { 127 ServerAuthConfig config = ServerAuthConfig.getConfig 128 (com.sun.enterprise.security.jauth.AuthConfig.SOAP, 129 endpoint_.getMessageSecurityBinding(), 130 WSSCallbackHandler.getInstance()); 131 if (config != null) { 132 securityHandlerDelegate = 133 new ServletSystemHandlerDelegate(config); 134 rpcDelegate_.setSystemHandlerDelegate(securityHandlerDelegate); 135 } 136 } catch (Exception e) { 137 logger.log(Level.SEVERE, 138 "Servlet Webservice security configuration Failure", e); 139 } 140 } 141 endpointImpl_ = (JAXRPCEndpointImpl)wsEngine_.createHandler(securityHandlerDelegate, endpoint_); 143 rpcDelegate_.setSystemHandlerDelegate(endpointImpl_); 144 145 } else { 146 throw new ServletException(servletName + " not found"); 147 } 148 } catch(Throwable t) { 149 logger.log(Level.WARNING, "Servlet web service endpoint '" + 150 servletName + "' failure", t); 151 ServletException se = new ServletException(); 152 se.initCause(t); 153 throw se; 154 } 155 } 156 157 public void destroy() { 158 wsEngine_.removeHandler(endpoint_); 159 } 160 161 public void doGet(HttpServletRequest request, 162 HttpServletResponse response) throws ServletException { 163 164 WsUtil wsUtil = new WsUtil(); 166 try { 167 wsUtil.handleGet(request, response, endpoint_); 168 } catch(Exception e) { 169 logger.log(Level.WARNING, "Servlet web service endpoint '" + 170 endpoint_.getEndpointName() + "' HTTP GET error", e); 171 } 172 } 173 174 public void doPost(HttpServletRequest request, 175 HttpServletResponse response) throws ServletException { 176 177 rpcDelegate_.doPost(request, response); 178 179 } 180 181 public void warnMissingContextInformation() { 182 } 185 186 public ImplementorCache createImplementorCache(ServletConfig sc) { 187 ImplementorCache ic = rpcFactory_.createImplementorCache(sc); 188 ImplementorCacheDelegate delegate = 189 new ImplementorCacheDelegateImpl(sc); 190 ic.setDelegate(delegate); 191 return ic; 192 } 193 194 private void registerEndpoint(ClassLoader loader) 195 throws Exception { 196 197 202 RuntimeEndpointInfo endpointInfo = 203 rpcFactory_.createRuntimeEndpointInfo(); 204 205 Class serviceEndpointInterfaceClass = 206 loader.loadClass(endpoint_.getServiceEndpointInterface()); 207 Class implementationClass = 208 loader.loadClass(endpoint_.getServletImplClass()); 209 String tieClassName = endpoint_.getTieClassName(); 210 if(tieClassName != null) { 211 Class tieClass = loader.loadClass(tieClassName); 212 endpointInfo.setTieClass(tieClass); 213 } 214 215 endpointInfo.setRemoteInterface(serviceEndpointInterfaceClass); 216 endpointInfo.setImplementationClass(implementationClass); 217 218 endpointInfo.setName(endpoint_.getEndpointName()); 219 220 WebService webService = endpoint_.getWebService(); 221 222 223 228 endpointInfo.setDeployed(true); 229 endpointInfo.setPortName(endpoint_.getWsdlPort()); 230 231 endpointInfo.setServiceName(endpoint_.getServiceName()); 232 233 String uri = endpoint_.getEndpointAddressUri(); 236 uri = uri.startsWith("/") ? uri : "/" + uri; 237 endpointInfo.setUrlPattern(uri); 238 239 rpcDelegate_.registerEndpointUrlPattern(endpointInfo); 240 } 241 242 } 243 | Popular Tags |