use of com.sun.enterprise.deployment.Application in project Payara by payara.
the class EjbWebServiceServlet method dispatchToEjbEndpoint.
private void dispatchToEjbEndpoint(HttpServletRequest hreq, HttpServletResponse hresp, EjbRuntimeEndpointInfo ejbEndpoint) {
EjbEndpointFacade container = ejbEndpoint.getContainer();
ClassLoader savedClassLoader = null;
boolean authenticated = false;
try {
// Set context class loader to application class loader
savedClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(container.getEndpointClassLoader());
// compute realmName
String realmName = null;
Application app = ejbEndpoint.getEndpoint().getBundleDescriptor().getApplication();
if (app != null) {
realmName = app.getRealm();
}
if (realmName == null) {
realmName = ejbEndpoint.getEndpoint().getRealm();
}
if (realmName == null) {
// use the same logic as BasicAuthenticator
realmName = hreq.getServerName() + ":" + hreq.getServerPort();
}
try {
if (secServ != null) {
WebServiceContextImpl context = (WebServiceContextImpl) ejbEndpoint.getWebServiceContext();
authenticated = secServ.doSecurity(hreq, ejbEndpoint, realmName, context);
}
} catch (Exception e) {
// sendAuthenticationEvents(false, hreq.getRequestURI(), null);
LogHelper.log(logger, Level.WARNING, LogUtils.AUTH_FAILED, e, ejbEndpoint.getEndpoint().getEndpointName());
}
if (!authenticated) {
hresp.setHeader("WWW-Authenticate", "Basic realm=\"" + realmName + "\"");
hresp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
// depending on the jaxrpc or jax-ws version, this will return the
// right dispatcher.
EjbMessageDispatcher msgDispatcher = ejbEndpoint.getMessageDispatcher();
msgDispatcher.invoke(hreq, hresp, getServletContext(), ejbEndpoint);
} catch (Throwable t) {
logger.log(Level.WARNING, LogUtils.EXCEPTION_THROWN, t);
} finally {
// remove any security context from the thread local before returning
if (secServ != null) {
secServ.resetSecurityContext();
secServ.resetPolicyContext();
}
// Restore context class loader
Thread.currentThread().setContextClassLoader(savedClassLoader);
}
}
Aggregations