1 23 package com.sun.enterprise.webservice; 24 25 import java.io.ByteArrayOutputStream ; 26 import java.io.ByteArrayInputStream ; 27 import java.io.OutputStreamWriter ; 28 import java.io.OutputStream ; 29 import java.io.InputStream ; 30 import java.io.File ; 31 import java.util.Iterator ; 32 33 import java.rmi.Remote ; 34 35 import com.sun.enterprise.deployment.WebServiceEndpoint; 36 import com.sun.enterprise.deployment.WebService; 37 import com.sun.enterprise.Switch; 38 import com.sun.ejb.Container; 39 import com.sun.ejb.containers.StatelessSessionContainer; 40 import com.sun.ejb.Invocation; 41 import com.sun.enterprise.InvocationManager; 42 43 import com.sun.enterprise.security.jauth.ServerAuthConfig; 44 import com.sun.enterprise.webservice.WSSCallbackHandler; 45 import com.sun.enterprise.webservice.monitoring.JAXWSEndpointImpl; 46 47 import javax.xml.rpc.handler.MessageContext ; 48 import javax.xml.ws.soap.SOAPBinding; 49 50 import com.sun.xml.ws.spi.runtime.RuntimeEndpointInfo; 51 import com.sun.xml.ws.spi.runtime.SystemHandlerDelegate; 52 import com.sun.xml.ws.spi.runtime.WSRtObjectFactory; 53 import com.sun.xml.ws.spi.runtime.WebServiceContext; 54 import com.sun.enterprise.deployment.EjbDescriptor; 55 import com.sun.enterprise.deployment.EjbBundleDescriptor; 56 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 57 58 import com.sun.xml.ws.server.Tie; 59 60 import java.util.logging.Logger ; 61 import java.util.logging.Level ; 62 import com.sun.logging.LogDomains; 63 64 65 73 public class EjbRuntimeEndpointInfo { 74 75 protected static Logger logger = 76 LogDomains.getLogger(LogDomains.EJB_LOGGER); 77 78 protected WebServiceEndpoint endpoint; 79 80 protected StatelessSessionContainer container; 81 82 protected Object webServiceEndpointServant; 83 84 protected ServerAuthConfig serverAuthConfig; 85 86 protected InvocationManager invManager; 87 88 private WSRtObjectFactory rpcFactory = WSRtObjectFactory.newInstance(); 89 90 private RuntimeEndpointInfo jaxWSRuntimeInfo = null; 91 92 private boolean handlersConfigured = false; 93 94 protected EjbMessageDispatcher messageDispatcher = null; 95 96 public EjbRuntimeEndpointInfo(WebServiceEndpoint webServiceEndpoint, 97 StatelessSessionContainer ejbContainer, 98 Object servant) { 99 100 endpoint = webServiceEndpoint; 101 container = ejbContainer; 102 webServiceEndpointServant = servant; 103 104 Switch theSwitch = Switch.getSwitch(); 105 invManager = theSwitch.getInvocationManager(); 106 107 try { 108 serverAuthConfig = ServerAuthConfig.getConfig 111 (com.sun.enterprise.security.jauth.AuthConfig.SOAP, 112 endpoint.getMessageSecurityBinding(), 113 WSSCallbackHandler.getInstance()); 114 } catch (com.sun.enterprise.security.jauth.AuthException ae) { 115 logger.log(Level.SEVERE, 116 "EJB Webservice security configuration Failure", ae); 117 } 118 } 119 120 public Container getContainer() { 121 return container; 122 } 123 124 public WebServiceEndpoint getEndpoint() { 125 return endpoint; 126 } 127 128 public ServerAuthConfig getServerAuthConfig() { 129 return serverAuthConfig; 130 } 131 132 public String getEndpointAddressUri() { 133 return endpoint.getEndpointAddressUri(); 134 } 135 136 public RuntimeEndpointInfo prepareInvocation(boolean doPreInvoke) 137 throws Exception { 138 139 if (jaxWSRuntimeInfo==null) { 144 synchronized(this) { 145 if(jaxWSRuntimeInfo == null) { 146 populateRuntimeEndpointInfo(); 147 } 148 } 149 } 150 151 if(doPreInvoke) { 152 Invocation inv = new Invocation(); 158 159 inv.isWebService = true; 161 inv.container = container; 162 166 inv.transactionAttribute = Container.TX_NOT_INITIALIZED; 167 168 inv.securityPermissions = Container.SEC_NOT_INITIALIZED; 173 174 javax.xml.ws.handler.MessageContext msgCtxt = rpcFactory.createMessageContext(); 177 jaxWSRuntimeInfo.getWebServiceContext().setMessageContext(msgCtxt); 178 inv.setContextData(jaxWSRuntimeInfo.getWebServiceContext()); 179 180 invManager.preInvoke(inv); 183 } 184 185 if(!handlersConfigured && doPreInvoke) { 187 synchronized(this) { 188 if(!handlersConfigured) { 189 (new WsUtil()).configureJAXWSServiceHandlers(endpoint, jaxWSRuntimeInfo); 191 jaxWSRuntimeInfo.init(); 192 handlersConfigured=true; 193 } 194 } 195 } 196 return jaxWSRuntimeInfo; 197 } 198 199 203 public RuntimeEndpointInfo initRuntimeInfo() throws Exception { 204 try { 205 return prepareInvocation(true); 206 } finally { 207 invManager.postInvoke(invManager.getCurrentInvocation()); 208 } 209 210 } 211 212 216 private void populateRuntimeEndpointInfo() { 217 if (jaxWSRuntimeInfo==null) { 219 jaxWSRuntimeInfo = rpcFactory.createRuntimeEndpointInfo(); 220 221 jaxWSRuntimeInfo.setPortName(endpoint.getWsdlPort()); 222 jaxWSRuntimeInfo.setServiceName(endpoint.getServiceName()); 223 String implClassName = endpoint.getEjbComponentImpl().getEjbClassName(); 224 try { 225 Class clazz = container.getClassLoader().loadClass(implClassName); 226 jaxWSRuntimeInfo.setImplementorClass(clazz); 227 } catch(Exception cnfe) { 228 logger.severe("Cannot load or instanciate " + implClassName); 229 } 230 231 jaxWSRuntimeInfo.setImplementor(webServiceEndpointServant); 232 233 WebServiceContext wsc = null; 237 EjbDescriptor ejbDesc = endpoint.getEjbComponentImpl(); 238 Iterator <ResourceReferenceDescriptor> it = ejbDesc.getResourceReferenceDescriptors().iterator(); 239 while(it.hasNext()) { 240 ResourceReferenceDescriptor r = it.next(); 241 if(r.isWebServiceContext()) { 242 try { 243 javax.naming.InitialContext ic = new javax.naming.InitialContext (); 244 wsc = (WebServiceContext) ic.lookup("java:comp/env/" + r.getName()); 245 break; 246 } catch (Throwable t) {} } 248 } 249 if(wsc == null) { 250 wsc = new WebServiceContextImpl(); 251 } 252 jaxWSRuntimeInfo.setWebServiceContext(wsc); 253 254 jaxWSRuntimeInfo.setBinding(rpcFactory.createBinding(endpoint.getProtocolBinding())); 256 257 WsUtil wsu = new WsUtil(); 259 wsu.setMtom(jaxWSRuntimeInfo.getBinding(), endpoint); 260 261 java.net.URL catalogURL = null; 263 File catalogFile = new File (endpoint.getBundleDescriptor().getDeploymentDescriptorDir() + 264 File.separator + "jax-ws-catalog.xml"); 265 if(catalogFile.exists()) { 266 try { 267 catalogURL = catalogFile.toURL(); 268 } catch(java.net.MalformedURLException mfue) { 269 logger.warning(" Malformed URL " + mfue.getMessage()); 270 } 271 } 272 jaxWSRuntimeInfo.setWsdlInfo(endpoint.getWebService().getWsdlFileUrl(), 273 rpcFactory.createEntityResolver(catalogURL)); 274 275 JAXWSEndpointImpl endpointImpl = (JAXWSEndpointImpl) 276 endpoint.getExtraAttribute(JAXWSEndpointImpl.NAME); 277 SystemHandlerDelegate delegate = 278 JAXWSSystemHandlerDelegateFactory.getEjbDelegate 279 (serverAuthConfig, endpoint,endpointImpl); 280 281 if (endpointImpl != null) { 283 endpointImpl.setParent(delegate); 284 jaxWSRuntimeInfo.getBinding().setSystemHandlerDelegate(endpointImpl); 285 } else { 286 jaxWSRuntimeInfo.getBinding().setSystemHandlerDelegate(delegate); 287 } 288 } 289 } 290 291 297 public void releaseImplementor() { 298 try { 299 Invocation inv = (Invocation) invManager.getCurrentInvocation(); 300 301 311 if( inv != null ) { 312 if( inv.ejb != null ) { 313 container.postInvoke(inv); 314 } else { 315 invManager.postInvoke(inv); 316 } 317 } 318 } catch(Throwable t) { 319 logger.log(Level.FINE, "", t); 320 } 321 322 } 323 324 public EjbMessageDispatcher getMessageDispatcher() { 325 if (messageDispatcher==null) { 326 messageDispatcher = new Ejb3MessageDispatcher(); 327 } 328 return messageDispatcher; 329 } 330 331 } 332 | Popular Tags |