use of org.apache.catalina.connector.Connector in project tomcat by apache.
the class StandardServiceSF method storeChildren.
/**
* Store the specified service element children.
*
* @param aWriter Current output writer
* @param indent Indentation level
* @param aService Service to store
* @param parentDesc The element description
* @throws Exception Configuration storing error
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aService, StoreDescription parentDesc) throws Exception {
if (aService instanceof StandardService) {
StandardService service = (StandardService) aService;
// Store nested <Listener> elements
LifecycleListener[] listeners = ((Lifecycle) service).findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
// Store nested <Executor> elements
Executor[] executors = service.findExecutors();
storeElementArray(aWriter, indent, executors);
Connector[] connectors = service.findConnectors();
storeElementArray(aWriter, indent, connectors);
// Store nested <Engine> element
Engine container = service.getContainer();
if (container != null) {
StoreDescription elementDesc = getRegistry().findDescription(container.getClass());
if (elementDesc != null) {
IStoreFactory factory = elementDesc.getStoreFactory();
factory.store(aWriter, indent, container);
}
}
}
}
use of org.apache.catalina.connector.Connector in project tomcat by apache.
the class Tomcat method getConnector.
// ------- Extra customization -------
// You can tune individual Tomcat objects, using internal APIs
/**
* Get the default HTTP connector that is used by the embedded
* Tomcat. It is first configured connector in the service.
* If there's no connector defined, it will create and add a default
* connector using the port and address specified in this Tomcat
* instance, and return it for further customization.
*
* @return The connector object
*/
public Connector getConnector() {
Service service = getService();
if (service.findConnectors().length > 0) {
return service.findConnectors()[0];
}
// The same as in standard Tomcat configuration.
// This creates an APR HTTP connector if AprLifecycleListener has been
// configured (created) and Tomcat Native library is available.
// Otherwise it creates a NIO HTTP connector.
Connector connector = new Connector("HTTP/1.1");
connector.setPort(port);
service.addConnector(connector);
return connector;
}
use of org.apache.catalina.connector.Connector in project tomcat by apache.
the class Tomcat method setConnector.
/**
* Set the specified connector in the service, if it is not already
* present.
* @param connector The connector instance to add
*/
public void setConnector(Connector connector) {
Service service = getService();
boolean found = false;
for (Connector serviceConnector : service.findConnectors()) {
if (connector == serviceConnector) {
found = true;
}
}
if (!found) {
service.addConnector(connector);
}
}
use of org.apache.catalina.connector.Connector in project tomcat by apache.
the class TomcatBaseTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
// Trigger loading of catalina.properties
CatalinaProperties.getProperty("foo");
File appBase = new File(getTemporaryDirectory(), "webapps");
if (!appBase.exists() && !appBase.mkdir()) {
fail("Unable to create appBase for test");
}
tomcat = new TomcatWithFastSessionIDs();
String protocol = getProtocol();
Connector connector = new Connector(protocol);
// Listen only on localhost
connector.setAttribute("address", InetAddress.getByName("localhost").getHostAddress());
// Use random free port
connector.setPort(0);
// Mainly set to reduce timeouts during async tests
connector.setAttribute("connectionTimeout", "3000");
tomcat.getService().addConnector(connector);
tomcat.setConnector(connector);
// Add AprLifecycleListener if we are using the Apr connector
if (protocol.contains("Apr")) {
StandardServer server = (StandardServer) tomcat.getServer();
AprLifecycleListener listener = new AprLifecycleListener();
listener.setSSLRandomSeed("/dev/urandom");
server.addLifecycleListener(listener);
connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
}
File catalinaBase = getTemporaryDirectory();
tomcat.setBaseDir(catalinaBase.getAbsolutePath());
tomcat.getHost().setAppBase(appBase.getAbsolutePath());
accessLogEnabled = Boolean.parseBoolean(System.getProperty("tomcat.test.accesslog", "false"));
if (accessLogEnabled) {
String accessLogDirectory = System.getProperty("tomcat.test.reports");
if (accessLogDirectory == null) {
accessLogDirectory = new File(getBuildDirectory(), "logs").toString();
}
AccessLogValve alv = new AccessLogValve();
alv.setDirectory(accessLogDirectory);
alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
tomcat.getHost().getPipeline().addValve(alv);
}
// Cannot delete the whole tempDir, because logs are there,
// but delete known subdirectories of it.
addDeleteOnTearDown(new File(catalinaBase, "webapps"));
addDeleteOnTearDown(new File(catalinaBase, "work"));
}
use of org.apache.catalina.connector.Connector in project tomcat by apache.
the class TestXxxEndpoint method testStartStopBindOnStart.
@Test
public void testStartStopBindOnStart() throws Exception {
Tomcat tomcat = getTomcatInstance();
Connector c = tomcat.getConnector();
c.setProperty("bindOnInit", "false");
File appDir = new File(getBuildDirectory(), "webapps/examples");
tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
tomcat.start();
int port = getPort();
tomcat.getConnector().stop();
Exception e = null;
ServerSocket s = null;
long pool = 0;
long nativeSocket = 0;
boolean isApr = tomcat.getConnector().getProtocolHandlerClassName().contains("Apr");
try {
// This should not throw an Exception
if (isApr) {
pool = createAprPool();
assertTrue(pool != 0);
nativeSocket = createAprSocket(port, pool);
assertTrue(nativeSocket != 0);
} else {
s = new ServerSocket(port, 100, InetAddress.getByName("localhost"));
}
} catch (Exception e1) {
e = e1;
} finally {
try {
if (isApr) {
destroyAprSocket(nativeSocket, pool);
} else if (s != null) {
s.close();
}
} catch (Exception e2) {
/* Ignore */
}
}
assertNull(e);
tomcat.getConnector().start();
}
Aggregations