use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class PECoyoteConnector method requestStartEvent.
/*
* Request/response related probe events
*/
/**
* Fires probe event related to the fact that the given request has
* been entered the web container.
*
* @param request the request object
* @param host the virtual server to which the request was mapped
* @param context the Context to which the request was mapped
*/
@Override
public void requestStartEvent(HttpServletRequest request, Host host, Context context) {
if (requestProbeProvider != null) {
String appName = null;
if (context instanceof WebModule) {
appName = ((WebModule) context).getMonitoringNodeName();
}
String hostName = null;
if (host != null) {
hostName = host.getName();
}
requestProbeProvider.requestStartEvent(appName, hostName, request.getServerName(), request.getServerPort(), request.getContextPath(), request.getServletPath());
}
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class J2EEInstanceListener method instanceEvent.
public void instanceEvent(InstanceEvent event) {
Context context = (Context) event.getWrapper().getParent();
if (!(context instanceof WebModule)) {
return;
}
WebModule wm = (WebModule) context;
init(wm);
InstanceEvent.EventType eventType = event.getType();
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, LogFacade.INSTANCE_EVENT, eventType);
}
if (eventType.isBefore) {
handleBeforeEvent(event, eventType);
} else {
handleAfterEvent(event, eventType);
}
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class J2EEInstanceListener method handleAfterEvent.
private void handleAfterEvent(InstanceEvent event, InstanceEvent.EventType eventType) {
Wrapper wrapper = event.getWrapper();
Context context = (Context) wrapper.getParent();
if (!(context instanceof WebModule)) {
return;
}
WebModule wm = (WebModule) context;
Object instance;
if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT) {
instance = event.getFilter();
} else {
instance = event.getServlet();
}
if (instance == null) {
return;
}
// Emit monitoring probe event
if (instance instanceof Servlet) {
if (eventType == InstanceEvent.EventType.AFTER_INIT_EVENT) {
wm.servletInitializedEvent(wrapper.getName());
} else if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
wm.servletDestroyedEvent(wrapper.getName());
}
}
// EE invocation context
try {
if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT && !DefaultServlet.class.equals(instance.getClass()) && !JspServlet.class.equals(instance.getClass())) {
injectionMgr.destroyManagedObject(instance, false);
}
} catch (InjectionException ie) {
String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
msg = MessageFormat.format(msg, new Object[] { eventType, wm });
_logger.log(Level.SEVERE, msg, ie);
}
ComponentInvocation inv = new WebComponentInvocation(wm, instance);
try {
im.postInvoke(inv);
} catch (Exception ex) {
String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
msg = MessageFormat.format(msg, new Object[] { eventType, wm });
throw new RuntimeException(msg, ex);
} finally {
if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
if (tm != null) {
tm.componentDestroyed(instance, inv);
}
} else if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT || eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
// Emit monitoring probe event
if (eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
ServletResponse response = event.getResponse();
int status = -1;
if (response != null && response instanceof HttpServletResponse) {
status = ((HttpServletResponse) response).getStatus();
}
wm.afterServiceEvent(wrapper.getName(), status);
}
// BEGIN IASRI# 4646060
if (im.getCurrentInvocation() == null) {
// END IASRI# 4646060
try {
// clear security context
Realm ra = context.getRealm();
if (ra != null && (ra instanceof RealmInitializer)) {
// cleanup not only securitycontext but also PolicyContext
((RealmInitializer) ra).logout();
}
} catch (Exception ex) {
String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
msg = MessageFormat.format(msg, new Object[] { eventType, wm });
_logger.log(Level.SEVERE, msg, ex);
}
if (tm != null) {
try {
if (tm.getTransaction() != null) {
tm.rollback();
}
tm.cleanTxnTimeout();
} catch (Exception ex) {
}
}
}
if (tm != null) {
tm.componentDestroyed(instance, inv);
}
}
}
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class WebContainerListener method postInvoke.
private void postInvoke(WebModule ctx) {
WebModule wm = (WebModule) ctx;
ComponentInvocation inv = new WebComponentInvocation(wm);
invocationMgr.postInvoke(inv);
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class ListRestEndpointsCommand method getSpecifiedJerseyApplications.
/**
* Gets a map of Jersey container to the Jersey container name, from a given component name and list of web modules.
* If the component name is null, then this will return all Jersey applications.
* @param componentName the name of the Jersey component.
* @param modules a list of web modules.
* @return a map of Jersey containers to their names.
*/
private Map<ServletContainer, String> getSpecifiedJerseyApplications(String componentName, List<WebModule> modules) {
Map<ServletContainer, String> jerseyApplicationMap = new HashMap<>();
for (WebModule webModule : modules) {
// loop through all servlets in the given web module
for (Container container : webModule.findChildren()) {
// check that it is actually a servlet
if (container instanceof StandardWrapper) {
// cast to a servlet from generic container
StandardWrapper servlet = (StandardWrapper) container;
// if it is a jersey application servlet, and if a component name has been specified and this servlet matches
if (servlet.getServletClass() == ServletContainer.class && (componentName == null ^ servlet.getName().equals(componentName))) {
Collection<String> mappings = servlet.getMappings();
String servletMapping = null;
if (mappings.size() > 0) {
// May be represented as "path/to/resource/*", which needs to be removed
servletMapping = mappings.toArray()[0].toString().replaceAll("/\\*", "");
}
jerseyApplicationMap.put((ServletContainer) servlet.getServlet(), servletMapping);
}
}
}
}
return jerseyApplicationMap;
}
Aggregations