Search in sources :

Example 1 with WebModule

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());
    }
}
Also used : String(java.lang.String) WebModule(com.sun.enterprise.web.WebModule)

Example 2 with WebModule

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);
    }
}
Also used : AppServSecurityContext(com.sun.enterprise.security.integration.AppServSecurityContext) ServerContext(org.glassfish.internal.api.ServerContext) WebModule(com.sun.enterprise.web.WebModule)

Example 3 with WebModule

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);
            }
        }
    }
}
Also used : AppServSecurityContext(com.sun.enterprise.security.integration.AppServSecurityContext) ServerContext(org.glassfish.internal.api.ServerContext) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) RealmInitializer(com.sun.enterprise.security.integration.RealmInitializer) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebModule(com.sun.enterprise.web.WebModule) String(java.lang.String) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) JspServlet(org.apache.jasper.servlet.JspServlet) Servlet(javax.servlet.Servlet) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) DefaultServlet(org.apache.catalina.servlets.DefaultServlet)

Example 4 with WebModule

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);
}
Also used : WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebModule(com.sun.enterprise.web.WebModule)

Example 5 with WebModule

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;
}
Also used : ServletContainer(org.glassfish.jersey.servlet.ServletContainer) WebContainer(com.sun.enterprise.web.WebContainer) Container(org.apache.catalina.Container) HashMap(java.util.HashMap) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) WebModule(com.sun.enterprise.web.WebModule) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Aggregations

WebModule (com.sun.enterprise.web.WebModule)14 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)7 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)5 String (java.lang.String)5 AppServSecurityContext (com.sun.enterprise.security.integration.AppServSecurityContext)3 ServerContext (org.glassfish.internal.api.ServerContext)3 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)2 InvocationManager (org.glassfish.api.invocation.InvocationManager)2 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)2 ApplicationRegistry (org.glassfish.internal.data.ApplicationRegistry)2 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)2 RealmInitializer (com.sun.enterprise.security.integration.RealmInitializer)1 WebApplication (com.sun.enterprise.web.WebApplication)1 WebContainer (com.sun.enterprise.web.WebContainer)1 Adapter (com.sun.xml.ws.api.server.Adapter)1 TCPAdapter (com.sun.xml.ws.transport.tcp.server.TCPAdapter)1 RestEndpointModel (fish.payara.appserver.rest.endpoints.RestEndpointModel)1 URI (java.net.URI)1