use of org.apache.catalina.connector.Connector 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