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);
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 {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogUtils.MISSING_MONITORING_INFO, req.getRequestURI());
}
}
AdapterInvocationInfo aInfo = null;
if (!(endpointInfo instanceof Ejb2RuntimeEndpointInfo)) {
throw new IllegalArgumentException(endpointInfo + "is not instance of Ejb2RuntimeEndpointInfo.");
}
try {
Ejb2RuntimeEndpointInfo endpointInfo2 = (Ejb2RuntimeEndpointInfo)endpointInfo;
// Do ejb container pre-invocation and pre-handler
// logic
aInfo = endpointInfo2.getHandlerImplementor();
// Set message context in invocation
((EJBInvocation) aInfo.getInv()).setMessageContext(msgContext);
// Set http response object so one-way operations will
// response before actual business method invocation.
msgContext.setProperty(HTTP_SERVLET_RESPONSE, resp);
if (secServ != null) {
wssSucceded = secServ.validateRequest(endpointInfo2.getServerAuthConfig(),
(StreamingHandler)aInfo.getHandler(), msgContext);
}
// 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) {
aInfo.getHandler().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.
if (aInfo != null) {
endpointInfo.releaseImplementor(aInfo.getInv());
}
}
} else {
String errorMsg = MessageFormat.format(
logger.getResourceBundle().getString(LogUtils.NULL_MESSAGE),
endpointInfo.getEndpoint().getEndpointName(), endpointInfo.getEndpointAddressUri());
if (logger.isLoggable(Level.FINE)) {
logger.fine(errorMsg);
}
msgContext.writeSimpleErrorResponse
(FAULT_CODE_CLIENT, errorMsg);
}
if (messageID!=null || endpoint!=null) {
endpoint.processResponse(msgContext);
}
SOAPMessage reply = msgContext.getMessage();
if (secServ != null && wssSucceded) {
if (!(endpointInfo instanceof Ejb2RuntimeEndpointInfo)) {
throw new IllegalArgumentException(endpointInfo + "is not instance of Ejb2RuntimeEndpointInfo.");
}
Ejb2RuntimeEndpointInfo endpointInfo2 = (Ejb2RuntimeEndpointInfo)endpointInfo;
secServ.secureResponse(endpointInfo2.getServerAuthConfig(),(StreamingHandler)endpointInfo2.getHandlerImplementor().getHandler(),msgContext);
}
if (reply.saveRequired()) {
reply.saveChanges();
}
wsUtil.writeReply(resp, msgContext);
} catch (Throwable e) {
String errorMessage = MessageFormat.format(
logger.getResourceBundle().getString(LogUtils.ERROR_ON_EJB),
new Object[] {endpointInfo.getEndpoint().getEndpointName(),
endpointInfo.getEndpointAddressUri(), e.getMessage()});
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);
}