use of org.apache.catalina.Wrapper in project tomee by apache.
the class TomcatWsRegistry method addServlet.
private void addServlet(final Container host, final Context context, final String mapping, final HttpListener httpListener, final String path, final List<String> addresses, final boolean fakeDeployment, final String moduleId) {
// build the servlet
final Wrapper wrapper = context.createWrapper();
wrapper.setName("webservice" + path.substring(1));
wrapper.setServletClass(WsServlet.class.getName());
// add servlet to context
context.addChild(wrapper);
context.addServletMappingDecoded(mapping, wrapper.getName());
final String webServicecontainerID = wrapper.getName() + WsServlet.WEBSERVICE_CONTAINER + httpListener.hashCode();
wrapper.addInitParameter(WsServlet.WEBSERVICE_CONTAINER, webServicecontainerID);
setWsContainer(context, wrapper, httpListener);
webserviceContexts.put(new Key(path, moduleId), context);
// register wsdl locations for service-ref resolution
for (final Connector connector : connectors) {
final StringBuilder fullContextpath;
if (!WEBSERVICE_OLDCONTEXT_ACTIVE && !fakeDeployment) {
String contextPath = context.getPath();
if (contextPath == null || !contextPath.isEmpty()) {
if (contextPath != null && !contextPath.startsWith("/")) {
contextPath = "/" + contextPath;
} else if (contextPath == null) {
contextPath = "/";
}
}
fullContextpath = new StringBuilder(contextPath);
if (!WEBSERVICE_SUB_CONTEXT.equals("/")) {
fullContextpath.append(WEBSERVICE_SUB_CONTEXT);
}
fullContextpath.append(path);
} else {
fullContextpath = new StringBuilder(context.getPath()).append(path);
}
try {
final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), fullContextpath.toString(), null, null);
addresses.add(address.toString());
} catch (final URISyntaxException ignored) {
// no-op
}
}
}
use of org.apache.catalina.Wrapper in project tomee by apache.
the class TomcatWsRegistry method setWsContainer.
@Override
public List<String> setWsContainer(final HttpListener httpListener, final ClassLoader classLoader, String contextRoot, String virtualHost, final ServletInfo servletInfo, final String realmName, final String transportGuarantee, final String authMethod, final String moduleId) throws Exception {
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?");
}
if ("ROOT".equals(contextRoot)) {
// doesn't happen in tomee itself but with all our tooling around
contextRoot = "";
}
if (!contextRoot.startsWith("/") && !contextRoot.isEmpty()) {
contextRoot = "/" + contextRoot;
}
final Context context = (Context) host.findChild(contextRoot);
if (context == null) {
throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName());
}
final Wrapper wrapper = (Wrapper) context.findChild(servletInfo.servletName);
if (wrapper == null) {
throw new IllegalArgumentException("Could not find servlet " + servletInfo.servletName + " in web application context " + context.getName());
}
// for Pojo web services, we need to change the servlet class which is the service implementation
// by the WsServler class
wrapper.setServletClass(WsServlet.class.getName());
if (wrapper.getServlet() != null) {
// deallocate previous one
wrapper.unload();
// reload this one withuot unloading it to keep the instance - unload is called during stop()
wrapper.load();
// boolean controlling this method call can't be set to false through API so let do it ourself
// or Reflections.set(wrapper, "instanceInitialized", false);
wrapper.getServlet().init(StandardWrapper.class.cast(wrapper));
}
setWsContainer(context, wrapper, httpListener);
// add service locations
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.startsWith("/") ? "" : "/") + contextRoot + mapping, null, null);
addresses.add(address.toString());
}
}
return addresses;
}
Aggregations