use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class AppServRegistry method getWebModule.
/*
* This function is called once for every endpoint registration.
* and the WebModule corresponding to that endpoint is stored.
*/
static WebModule getWebModule(WebServiceEndpoint wsep) {
ApplicationRegistry appRegistry = org.glassfish.internal.api.Globals.getDefaultHabitat().getService(ApplicationRegistry.class);
String appName = wsep.getBundleDescriptor().getApplication().getAppName();
ApplicationInfo appInfo = appRegistry.get(appName);
WebApplication webApp = null;
if (appInfo != null) {
Collection<ModuleInfo> moduleInfos = appInfo.getModuleInfos();
Set<EngineRef> engineRefs = null;
WebBundleDescriptor requiredWbd = (WebBundleDescriptor) wsep.getBundleDescriptor();
for (ModuleInfo moduleInfo : moduleInfos) {
engineRefs = moduleInfo.getEngineRefs();
for (EngineRef engineRef : engineRefs) {
if (engineRef.getApplicationContainer() instanceof WebApplication) {
webApp = (WebApplication) engineRef.getApplicationContainer();
WebBundleDescriptor wbd = webApp.getDescriptor();
if (wbd.equals(requiredWbd)) {
// WebApp corresponding to wsep is found.
break;
} else {
webApp = null;
}
}
}
}
}
// get the required WebModule from the webApp.
if (webApp != null) {
String requiredModule = ((WebBundleDescriptor) wsep.getBundleDescriptor()).getModuleName();
Set<WebModule> webModules = webApp.getWebModules();
for (WebModule wm : webModules) {
if (wm.getModuleName().equalsIgnoreCase(requiredModule)) {
return wm;
}
}
}
return null;
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class ListRestEndpointsCommand method getEndpointMap.
/**
* Returns a list of a map of endpoint -> list of methods.
* @param appName the name of the application.
* @throws IllegalArgumentException if the application does not contain endpoints. Specifies the reason.
*/
public Map<String, Set<String>> getEndpointMap(String appName) {
// Create an initial array
Map<String, Set<String>> endpoints = new TreeMap<>();
// Get all deployed applications
ApplicationRegistry appRegistry = habitat.getService(ApplicationRegistry.class);
// Get the deployed application with the provided name
ApplicationInfo appInfo = getSpecifiedApplication(appName, appRegistry);
// Check if the given application exists
if (appInfo == null) {
throw new IllegalArgumentException("Application " + appName + " is not registered.");
}
// Get the web modules from the given application (e.g. multiple wars in an ear)
List<WebModule> modules = getWebModules(appInfo);
// Check if the given application exists
if (modules.isEmpty()) {
throw new IllegalArgumentException("Application " + appName + " contains no web modules.");
}
// Get the Jersey applications from all of the modules (or only the one matching the given component name)
Map<ServletContainer, String> jerseyApplicationMap = getSpecifiedJerseyApplications(componentName, modules);
// error out in the case of a non existent provided component or no components at all
if (jerseyApplicationMap.isEmpty()) {
if (componentName == null) {
throw new IllegalArgumentException("Application " + appName + " has no deployed JAX-RS applications.");
}
throw new IllegalArgumentException("Component " + componentName + " could not be found.");
}
// loop through jersey components
boolean hasEndpoints = false;
for (ServletContainer jerseyApplication : jerseyApplicationMap.keySet()) {
String appRoot = jerseyApplication.getServletContext().getContextPath();
String jerseyAppRoot = jerseyApplicationMap.get(jerseyApplication);
List<Class<?>> containedClasses = getClasses(jerseyApplication);
// loop through all classes contained by given jersey application
for (Class<?> containedClass : containedClasses) {
List<RestEndpointModel> classEndpoints = getEndpointsForClass(containedClass);
if (!classEndpoints.isEmpty()) {
// loop through endpoints in given class
for (RestEndpointModel endpoint : classEndpoints) {
String path = appRoot + jerseyAppRoot + endpoint.getPath();
String method = endpoint.getRequestMethod();
if (endpoints.keySet().contains(path)) {
Set<String> methods = endpoints.get(path);
methods.add(method);
endpoints.put(path, methods);
} else {
endpoints.put(path, new TreeSet<>(asList(method)));
}
}
}
}
// Jersey will automatically generate a wadl file for the endpoints, so add
// it for every deployed application with endpoints
endpoints.put(appRoot + jerseyAppRoot + jerseyWADL, new TreeSet<>(asList(HttpMethod.GET)));
hasEndpoints = true;
}
if (!hasEndpoints) {
return null;
}
return endpoints;
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class WeldFacesConfigProvider method getResources.
@Override
public Collection<URI> getResources(ServletContext context) {
ServiceLocator defaultServices = (ServiceLocator) context.getAttribute(HABITAT_ATTRIBUTE);
invokeMgr = defaultServices.getService(InvocationManager.class);
ComponentInvocation inv = invokeMgr.getCurrentInvocation();
WebModule webModule = (WebModule) inv.getContainer();
WebBundleDescriptor wdesc = webModule.getWebBundleDescriptor();
List<URI> list = new ArrayList<URI>(1);
if (!wdesc.hasExtensionProperty(WeldDeployer.WELD_EXTENSION)) {
return list;
}
// Don't use Util.getCurrentLoader(). This config resource should
// be available from the same classloader that loaded this instance.
// Doing so allows us to be more OSGi friendly.
ClassLoader loader = this.getClass().getClassLoader();
URL resource = loader.getResource(SERVICES_FACES_CONFIG);
if (resource != null) {
try {
list.add(resource.toURI());
} catch (URISyntaxException ex) {
if (logger.isLoggable(Level.SEVERE)) {
logger.log(Level.SEVERE, CDILoggerInfo.SEVERE_ERROR_CREATING_URI_FOR_FACES_CONFIG_XML, new Object[] { resource.toExternalForm(), ex });
}
}
}
return list;
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class PECoyoteConnector method requestEndEvent.
/**
* Fires probe event related to the fact that the given request is about
* to exit from 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
* @param statusCode the response status code
*/
@Override
public void requestEndEvent(HttpServletRequest request, Host host, Context context, int statusCode) {
if (requestProbeProvider != null) {
String appName = null;
if (context instanceof WebModule) {
appName = ((WebModule) context).getMonitoringNodeName();
}
String hostName = null;
if (host != null) {
hostName = host.getName();
}
requestProbeProvider.requestEndEvent(appName, hostName, request.getServerName(), request.getServerPort(), request.getContextPath(), request.getServletPath(), statusCode, request.getMethod(), request.getRequestURI());
}
}
use of com.sun.enterprise.web.WebModule in project Payara by payara.
the class J2EEInstanceListener method handleBeforeEvent.
private void handleBeforeEvent(InstanceEvent event, InstanceEvent.EventType eventType) {
Context context = (Context) event.getWrapper().getParent();
if (!(context instanceof WebModule)) {
return;
}
WebModule wm = (WebModule) context;
Object instance;
if (eventType == InstanceEvent.EventType.BEFORE_FILTER_EVENT) {
instance = event.getFilter();
} else {
instance = event.getServlet();
}
// set security context
// BEGIN IAfSRI 4688449
// try {
Realm ra = context.getRealm();
// START OF IASRI 4713234
if (ra != null) {
ServletRequest request = event.getRequest();
if (request != null && request instanceof HttpServletRequest) {
HttpServletRequest hreq = (HttpServletRequest) request;
HttpServletRequest base = hreq;
Principal prin = hreq.getUserPrincipal();
Principal basePrincipal = prin;
boolean wrapped = false;
while (prin != null) {
if (base instanceof ServletRequestWrapper) {
// unwarp any wrappers to find the base object
ServletRequest sr = ((ServletRequestWrapper) base).getRequest();
if (sr instanceof HttpServletRequest) {
base = (HttpServletRequest) sr;
wrapped = true;
continue;
}
}
if (wrapped) {
basePrincipal = base.getUserPrincipal();
} else if (base instanceof RequestFacade) {
// when we can identify see we have the texact class.
if (base.getClass() != RequestFacade.class) {
basePrincipal = ((RequestFacade) base).getUnwrappedCoyoteRequest().getUserPrincipal();
}
} else {
basePrincipal = base.getUserPrincipal();
}
break;
}
if (prin != null && prin == basePrincipal && prin.getClass().getName().equals(SecurityConstants.WEB_PRINCIPAL_CLASS)) {
securityContext.setSecurityContextWithPrincipal(prin);
} else if (prin != basePrincipal) {
// the wrapper has overridden getUserPrincipal
// reject the request if the wrapper does not have
// the necessary permission.
checkObjectForDoAsPermission(hreq);
securityContext.setSecurityContextWithPrincipal(prin);
}
}
}
// END OF IASRI 4713234
// END IASRI 4688449
ComponentInvocation inv;
if (eventType == InstanceEvent.EventType.BEFORE_INIT_EVENT) {
// The servletName is not avaiable from servlet instance before servlet init.
// We have to pass the servletName to ComponentInvocation so it can be retrieved
// in RealmAdapter.getServletName().
inv = new WebComponentInvocation(wm, instance, event.getWrapper().getName());
} else {
inv = new WebComponentInvocation(wm, instance);
}
try {
im.preInvoke(inv);
if (eventType == InstanceEvent.EventType.BEFORE_SERVICE_EVENT) {
// Emit monitoring probe event
wm.beforeServiceEvent(event.getWrapper().getName());
// enlist resources with TM for service method
if (tm != null) {
tm.enlistComponentResources();
}
}
} catch (Exception ex) {
// See CR 6920895
im.postInvoke(inv);
String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
msg = MessageFormat.format(msg, new Object[] { eventType, wm });
throw new RuntimeException(msg, ex);
}
}
Aggregations