use of org.apache.camel.component.netty.NettyServerBootstrapConfiguration in project camel by apache.
the class NettyHttpComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
NettyConfiguration config;
if (getConfiguration() != null) {
config = getConfiguration().copy();
} else {
config = new NettyHttpConfiguration();
}
HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
// merge any custom bootstrap configuration on the config
NettyServerBootstrapConfiguration bootstrapConfiguration = resolveAndRemoveReferenceParameter(parameters, "bootstrapConfiguration", NettyServerBootstrapConfiguration.class);
if (bootstrapConfiguration != null) {
Map<String, Object> options = new HashMap<String, Object>();
if (IntrospectionSupport.getProperties(bootstrapConfiguration, options, null, false)) {
IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), config, options);
}
}
// any custom security configuration
NettyHttpSecurityConfiguration securityConfiguration = resolveAndRemoveReferenceParameter(parameters, "securityConfiguration", NettyHttpSecurityConfiguration.class);
Map<String, Object> securityOptions = IntrospectionSupport.extractProperties(parameters, "securityConfiguration.");
// are we using a shared http server?
int sharedPort = -1;
NettySharedHttpServer shared = resolveAndRemoveReferenceParameter(parameters, "nettySharedHttpServer", NettySharedHttpServer.class);
if (shared != null) {
// use port number from the shared http server
LOG.debug("Using NettySharedHttpServer: {} with port: {}", shared, shared.getPort());
sharedPort = shared.getPort();
}
// we must include the protocol in the remaining
boolean hasProtocol = remaining.startsWith("http://") || remaining.startsWith("http:") || remaining.startsWith("https://") || remaining.startsWith("https:");
if (!hasProtocol) {
// http is the default protocol
remaining = "http://" + remaining;
}
boolean hasSlash = remaining.startsWith("http://") || remaining.startsWith("https://");
if (!hasSlash) {
// must have double slash after protocol
if (remaining.startsWith("http:")) {
remaining = "http://" + remaining.substring(5);
} else {
remaining = "https://" + remaining.substring(6);
}
}
LOG.debug("Netty http url: {}", remaining);
// set port on configuration which is either shared or using default values
if (sharedPort != -1) {
config.setPort(sharedPort);
} else if (config.getPort() == -1 || config.getPort() == 0) {
if (remaining.startsWith("http:")) {
config.setPort(80);
} else if (remaining.startsWith("https:")) {
config.setPort(443);
}
}
if (config.getPort() == -1) {
throw new IllegalArgumentException("Port number must be configured");
}
// configure configuration
config = parseConfiguration(config, remaining, parameters);
setProperties(config, parameters);
// validate config
config.validateConfiguration();
// create the address uri which includes the remainder parameters (which is not configuration parameters for this component)
URI u = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(remaining));
String addressUri = URISupport.createRemainingURI(u, parameters).toString();
NettyHttpEndpoint answer = new NettyHttpEndpoint(addressUri, this, config);
answer.setTimer(getTimer());
// must use a copy of the binding on the endpoint to avoid sharing same instance that can cause side-effects
if (answer.getNettyHttpBinding() == null) {
Object binding = getNettyHttpBinding();
if (binding instanceof RestNettyHttpBinding) {
NettyHttpBinding copy = ((RestNettyHttpBinding) binding).copy();
answer.setNettyHttpBinding(copy);
} else if (binding instanceof DefaultNettyHttpBinding) {
NettyHttpBinding copy = ((DefaultNettyHttpBinding) binding).copy();
answer.setNettyHttpBinding(copy);
}
}
if (headerFilterStrategy != null) {
answer.setHeaderFilterStrategy(headerFilterStrategy);
} else if (answer.getHeaderFilterStrategy() == null) {
answer.setHeaderFilterStrategy(getHeaderFilterStrategy());
}
if (securityConfiguration != null) {
answer.setSecurityConfiguration(securityConfiguration);
} else if (answer.getSecurityConfiguration() == null) {
answer.setSecurityConfiguration(getSecurityConfiguration());
}
// configure any security options
if (securityOptions != null && !securityOptions.isEmpty()) {
securityConfiguration = answer.getSecurityConfiguration();
if (securityConfiguration == null) {
securityConfiguration = new NettyHttpSecurityConfiguration();
answer.setSecurityConfiguration(securityConfiguration);
}
setProperties(securityConfiguration, securityOptions);
validateParameters(uri, securityOptions, null);
}
answer.setNettySharedHttpServer(shared);
return answer;
}
use of org.apache.camel.component.netty.NettyServerBootstrapConfiguration in project camel by apache.
the class NettyHttpTwoRoutesBootstrapConfigurationTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
// create NettyServerBootstrapConfiguration instance where we can configure the bootstrap
// option we want to use in our Camel routes. This allows us to configure this once,
// and also explicit
bootstrapConfiguration = new NettyServerBootstrapConfiguration();
bootstrapConfiguration.setBacklog(200);
bootstrapConfiguration.setConnectTimeout(5000);
bootstrapConfiguration.setKeepAlive(true);
bootstrapConfiguration.setWorkerCount(4);
// register the configuration in the registry with this key
jndi.bind("myBootstrapOptions", bootstrapConfiguration);
return jndi;
}
Aggregations