本文整理了Java中org.apache.catalina.Service.addConnector()
方法的一些代码示例,展示了Service.addConnector()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Service.addConnector()
方法的具体详情如下:
包路径:org.apache.catalina.Service
类名称:Service
方法名:addConnector
[英]Add a new Connector to the set of defined Connectors, and associate it with this Service's Container.
[中]将新连接器添加到已定义的连接器集中,并将其与此服务的容器相关联。
代码示例来源:origin: SonarSource/sonarqube
static void configure(Tomcat tomcat, Props props) {
Connector httpConnector = newHttpConnector(props);
tomcat.getService().addConnector(httpConnector);
}
代码示例来源:origin: org.springframework.boot/spring-boot
private void addPreviouslyRemovedConnectors() {
Service[] services = this.tomcat.getServer().findServices();
for (Service service : services) {
Connector[] connectors = this.serviceConnectors.get(service);
if (connectors != null) {
for (Connector connector : connectors) {
service.addConnector(connector);
if (!this.autoStart) {
stopProtocolHandler(connector);
}
}
this.serviceConnectors.remove(service);
}
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void bind_to_specific_address() {
Properties p = new Properties();
p.setProperty("sonar.web.port", "9000");
p.setProperty("sonar.web.host", "1.2.3.4");
TomcatConnectors.configure(tomcat, new Props(p));
verify(tomcat.getService())
.addConnector(argThat(c -> c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress) c.getProperty("address")).getHostAddress().equals("1.2.3.4")));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void setup() {
Connector connector = new Connector(Http11NioProtocol.class.getName());
connector.setPort(0);
File baseDir = createTempDir("tomcat");
String baseDirPath = baseDir.getAbsolutePath();
this.tomcatServer = new Tomcat();
this.tomcatServer.setBaseDir(baseDirPath);
this.tomcatServer.setPort(0);
this.tomcatServer.getService().addConnector(connector);
this.tomcatServer.setConnector(connector);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void bind_to_all_addresses_by_default() {
Properties p = new Properties();
p.setProperty("sonar.web.port", "9000");
TomcatConnectors.configure(tomcat, new Props(p));
verify(tomcat.getService()).addConnector(argThat(c -> c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress) c.getProperty("address")).getHostAddress().equals("0.0.0.0")));
}
代码示例来源:origin: SonarSource/sonarqube
private void verifyHttpConnector(int expectedPort, Map<String, Object> expectedProps) {
verify(tomcat.getService()).addConnector(argThat(c -> {
if (!c.getScheme().equals("http")) {
return false;
}
if (!c.getProtocol().equals(TomcatConnectors.HTTP_PROTOCOL)) {
return false;
}
if (c.getPort() != expectedPort) {
return false;
}
for (Map.Entry<String, Object> expectedProp : expectedProps.entrySet()) {
if (!expectedProp.getValue().equals(c.getProperty(expectedProp.getKey()))) {
return false;
}
}
return true;
}));
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void test_max_post_size_for_http_connection() {
Properties properties = new Properties();
Props props = new Props(properties);
TomcatConnectors.configure(tomcat, props);
verify(tomcat.getService()).addConnector(argThat(c -> c.getMaxPostSize() == -1));
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
Tomcat tomcat = new Tomcat();
File baseDir = (this.baseDirectory != null) ? this.baseDirectory
: createTempDir("tomcat");
tomcat.setBaseDir(baseDir.getAbsolutePath());
Connector connector = new Connector(this.protocol);
tomcat.getService().addConnector(connector);
customizeConnector(connector);
tomcat.setConnector(connector);
tomcat.getHost().setAutoDeploy(false);
configureEngine(tomcat.getEngine());
for (Connector additionalConnector : this.additionalTomcatConnectors) {
tomcat.getService().addConnector(additionalConnector);
}
prepareContext(tomcat.getHost(), initializers);
return getTomcatWebServer(tomcat);
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public WebServer getWebServer(HttpHandler httpHandler) {
Tomcat tomcat = new Tomcat();
File baseDir = (this.baseDirectory != null) ? this.baseDirectory
: createTempDir("tomcat");
tomcat.setBaseDir(baseDir.getAbsolutePath());
Connector connector = new Connector(this.protocol);
tomcat.getService().addConnector(connector);
customizeConnector(connector);
tomcat.setConnector(connector);
tomcat.getHost().setAutoDeploy(false);
configureEngine(tomcat.getEngine());
TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(httpHandler);
prepareContext(tomcat.getHost(), servlet);
return new TomcatWebServer(tomcat, getPort() >= 0);
}
代码示例来源:origin: org.apache.geronimo.modules/geronimo-tomcat6
public void addConnector(Connector connector) {
embedded.addConnector(connector);
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
static void configure(Tomcat tomcat, Props props) {
Connector httpConnector = newHttpConnector(props);
tomcat.getService().addConnector(httpConnector);
}
代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core
/**
* 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);
}
}
代码示例来源:origin: myrrix/myrrix-recommender
private void configureTomcat(Tomcat tomcat, Connector connector) {
tomcat.setBaseDir(noSuchBaseDir.getAbsolutePath());
tomcat.setConnector(connector);
tomcat.getService().addConnector(connector);
}
代码示例来源:origin: org.apache.tomcat/tomcat-catalina
/**
* 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);
}
}
代码示例来源:origin: codefollower/Tomcat-Research
/**
* Get the default http connector. You can set more
* parameters - the port is already initialized.
*
* Alternatively, you can construct a Connector and set any params,
* then call addConnector(Connector)
*
* @return A connector object that can be customized
*/
public Connector getConnector() {
getServer();
if (connector != null) {
return connector;
}
// This will load Apr connector if available,
// default to nio. I'm having strange problems with apr
// XXX: jfclere weird... Don't add the AprLifecycleListener then.
// and for the use case the speed benefit wouldn't matter.
connector = new Connector("HTTP/1.1");
// connector = new Connector("org.apache.coyote.http11.Http11Protocol");
connector.setPort(port);
service.addConnector( connector );
return connector;
}
代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9
/**
* Get the default http connector. You can set more
* parameters - the port is already initialized.
*
* Alternatively, you can construct a Connector and set any params,
* then call addConnector(Connector)
*
* @return A connector object that can be customized
*/
public Connector getConnector() {
getServer();
if (connector != null) {
return connector;
}
// This will load Apr connector if available,
// default to nio. I'm having strange problems with apr
// XXX: jfclere weird... Don't add the AprLifecycleListener then.
// and for the use case the speed benefit wouldn't matter.
connector = new Connector("HTTP/1.1");
// connector = new Connector("org.apache.coyote.http11.Http11Protocol");
connector.setPort(port);
service.addConnector( connector );
return connector;
}
代码示例来源:origin: org.apache.tomcat/tomcat-catalina
/**
* Add a new Connector to the set of defined Connectors, and associate it
* with this Service's Container.
*
* @param address The IP address on which to bind
* @param port TCP port number to listen on
* @param isAjp Create a AJP/1.3 Connector
* @param isSSL Create a secure Connector
*
* @throws MBeanException error creating the connector
*/
public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException {
Service service = doGetManagedResource();
String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
Connector connector = new Connector(protocol);
if ((address!=null) && (address.length()>0)) {
connector.setProperty("address", address);
}
connector.setPort(port);
connector.setSecure(isSSL);
connector.setScheme(isSSL ? "https" : "http");
service.addConnector(connector);
}
代码示例来源:origin: org.apache.tomcat/tomcat-catalina
/**
* 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;
}
代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core
/**
* 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;
}
代码示例来源:origin: nutzam/nutzboot
@Override
public void init() throws LifecycleException {
this.tomcat = new Tomcat();
File baseDir = createTempDir("tomcat");
this.tomcat.setBaseDir(baseDir.getAbsolutePath());
Connector connector = new Connector(PROP_PROTOCOL);
connector.setPort(getPort());
connector.setURIEncoding(DEFAULT_CHARSET.name());
connector.setMaxPostSize(conf.getInt(PROP_MAX_POST_SIZE, 64 * 1024 * 1024));
String connectorKey = PRE + "connector.";
for (String key : conf.keys()) {
if (key.startsWith(connectorKey)) {
String k = key.substring(connectorKey.length());
String v = conf.get(key);
connector.setProperty(k, v);
}
}
// 设置一下最大线程数
this.tomcat.getService().addConnector(connector);
StandardThreadExecutor executor = new StandardThreadExecutor();
executor.setMaxThreads(getMaxThread());
connector.getService().addExecutor(executor);
this.tomcat.setConnector(connector);
this.tomcat.setHostname(getHost());
this.tomcat.getHost().setAutoDeploy(false);
this.tomcat.getEngine().setBackgroundProcessorDelay(30);
this.prepareContext();
}
内容来源于网络,如有侵权,请联系作者删除!