use of org.apache.catalina.Wrapper in project tomee by apache.
the class ManualDeploymentTest method run.
@Test
public void run() throws IOException {
final Configuration configuration = new Configuration().randomHttpPort();
configuration.setDir(Files.mkdirs(new File("target/" + getClass().getSimpleName() + "-tomcat")).getAbsolutePath());
try (final Container container = new Container(configuration)) {
// tomee-embedded (this "container url" is filtered: name prefix + it is a directory (target/test-classes)
final File parent = Files.mkdirs(new File("target/" + getClass().getSimpleName()));
final File war = ShrinkWrap.create(WebArchive.class, "the-webapp").addClass(Foo.class).addAsWebInfResource(EmptyAsset.INSTANCE, // activate CDI
"beans.xml").as(ExplodedExporter.class).exportExploded(parent);
final Context ctx = container.addContext("", war.getAbsolutePath());
final Wrapper wrapper = Tomcat.addServlet(ctx, "awesome", AServlet.class.getName());
ctx.addServletMappingDecoded("/awesome", wrapper.getName());
assertEquals("Awesome", IO.slurp(new URL("http://localhost:" + configuration.getHttpPort() + "/awesome")).trim());
} catch (final Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.catalina.Wrapper in project tomee by apache.
the class CXFJAXRSFilter method servletMappingIsUnderRestPath.
private boolean servletMappingIsUnderRestPath(final HttpServletRequest request) {
final HttpServletRequest unwrapped = unwrap(request);
if (!RequestFacade.class.isInstance(unwrapped)) {
return false;
}
final Request tr;
try {
tr = Request.class.cast(REQUEST.get(unwrapped));
} catch (final IllegalAccessException e) {
return false;
}
final Wrapper wrapper = tr.getWrapper();
if (wrapper == null || mapping == null) {
return false;
}
Boolean accept = mappingByServlet.get(wrapper);
if (accept == null) {
accept = false;
if (!"org.apache.catalina.servlets.DefaultServlet".equals(wrapper.getServletClass())) {
for (final String mapping : wrapper.findMappings()) {
if (!mapping.isEmpty() && !"/*".equals(mapping) && !"/".equals(mapping) && !mapping.startsWith("*") && mapping.startsWith(this.mapping)) {
accept = true;
break;
}
}
}
// else will be handed by getResourceAsStream()
mappingByServlet.putIfAbsent(wrapper, accept);
return accept;
}
return accept;
}
use of org.apache.catalina.Wrapper in project tomee by apache.
the class TomcatHessianRegistry method deploy.
@Override
public String deploy(final ClassLoader loader, final HessianServer listener, final String hostname, final String app, final String authMethod, final String transportGuarantee, final String realmName, final String name) throws URISyntaxException {
Container host = engine.findChild(hostname);
if (host == null) {
host = engine.findChild(engine.getDefaultHost());
if (host == null) {
throw new IllegalArgumentException("Invalid virtual host '" + engine.getDefaultHost() + "'. Do you have a matchiing Host entry in the server.xml?");
}
}
final String contextRoot = contextName(app);
Context context = Context.class.cast(host.findChild(contextRoot));
if (context == null) {
Pair<Context, Integer> fakeContext = fakeContexts.get(contextRoot);
if (fakeContext != null) {
context = fakeContext.getLeft();
fakeContext.setValue(fakeContext.getValue() + 1);
} else {
context = Context.class.cast(host.findChild(contextRoot));
if (context == null) {
fakeContext = fakeContexts.get(contextRoot);
if (fakeContext == null) {
context = createNewContext(loader, authMethod, transportGuarantee, realmName, app);
fakeContext = new MutablePair<>(context, 1);
fakeContexts.put(contextRoot, fakeContext);
} else {
context = fakeContext.getLeft();
fakeContext.setValue(fakeContext.getValue() + 1);
}
}
}
}
final String servletMapping = generateServletPath(name);
Wrapper wrapper = Wrapper.class.cast(context.findChild(servletMapping));
if (wrapper != null) {
throw new IllegalArgumentException("Servlet " + servletMapping + " in web application context " + context.getName() + " already exists");
}
wrapper = context.createWrapper();
wrapper.setName(HESSIAN.replace("/", "") + "_" + name);
wrapper.setServlet(new OpenEJBHessianServlet(listener));
context.addChild(wrapper);
context.addServletMappingDecoded(servletMapping, wrapper.getName());
if ("BASIC".equals(authMethod) && StandardContext.class.isInstance(context)) {
final StandardContext standardContext = StandardContext.class.cast(context);
boolean found = false;
for (final Valve v : standardContext.getPipeline().getValves()) {
if (LimitedBasicValve.class.isInstance(v) || BasicAuthenticator.class.isInstance(v)) {
found = true;
break;
}
}
if (!found) {
standardContext.addValve(new LimitedBasicValve());
}
}
final List<String> addresses = new ArrayList<>();
for (final Connector connector : connectors) {
for (final String mapping : wrapper.findMappings()) {
final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), contextRoot + mapping, null, null);
addresses.add(address.toString());
}
}
return HttpUtil.selectSingleAddress(addresses);
}
use of org.apache.catalina.Wrapper in project tomee by apache.
the class OpenEJBContextConfig method addAddedJAXWsServices.
private void addAddedJAXWsServices() {
final WebAppInfo webAppInfo = info.get();
final AppInfo appInfo = info.app();
if (webAppInfo == null || appInfo == null || "false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxws.add-missing-servlets", "true"))) {
return;
}
try {
// if no jaxws classes are here don't try anything
OpenEJBContextConfig.class.getClassLoader().loadClass("org.apache.openejb.server.webservices.WsServlet");
} catch (final ClassNotFoundException | NoClassDefFoundError e) {
return;
}
for (final ServletInfo servlet : webAppInfo.servlets) {
if (!servlet.mappings.iterator().hasNext()) {
// no need to do anything
continue;
}
for (final ParamValueInfo pv : servlet.initParams) {
if ("openejb-internal".equals(pv.name) && "true".equals(pv.value)) {
if (context.findChild(servlet.servletName) == null) {
final Wrapper wrapper = context.createWrapper();
wrapper.setName(servlet.servletName);
wrapper.setServletClass("org.apache.openejb.server.webservices.WsServlet");
// add servlet to context
context.addChild(wrapper);
context.addServletMappingDecoded(servlet.mappings.iterator().next(), wrapper.getName());
}
break;
}
}
}
}
use of org.apache.catalina.Wrapper in project tomee by apache.
the class OpenEJBContextConfig method webConfig.
@Override
protected void webConfig() {
TomcatHelper.configureJarScanner(context);
// read the real config
super.webConfig();
if (IgnoredStandardContext.class.isInstance(context)) {
// no need of jsf
return;
}
if (AppFinder.findAppContextOrWeb(context.getLoader().getClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) != null) {
final FilterDef asyncOwbFilter = new FilterDef();
asyncOwbFilter.setAsyncSupported("true");
asyncOwbFilter.setDescription("OpenEJB CDI Filter - to propagate @RequestScoped in async tasks");
asyncOwbFilter.setDisplayName("OpenEJB CDI");
asyncOwbFilter.setFilterClass(EEFilter.class.getName());
asyncOwbFilter.setFilterName(EEFilter.class.getName());
context.addFilterDef(asyncOwbFilter);
final FilterMap asyncOwbMapping = new FilterMap();
asyncOwbMapping.setFilterName(asyncOwbFilter.getFilterName());
asyncOwbMapping.addURLPattern("/*");
context.addFilterMap(asyncOwbMapping);
}
if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.jsp-development", "false"))) {
for (final Container c : context.findChildren()) {
if (Wrapper.class.isInstance(c)) {
final Wrapper servlet = Wrapper.class.cast(c);
if ("org.apache.jasper.servlet.JspServlet".equals(servlet.getServletClass())) {
servlet.addInitParameter("development", "true");
}
}
}
}
final ClassLoader classLoader = context.getLoader().getClassLoader();
// add myfaces auto-initializer if mojarra is not present
try {
classLoader.loadClass("com.sun.faces.context.SessionMap");
return;
} catch (final Throwable ignored) {
// no-op
}
try {
final Class<?> myfacesInitializer = Class.forName(MYFACES_TOMEEM_CONTAINER_INITIALIZER, true, classLoader);
final ServletContainerInitializer instance = (ServletContainerInitializer) myfacesInitializer.newInstance();
context.addServletContainerInitializer(instance, getJsfClasses(context));
// cleanup listener
context.addApplicationListener(TOMEE_MYFACES_CONTEXT_LISTENER);
} catch (final Exception | NoClassDefFoundError ignored) {
// no-op
}
}
Aggregations