use of org.apache.catalina.Container in project Payara by payara.
the class StandardContext method addServlet.
/**
* Adds the given servlet instance with the given name and URL patterns
* to this servlet context, and initializes it.
*
* @param servletName the servlet name
* @param servlet the servlet instance
* @param initParams Map containing the initialization parameters for
* the servlet
* @param urlPatterns the URL patterns that will be mapped to the servlet
*
* @return the ServletRegistration through which the servlet may be
* further configured
*/
@Override
public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet, Map<String, String> initParams, String... urlPatterns) {
if (isContextInitializedCalled) {
String msg = MessageFormat.format(rb.getString(LogFacade.SERVLET_CONTEXT_ALREADY_INIT_EXCEPTION), new Object[] { "addServlet", getName() });
throw new IllegalStateException(msg);
}
if (servletName == null || servletName.length() == 0) {
throw new IllegalArgumentException(rb.getString(LogFacade.NULL_EMPTY_SERVLET_NAME_EXCEPTION));
}
if (servlet == null) {
throw new NullPointerException(rb.getString(LogFacade.NULL_SERVLET_INSTANCE_EXCEPTION));
}
if (servlet instanceof SingleThreadModel) {
throw new IllegalArgumentException("Servlet implements " + SingleThreadModel.class.getName());
}
/*
* Make sure the given Servlet instance is unique across all deployed
* contexts
*/
Container host = getParent();
if (host != null) {
for (Container child : host.findChildren()) {
if (child == this) {
// Our own context will be checked further down
continue;
}
if (((StandardContext) child).hasServlet(servlet)) {
return null;
}
}
}
/*
* Make sure the given Servlet name and instance are unique within
* this context
*/
synchronized (children) {
for (Map.Entry<String, Container> e : children.entrySet()) {
if (servletName.equals(e.getKey()) || servlet == ((StandardWrapper) e.getValue()).getServlet()) {
return null;
}
}
DynamicServletRegistrationImpl regis = (DynamicServletRegistrationImpl) servletRegisMap.get(servletName);
StandardWrapper wrapper = null;
if (regis == null) {
wrapper = (StandardWrapper) createWrapper();
} else {
// Complete preliminary servlet registration
wrapper = regis.getWrapper();
}
wrapper.setName(servletName);
wrapper.setServlet(servlet);
if (initParams != null) {
for (Map.Entry<String, String> e : initParams.entrySet()) {
wrapper.addInitParameter(e.getKey(), e.getValue());
}
}
addChild(wrapper, true, (null == regis));
if (null == regis) {
regis = (DynamicServletRegistrationImpl) servletRegisMap.get(servletName);
}
if (urlPatterns != null) {
for (String urlPattern : urlPatterns) {
addServletMapping(urlPattern, servletName, false);
}
}
return regis;
}
}
use of org.apache.catalina.Container in project Payara by payara.
the class StandardContext method loadOnStartup.
/**
* Load and initialize all servlets marked "load on startup" in the
* web application deployment descriptor.
*
* @param children Array of wrappers for all currently defined
* servlets (including those not declared load on startup)
*/
/* SJSAS 6377790
public void loadOnStartup(Container children[]){
*/
// START SJSAS 6377790
public void loadOnStartup(Container[] children) throws LifecycleException {
// END SJSAS 6377790
// Collect "load on startup" servlets that need to be initialized
Map<Integer, List<Wrapper>> map = new TreeMap<Integer, List<Wrapper>>();
for (Container aChildren : children) {
Wrapper wrapper = (Wrapper) aChildren;
int loadOnStartup = wrapper.getLoadOnStartup();
if (loadOnStartup < 0) {
continue;
}
Integer key = loadOnStartup;
List<Wrapper> list = map.get(key);
if (list == null) {
list = new ArrayList<Wrapper>();
map.put(key, list);
}
list.add(wrapper);
}
// Load the collected "load on startup" servlets
for (List<Wrapper> list : map.values()) {
for (Wrapper wrapper : list) {
try {
wrapper.load();
} catch (ServletException e) {
String msg = MessageFormat.format(rb.getString(LogFacade.SERVLET_LOAD_EXCEPTION), getName());
getServletContext().log(msg, StandardWrapper.getRootCause(e));
// START SJSAS 6377790
throw new LifecycleException(StandardWrapper.getRootCause(e));
// END SJSAS 6377790
}
}
}
}
use of org.apache.catalina.Container 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;
}
use of org.apache.catalina.Container in project Payara by payara.
the class WebContainerImpl method init.
// --------------------------------------------------------- Private Methods
private void init() {
if (initialized) {
return;
}
if (config == null) {
// use default settings
config = new WebContainerConfig();
}
container = habitat.getServiceHandle(org.glassfish.api.container.Container.class, "com.sun.enterprise.web.WebContainer");
if (container == null) {
log.severe("Cannot find webcontainer implementation");
return;
}
ActiveDescriptor<?> activeDescriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("com.sun.enterprise.web.EmbeddedWebContainer"));
if (activeDescriptor == null) {
log.severe("Cannot find embedded implementation");
return;
}
embeddedInhabitant = habitat.getServiceHandle(activeDescriptor);
try {
webContainer = (com.sun.enterprise.web.WebContainer) container.getService();
embedded = (EmbeddedWebContainer) embeddedInhabitant.getService();
if ((webContainer == null) || (embedded == null)) {
log.severe("Cannot find webcontainer implementation");
return;
}
engine = webContainer.getEngine();
if (engine == null) {
log.severe("Cannot find engine implementation");
return;
}
initialized = true;
} catch (Exception e) {
log.severe("Init exception " + e.getMessage());
}
}
use of org.apache.catalina.Container in project Payara by payara.
the class ReplicationStore method getUniqueId.
protected long getUniqueId() {
long uniqueId = 0L;
Container container = this.manager.getContainer();
if (container instanceof StandardContext) {
StandardContext ctx = (StandardContext) container;
uniqueId = ctx.getUniqueId();
}
return uniqueId;
}
Aggregations