use of org.apache.catalina.connector.Connector in project spring-boot by spring-projects.
the class SampleTomcatTwoConnectorsApplication method createStandardConnector.
private Connector createStandardConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setPort(port());
return connector;
}
use of org.apache.catalina.connector.Connector 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.connector.Connector in project bamboobsc by billchen198318.
the class HostUtils method getHttpPort.
public static int getHttpPort() {
int port = 8080;
MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName name;
try {
name = new ObjectName("Catalina", "type", "Server");
try {
Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
Service[] services = server.findServices();
for (Service service : services) {
for (Connector connector : service.findConnectors()) {
ProtocolHandler protocolHandler = connector.getProtocolHandler();
if (protocolHandler instanceof Http11Protocol || protocolHandler instanceof Http11AprProtocol || protocolHandler instanceof Http11NioProtocol) {
port = connector.getPort();
}
}
}
} catch (AttributeNotFoundException e) {
e.printStackTrace();
} catch (InstanceNotFoundException e) {
e.printStackTrace();
} catch (MBeanException e) {
e.printStackTrace();
} catch (ReflectionException e) {
e.printStackTrace();
}
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
return port;
}
use of org.apache.catalina.connector.Connector in project fru-paqx-parent by dellemc-symphony.
the class ContextConfig method initiateHttpConnector.
/**
* This method sets up the redirect itself, creating a connector object with the new ports and protocol
*
* @return
*/
private Connector initiateHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8085);
connector.setSecure(false);
connector.setRedirectPort(18443);
connector.setProperty("transportGuaranteeRedirectStatus", "307");
return connector;
}
use of org.apache.catalina.connector.Connector 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);
}
Aggregations