use of org.apache.catalina.Container in project tomee by apache.
the class LiveReloadInstaller method install.
public static void install(String path, final int port, final String folder) {
final Server server = TomcatHelper.getServer();
if (server == null) {
throw new IllegalStateException("tomcat not yet starting");
}
// checking which one is localhost could be better but should be fine
final Service service = server.findServices()[0];
final Engine engine = Engine.class.cast(service.getContainer());
final Container host = engine.findChild(engine.getDefaultHost());
if (LifecycleState.STARTED != host.getState()) {
throw new IllegalStateException("host not started, call LiveReloadInstaller.install() later.");
}
// add connector
final Connector connector = new Connector();
connector.setPort(port);
connector.setAttribute("connectionTimeout", "30000");
service.addConnector(connector);
// and the endpoint and start the watcher
final Closeable watch = Instances.get().getWatcher().watch(folder);
final LiveReloadWebapp liveReloadWebapp = new LiveReloadWebapp(path);
liveReloadWebapp.addApplicationLifecycleListener(new ServletContextListener() {
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
servletContextEvent.getServletContext().log("Started livereload server on port " + port);
}
@Override
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
try {
watch.close();
} catch (final IOException e) {
// no-op: not that important, we shutdown anyway
}
}
});
host.addChild(liveReloadWebapp);
}
use of org.apache.catalina.Container in project tomee by apache.
the class TomcatWsRegistry method addWsContainer.
// String webContext, String path, HttpListener httpListener, String virtualHost, String realmName, String transportGuarantee, String authMethod, ClassLoader classLoader
@Override
public List<String> addWsContainer(final HttpListener httpListener, final ClassLoader classLoader, final String context, String virtualHost, String path, final String realmName, final String transportGuarantee, final String authMethod, final String moduleId) throws Exception {
if (path == null) {
throw new NullPointerException("contextRoot is null");
}
if (httpListener == null) {
throw new NullPointerException("httpListener is null");
}
// assure context root with a leading slash
if (!path.startsWith("/")) {
path = "/" + path;
}
// find the existing host (we do not auto-create hosts)
if (virtualHost == null) {
virtualHost = engine.getDefaultHost();
}
final Container host = engine.findChild(virtualHost);
if (host == null) {
throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?");
}
final List<String> addresses = new ArrayList<>();
// - old way (/*)
if (WEBSERVICE_OLDCONTEXT_ACTIVE) {
deployInFakeWebapp(path, classLoader, authMethod, transportGuarantee, realmName, host, httpListener, addresses, context);
}
// - new way (/<webappcontext>/webservices/<name>) if webcontext is specified
if (context != null) {
final Context webAppContext = findContext(context, moduleId, host);
if (webAppContext != null) {
// sub context = '/' means the service address is provided by webservices
if (WEBSERVICE_SUB_CONTEXT.equals("/") && path.startsWith("/")) {
addServlet(host, webAppContext, path, httpListener, path, addresses, false, moduleId);
} else if (WEBSERVICE_SUB_CONTEXT.equals("/") && !path.startsWith("/")) {
addServlet(host, webAppContext, '/' + path, httpListener, path, addresses, false, moduleId);
} else {
addServlet(host, webAppContext, WEBSERVICE_SUB_CONTEXT + path, httpListener, path, addresses, false, moduleId);
}
} else if (!WEBSERVICE_OLDCONTEXT_ACTIVE) {
// deploying in a jar
deployInFakeWebapp(path, classLoader, authMethod, transportGuarantee, realmName, host, httpListener, addresses, context);
}
}
return addresses;
}
use of org.apache.catalina.Container in project tomee by apache.
the class WebappDeployer method check.
private void check() {
final StandardServer server = TomcatHelper.getServer();
for (final Service service : server.findServices()) {
if (service.getContainer() instanceof Engine) {
final Engine engine = (Engine) service.getContainer();
for (final Container engineChild : engine.findChildren()) {
if (engineChild instanceof StandardHost) {
final StandardHost host = (StandardHost) engineChild;
webappBuilder.checkHost(host);
}
}
}
}
}
use of org.apache.catalina.Container 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.Container in project tomee by apache.
the class TomcatHessianRegistry method undeploy.
@Override
public void undeploy(final String hostname, final String app, final String name) {
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);
final Pair<Context, Integer> fakeContext = fakeContexts.get(contextRoot);
if (fakeContext != null) {
fakeContext.setValue(fakeContext.getValue() - 1);
if (fakeContext.getValue() == 0) {
fakeContexts.remove(contextRoot);
host.removeChild(fakeContext.getKey());
}
}
}
Aggregations