1 23 24 package com.sun.enterprise.webservice; 25 26 import java.io.IOException ; 27 28 import java.util.logging.Logger ; 29 import java.util.logging.Level ; 30 import com.sun.logging.LogDomains; 31 32 import javax.xml.soap.SOAPMessage ; 33 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 36 import javax.xml.ws.handler.MessageContext.Scope; 37 import javax.xml.ws.handler.MessageContext; 38 import javax.xml.ws.handler.soap.SOAPMessageContext; 39 40 import com.sun.xml.ws.spi.runtime.RuntimeEndpointInfo; 41 import com.sun.xml.ws.server.Tie; 42 import com.sun.xml.ws.spi.runtime.WSRtObjectFactory; 43 import com.sun.xml.ws.spi.runtime.WSConnection; 44 import com.sun.xml.ws.spi.runtime.WebServiceContext; 45 46 import com.sun.enterprise.webservice.monitoring.WebServiceEngineImpl; 47 import com.sun.enterprise.webservice.monitoring.EndpointImpl; 48 import com.sun.enterprise.webservice.monitoring.HttpRequestInfoImpl; 49 import com.sun.enterprise.webservice.monitoring.HttpResponseInfoImpl; 50 import com.sun.enterprise.webservice.monitoring.ThreadLocalInfo; 51 52 57 public class Ejb3MessageDispatcher implements EjbMessageDispatcher { 58 59 private static Logger logger = 60 LogDomains.getLogger(LogDomains.EJB_LOGGER); 61 62 private static WsUtil wsUtil = new WsUtil(); 63 64 private static Tie tie = new Tie(); 66 private static WSRtObjectFactory rpcFactory = WSRtObjectFactory.newInstance(); 67 private WebServiceEngineImpl wsEngine; 68 69 70 public Ejb3MessageDispatcher() { 71 wsEngine = WebServiceEngineImpl.getInstance(); 72 } 73 74 public void invoke(HttpServletRequest req, 75 HttpServletResponse resp, 76 EjbRuntimeEndpointInfo endpointInfo) { 77 78 79 if (logger.isLoggable(Level.FINE)) { 80 logger.log(Level.FINE, "JAXWS WebServiceDispatcher " + req.getMethod() + 81 " entering for " + req.getRequestURI() + " and query string " + req.getQueryString()); 82 } 83 84 String method = req.getMethod(); 85 86 try { 87 if( method.equals("POST") ) { 88 89 handlePost(req, resp, endpointInfo); 90 91 } else if( method.equals("GET") ) { 92 93 handleGet(req, resp, endpointInfo); 94 95 } else { 96 97 String errorMessage = "Unsupported method request = [" 98 + method + "] for endpoint " + 99 endpointInfo.getEndpoint().getEndpointName() + " at " + 100 endpointInfo.getEndpointAddressUri(); 101 logger.warning(errorMessage); 102 wsUtil.writeInvalidMethodType(resp, errorMessage); 103 } 104 } catch(Exception e) { 105 logger.log(Level.WARNING, "ejb endpoint exception", e); 106 } 107 } 108 109 private void handlePost(HttpServletRequest req, 110 HttpServletResponse resp, 111 EjbRuntimeEndpointInfo endpointInfo) 112 throws IOException { 113 114 EndpointImpl endpoint = null; 115 String messageID = null; 116 117 try { 118 119 try { 120 121 RuntimeEndpointInfo jaxwsInfo = endpointInfo.prepareInvocation(true); 122 if (jaxwsInfo != null) { 123 124 endpoint = (EndpointImpl) endpointInfo.getEndpoint().getExtraAttribute(EndpointImpl.NAME); 126 127 if (endpoint!=null) { 128 if (wsEngine.hasGlobalMessageListener()) { 130 messageID = wsEngine.preProcessRequest(endpoint); 131 } 132 } else { 133 logger.fine("Missing internal monitoring info to trace " + req.getRequestURI()); 134 } 135 136 137 138 WSConnection connection = rpcFactory.createWSConnection(req, resp); 139 WebServiceContext wsCtxt = jaxwsInfo.getWebServiceContext(); 140 MessageContext msgCtxt = wsCtxt.getMessageContext(); 141 msgCtxt.put(MessageContext.SERVLET_REQUEST, req); 142 msgCtxt.setScope(MessageContext.SERVLET_REQUEST, Scope.APPLICATION); 143 msgCtxt.put(MessageContext.SERVLET_RESPONSE, resp); 144 msgCtxt.setScope(MessageContext.SERVLET_RESPONSE, Scope.APPLICATION); 145 msgCtxt.put(MessageContext.HTTP_REQUEST_METHOD, req.getMethod()); 146 msgCtxt.setScope(MessageContext.HTTP_REQUEST_METHOD, Scope.APPLICATION); 147 if (req.getQueryString() != null) { 148 msgCtxt.put(MessageContext.QUERY_STRING, req.getQueryString()); 149 msgCtxt.setScope(MessageContext.QUERY_STRING, Scope.APPLICATION); 150 } 151 if (req.getPathInfo() != null) { 152 msgCtxt.put(MessageContext.PATH_INFO, req.getPathInfo()); 153 msgCtxt.setScope(MessageContext.PATH_INFO, Scope.APPLICATION); 154 } 155 msgCtxt.put(MessageContext.HTTP_REQUEST_HEADERS, connection.getHeaders()); 156 msgCtxt.setScope(MessageContext.HTTP_REQUEST_HEADERS, Scope.APPLICATION); 157 158 msgCtxt.put(EndpointImpl.MESSAGE_ID, messageID); 160 tie.handle(connection, jaxwsInfo); 161 162 } 163 164 } finally { 165 166 endpointInfo.releaseImplementor(); 171 172 } 173 174 } catch (Throwable e) { 175 176 String errorMessage = "invocation error on ejb endpoint " + 177 endpointInfo.getEndpoint().getEndpointName() + " at " + 178 endpointInfo.getEndpointAddressUri() + " : " + e.getMessage(); 179 logger.log(Level.WARNING, errorMessage, e); 180 181 String binding = endpointInfo.getEndpoint().getProtocolBinding(); 182 WsUtil.raiseException(resp, binding, errorMessage); 183 } 184 185 if (messageID!=null) { 187 HttpResponseInfoImpl response = new HttpResponseInfoImpl(resp); 188 wsEngine.postProcessResponse(messageID, response); 189 } 190 } 191 192 private void handleGet(HttpServletRequest req, 193 HttpServletResponse resp, 194 EjbRuntimeEndpointInfo endpointInfo) 195 throws IOException 196 { 197 198 wsUtil.handleGet(req, resp, endpointInfo.getEndpoint()); 199 200 } 201 202 } 203 | Popular Tags |