use of org.apache.coyote.ProtocolHandler 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.coyote.ProtocolHandler in project nuxeo-filesystem-connectors by nuxeo.
the class WebDavServerFeature method setUpTomcat.
protected void setUpTomcat() throws Exception {
tomcat = new Tomcat();
// for tmp dir
tomcat.setBaseDir(".");
tomcat.setHostname(HOST);
tomcat.setPort(PORT);
ProtocolHandler p = tomcat.getConnector().getProtocolHandler();
AbstractEndpoint<?> endpoint = (AbstractEndpoint<?>) getFieldValue(p, "endpoint");
// vital for clean shutdown
endpoint.setMaxKeepAliveRequests(1);
File docBase = new File(".");
Context context = tomcat.addContext(CONTEXT, docBase.getAbsolutePath());
Application app = new org.nuxeo.ecm.webdav.Application();
ApplicationAdapter conf = new ApplicationAdapter(app);
conf.getFeatures().put(ResourceConfig.FEATURE_MATCH_MATRIX_PARAMS, Boolean.TRUE);
String servletName = "testServlet";
Servlet servlet = new ServletContainer(conf);
tomcat.addServlet(CONTEXT, servletName, servlet);
context.addServletMappingDecoded("/*", servletName);
addFilter(context, servletName, "RequestContextFilter", new RequestContextFilter());
addFilter(context, servletName, "SessionCleanupFilter", new SessionCleanupFilter());
addFilter(context, servletName, "NuxeoAuthenticationFilter", new NuxeoAuthenticationFilter());
addFilter(context, servletName, "WebEngineFilter", new WebEngineFilter());
tomcat.start();
}
use of org.apache.coyote.ProtocolHandler in project tomcat70 by apache.
the class MBeanUtils method destroyMBean.
/**
* Deregister the MBean for this
* <code>Connector</code> object.
*
* @param connector The Connector to be managed
*
* @exception Exception if an MBean cannot be deregistered
* @deprecated Unused. Will be removed in Tomcat 8.0.x
*/
@Deprecated
static void destroyMBean(Connector connector, Service service) throws Exception {
// domain is engine name
String domain = service.getContainer().getName();
if (domain == null)
domain = mserver.getDefaultDomain();
ObjectName oname = createObjectName(domain, connector);
if (mserver.isRegistered(oname)) {
mserver.unregisterMBean(oname);
}
// Unregister associated request processor
String worker = null;
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof Http11Protocol) {
worker = ((Http11Protocol) handler).getName();
} else if (handler instanceof Http11NioProtocol) {
worker = ((Http11NioProtocol) handler).getName();
} else if (handler instanceof Http11AprProtocol) {
worker = ((Http11AprProtocol) handler).getName();
} else if (handler instanceof AjpProtocol) {
worker = ((AjpProtocol) handler).getName();
} else if (handler instanceof AjpAprProtocol) {
worker = ((AjpAprProtocol) handler).getName();
}
ObjectName query = new ObjectName(domain + ":type=RequestProcessor,worker=" + worker + ",*");
Set<ObjectName> results = mserver.queryNames(query, null);
for (ObjectName result : results) {
mserver.unregisterMBean(result);
}
}
use of org.apache.coyote.ProtocolHandler in project tomcat70 by apache.
the class ThreadLocalLeakPreventionListener method stopIdleThreads.
/**
* Updates each ThreadPoolExecutor with the current time, which is the time
* when a context is being stopped.
*
* @param context
* the context being stopped, used to discover all the Connectors
* of its parent Service.
*/
private void stopIdleThreads(Context context) {
if (serverStopping)
return;
if (!(context instanceof StandardContext) || !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
log.debug("Not renewing threads when the context is stopping. " + "It is not configured to do it.");
return;
}
Engine engine = (Engine) context.getParent().getParent();
Service service = engine.getService();
Connector[] connectors = service.findConnectors();
if (connectors != null) {
for (Connector connector : connectors) {
ProtocolHandler handler = connector.getProtocolHandler();
Executor executor = null;
if (handler != null) {
executor = handler.getExecutor();
}
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
threadPoolExecutor.contextStopping();
} else if (executor instanceof StandardThreadExecutor) {
StandardThreadExecutor stdThreadExecutor = (StandardThreadExecutor) executor;
stdThreadExecutor.contextStopping();
}
}
}
}
use of org.apache.coyote.ProtocolHandler in project tomcat70 by apache.
the class TestCustomSsl method doTestCustomTrustManager.
private void doTestCustomTrustManager(boolean serverTrustAll) throws Exception {
if (!TesterSupport.RFC_5746_SUPPORTED) {
// Make sure SSL renegotiation is not disabled in the JVM
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
}
Tomcat tomcat = getTomcatInstance();
Assume.assumeTrue("SSL renegotiation has to be supported for this test", TesterSupport.isRenegotiationSupported(getTomcatInstance()));
TesterSupport.configureClientCertContext(tomcat);
// Override the defaults
ProtocolHandler handler = tomcat.getConnector().getProtocolHandler();
if (handler instanceof AbstractHttp11JsseProtocol) {
((AbstractHttp11JsseProtocol<?>) handler).setTruststoreFile(null);
} else {
// Unexpected
Assert.fail("Unexpected handler type");
}
if (serverTrustAll) {
tomcat.getConnector().setAttribute("trustManagerClassName", "org.apache.tomcat.util.net.TesterSupport$TrustAllCerts");
}
// Start Tomcat
tomcat.start();
TesterSupport.configureClientSsl();
// Unprotected resource
ByteChunk res = getUrl("https://localhost:" + getPort() + "/unprotected");
Assert.assertEquals("OK", res.toString());
// Protected resource
res.recycle();
int rc = -1;
try {
rc = getUrl("https://localhost:" + getPort() + "/protected", res, null, null);
} catch (SocketException se) {
if (serverTrustAll) {
Assert.fail(se.getMessage());
se.printStackTrace();
}
} catch (SSLException he) {
if (serverTrustAll) {
Assert.fail(he.getMessage());
he.printStackTrace();
}
}
if (serverTrustAll) {
Assert.assertEquals(200, rc);
Assert.assertEquals("OK-" + TesterSupport.ROLE, res.toString());
} else {
Assert.assertTrue(rc != 200);
Assert.assertEquals("", res.toString());
}
}
Aggregations