Search in sources :

Example 1 with JettyHttpEndpoint

use of org.apache.camel.component.jetty.JettyHttpEndpoint 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);
    }
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) JettyHttpEndpoint(org.apache.camel.component.jetty.JettyHttpEndpoint) URISyntaxException(java.net.URISyntaxException) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JettyHttpEndpoint (org.apache.camel.component.jetty.JettyHttpEndpoint)1 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)1 ForwardedRequestCustomizer (org.eclipse.jetty.server.ForwardedRequestCustomizer)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)1