HttpServletResponse resp,
EjbRuntimeEndpointInfo endpointInfo)
throws IOException, SOAPException
{
JAXRPCEndpointImpl endpoint = null;
String messageID = null;
SOAPMessageContext msgContext = null;
try {
MimeHeaders headers = wsUtil.getHeaders(req);
if (!wsUtil.hasTextXmlContentType(headers)) {
wsUtil.writeInvalidContentType(resp);
return;
}
msgContext = rpcFactory.createSOAPMessageContext();
SOAPMessage message = createSOAPMessage(req, headers);
ServerAuthContext sAC = null;
boolean wssSucceded = true;
if (message != null) {
msgContext.setMessage(message);
// get the endpoint info
endpoint = (JAXRPCEndpointImpl) endpointInfo.getEndpoint().getExtraAttribute(EndpointImpl.NAME);
if (endpoint!=null) {
// first global notification
if (wsEngine.hasGlobalMessageListener()) {
messageID = wsEngine.preProcessRequest(endpoint);
}
} else {
logger.fine("Missing internal monitoring info to trace " + req.getRequestURI());
}
Handler implementor = null;
try {
Ejb2RuntimeEndpointInfo endpointInfo2 = (Ejb2RuntimeEndpointInfo)endpointInfo;
// Do ejb container pre-invocation and pre-handler
// logic
implementor = endpointInfo2.getHandlerImplementor(msgContext);
// Set http request object
msgContext.setProperty(HTTP_SERVLET_REQUEST, req);
// Set http response object so one-way operations will
// response before actual business method invocation.
msgContext.setProperty(HTTP_SERVLET_RESPONSE, resp);
ServerAuthConfig authConfig = endpointInfo2.getServerAuthConfig();
if (authConfig != null) {
sAC = authConfig.getAuthContext
((StreamingHandler)implementor,message);
if (sAC != null) {
wssSucceded =
WebServiceSecurity.validateRequest(msgContext,sAC);
}
}
// Trace if necessary
if (messageID!=null || (endpoint!=null && endpoint.hasListeners())) {
// create the thread local
ThreadLocalInfo threadLocalInfo =
new ThreadLocalInfo(messageID, req);
wsEngine.getThreadLocal().set(threadLocalInfo);
endpoint.processRequest(msgContext);
}
// Pass control back to jaxrpc runtime to invoke
// any handlers and call the webservice method itself,
// which will be flow back into the ejb container.
if (wssSucceded) {
implementor.handle(msgContext);
}
} finally {
// Always call release, even if an error happened
// during getImplementor(), since some of the
// preInvoke steps might have occurred. It's ok
// if implementor is null.
endpointInfo.releaseImplementor();
}
} else {
String errorMsg = "null message POSTed to ejb endpoint " +
endpointInfo.getEndpoint().getEndpointName() +
" at " + endpointInfo.getEndpointAddressUri();
logger.fine(errorMsg);
msgContext.writeSimpleErrorResponse
(FAULT_CODE_CLIENT, errorMsg);
}
if (messageID!=null || endpoint!=null) {
endpoint.processResponse(msgContext);
}
SOAPMessage reply = msgContext.getMessage();
if (sAC != null && wssSucceded) {
WebServiceSecurity.secureResponse(msgContext,sAC);
}
if (reply.saveRequired()) {
reply.saveChanges();
}
wsUtil.writeReply(resp, msgContext);
} catch (Throwable e) {
String errorMessage = "invocation error on ejb endpoint " +
endpointInfo.getEndpoint().getEndpointName() + " at " +
endpointInfo.getEndpointAddressUri();
logger.log(Level.WARNING, errorMessage, e);
SOAPMessageContext errorMsgContext =
rpcFactory.createSOAPMessageContext();
errorMsgContext.writeSimpleErrorResponse
(SOAPConstants.FAULT_CODE_SERVER, errorMessage);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
if (messageID!=null || endpoint!=null) {
endpoint.processResponse(errorMsgContext);
}
wsUtil.writeReply(resp, errorMsgContext);
}