use of org.eclipse.jetty.server.ServerConnector in project camel by apache.
the class JettyHttpComponent9 method createConnectorJettyInternal.
protected AbstractConnector createConnectorJettyInternal(Server server, JettyHttpEndpoint endpoint, SslContextFactory sslcf) {
try {
String host = endpoint.getHttpUri().getHost();
int porto = endpoint.getPort();
org.eclipse.jetty.server.HttpConfiguration httpConfig = new org.eclipse.jetty.server.HttpConfiguration();
httpConfig.setSendServerVersion(endpoint.isSendServerVersion());
httpConfig.setSendDateHeader(endpoint.isSendDateHeader());
httpConfig.setSendDateHeader(endpoint.isSendDateHeader());
if (requestBufferSize != null) {
// Does not work
//httpConfig.setRequestBufferSize(requestBufferSize);
}
if (requestHeaderSize != null) {
httpConfig.setRequestHeaderSize(requestHeaderSize);
}
if (responseBufferSize != null) {
httpConfig.setOutputBufferSize(responseBufferSize);
}
if (responseHeaderSize != null) {
httpConfig.setResponseHeaderSize(responseHeaderSize);
}
if (useXForwardedForHeader) {
httpConfig.addCustomizer(new ForwardedRequestCustomizer());
}
HttpConnectionFactory httpFactory = new org.eclipse.jetty.server.HttpConnectionFactory(httpConfig);
ArrayList<ConnectionFactory> connectionFactories = new ArrayList<ConnectionFactory>();
ServerConnector result = new org.eclipse.jetty.server.ServerConnector(server);
if (sslcf != null) {
httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
SslConnectionFactory scf = new org.eclipse.jetty.server.SslConnectionFactory(sslcf, "HTTP/1.1");
connectionFactories.add(scf);
// The protocol name can be "SSL" or "SSL-HTTP/1.1" depending on the version of Jetty
result.setDefaultProtocol(scf.getProtocol());
}
connectionFactories.add(httpFactory);
result.setConnectionFactories(connectionFactories);
result.setPort(porto);
if (host != null) {
result.setHost(host);
}
if (getSslSocketConnectorProperties() != null && "https".equals(endpoint.getProtocol())) {
// must copy the map otherwise it will be deleted
Map<String, Object> properties = new HashMap<String, Object>(getSslSocketConnectorProperties());
IntrospectionSupport.setProperties(sslcf, properties);
if (properties.size() > 0) {
throw new IllegalArgumentException("There are " + properties.size() + " parameters that couldn't be set on the SocketConnector." + " Check the uri if the parameters are spelt correctly and that they are properties of the SelectChannelConnector." + " Unknown parameters=[" + properties + "]");
}
}
return result;
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
use of org.eclipse.jetty.server.ServerConnector in project camel by apache.
the class WssProducerTest method getConnector.
@Override
protected Connector getConnector() throws Exception {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(defineSSLContextServerParameters().createSSLContext(camelContext));
ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, null));
return https;
}
use of org.eclipse.jetty.server.ServerConnector in project camel by apache.
the class CometdComponent method connect.
/**
* Connects the URL specified on the endpoint to the specified processor.
*/
public void connect(CometdProducerConsumer prodcon) throws Exception {
Server server = null;
// Make sure that there is a connector for the requested endpoint.
CometdEndpoint endpoint = prodcon.getEndpoint();
String connectorKey = endpoint.getProtocol() + ":" + endpoint.getUri().getHost() + ":" + endpoint.getPort();
synchronized (connectors) {
ConnectorRef connectorRef = connectors.get(connectorKey);
if (connectorRef == null) {
ServerConnector connector;
server = createServer();
if ("cometds".equals(endpoint.getProtocol())) {
connector = getSslSocketConnector(server);
} else {
connector = new ServerConnector(server);
}
connector.setPort(endpoint.getPort());
connector.setHost(endpoint.getUri().getHost());
if ("localhost".equalsIgnoreCase(endpoint.getUri().getHost())) {
LOG.warn("You use localhost interface! It means that no external connections will be available." + " Don't you want to use 0.0.0.0 instead (all network interfaces)?");
}
server.addConnector(connector);
CometDServlet servlet = createServletForConnector(server, connector, endpoint);
connectorRef = new ConnectorRef(connector, servlet, server);
server.start();
connectors.put(connectorKey, connectorRef);
} else {
connectorRef.increment();
}
BayeuxServerImpl bayeux = connectorRef.servlet.getBayeux();
if (securityPolicy != null) {
bayeux.setSecurityPolicy(securityPolicy);
}
if (extensions != null) {
for (BayeuxServer.Extension extension : extensions) {
bayeux.addExtension(extension);
}
}
if (serverListeners != null) {
for (BayeuxServer.BayeuxServerListener serverListener : serverListeners) {
bayeux.addListener(serverListener);
}
}
prodcon.setBayeux(bayeux);
}
}
use of org.eclipse.jetty.server.ServerConnector in project camel by apache.
the class CometdComponent method getSslSocketConnector.
protected ServerConnector getSslSocketConnector(Server server) throws Exception {
ServerConnector sslSocketConnector = null;
if (sslContextParameters != null) {
SslContextFactory sslContextFactory = new CometdComponentSslContextFactory();
sslContextFactory.setSslContext(sslContextParameters.createSSLContext(getCamelContext()));
sslSocketConnector = new ServerConnector(server, sslContextFactory);
} else {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePassword(sslKeyPassword);
sslContextFactory.setKeyManagerPassword(sslPassword);
if (sslKeystore != null) {
sslContextFactory.setKeyStorePath(sslKeystore);
}
sslSocketConnector = new ServerConnector(server, sslContextFactory);
}
return sslSocketConnector;
}
use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.
the class WeldInitializationTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
JettyLogHandler.config();
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
EmbeddedCdiHandler context = new EmbeddedCdiHandler();
File baseDir = MavenTestingUtils.getTestResourcesDir();
context.setBaseResource(Resource.newResource(baseDir));
context.setContextPath("/");
server.setHandler(context);
// Add some servlets
context.addServlet(TimeServlet.class, "/time");
context.addServlet(RequestInfoServlet.class, "/req-info");
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverHttpURI = new URI(String.format("http://%s:%d/", host, port));
}
Aggregations