Amit Patel created CAMEL-5575:
---------------------------------

             Summary: Add new HttpEndpoint Option "httpHeaderFilterStrategy" on 
Http4 component
                 Key: CAMEL-5575
                 URL: https://issues.apache.org/jira/browse/CAMEL-5575
             Project: Camel
          Issue Type: New Feature
          Components: camel-http
            Reporter: Amit Patel
            Priority: Critical
             Fix For: 2.10.1
         Attachments: HttpComponent.java

Our third-party application accepts Date as Http header, but 
HttpHeaderFilterStrategy.java filters the date. To support out third-party 
application I want new feature to add Custom http filter on a Http4 Endpoint.

I made the following changes on HttpComponent createEndpoint method  to support 
custom http filter as opetion qq on Http4 Endpoint.
  


  @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, 
Object> parameters) throws Exception {
        String addressUri = uri;
        if (!uri.startsWith("http4:") && !uri.startsWith("https4:")) {
            addressUri = remaining;
        }
        Map<String, Object> httpClientParameters = new HashMap<String, 
Object>(parameters);
        // http client can be configured from URI options
        HttpParams clientParams = configureHttpParams(parameters);
        // validate that we could resolve all httpClient. parameters as this 
component is lenient
        validateParameters(uri, parameters, "httpClient.");
        
        HttpBinding httpBinding = 
resolveAndRemoveReferenceParameter(parameters, "httpBindingRef", 
HttpBinding.class);
        if (httpBinding == null) {
            httpBinding = resolveAndRemoveReferenceParameter(parameters, 
"httpBinding", HttpBinding.class);
        }
        
        HttpHeaderFilterStrategy httpHeaderFilterStrategy = 
resolveAndRemoveReferenceParameter(
                                                                                
               parameters, "httpHeaderFilterStrategy",
                                                                                
               HttpHeaderFilterStrategy.class);
        if (httpHeaderFilterStrategy == null) {
                        httpHeaderFilterStrategy = 
resolveAndRemoveReferenceParameter(
                                                                          
parameters, "httpHeaderFilterStrategy",
                                                                          
HttpHeaderFilterStrategy.class);
        }
       

        HttpClientConfigurer httpClientConfigurer = 
resolveAndRemoveReferenceParameter(parameters, "httpClientConfigurerRef", 
HttpClientConfigurer.class);
        if (httpClientConfigurer == null) {
            httpClientConfigurer = 
resolveAndRemoveReferenceParameter(parameters, "httpClientConfigurer", 
HttpClientConfigurer.class);
        }

        HttpContext httpContext = 
resolveAndRemoveReferenceParameter(parameters, "httpContextRef", 
HttpContext.class);
        if (httpContext == null) {
            httpContext = resolveAndRemoveReferenceParameter(parameters, 
"httpContext", HttpContext.class);
        }

        X509HostnameVerifier x509HostnameVerifier = 
resolveAndRemoveReferenceParameter(parameters, "x509HostnameVerifier", 
X509HostnameVerifier.class);
        if (x509HostnameVerifier == null) {
            x509HostnameVerifier = getX509HostnameVerifier();
        }
        
        SSLContextParameters sslContextParameters = 
resolveAndRemoveReferenceParameter(parameters, "sslContextParametersRef", 
SSLContextParameters.class);
        if (sslContextParameters == null) {
            sslContextParameters = getSslContextParameters();
        }
        
        boolean secure = HttpHelper.isSecureConnection(uri);

        // create the configurer to use for this endpoint
        HttpClientConfigurer configurer = 
createHttpClientConfigurer(parameters, secure);
        URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), 
httpClientParameters);
        // create the endpoint and set the http uri to be null
        HttpEndpoint endpoint = new HttpEndpoint(endpointUri.toString(), this, 
clientParams, clientConnectionManager, configurer);
        // configure the endpoint
        setProperties(endpoint, parameters);
        // The httpUri should be start with http or https
        String httpUriAddress = addressUri;
        if (addressUri.startsWith("http4")) {
            httpUriAddress = "http" + addressUri.substring(5);
        }
        if (addressUri.startsWith("https4")) {
            httpUriAddress = "https" + addressUri.substring(6);
        }
        // restructure uri to be based on the parameters left as we dont want 
to include the Camel internal options
        // build up the http uri
        URI httpUri = URISupport.createRemainingURI(new URI(httpUriAddress), 
parameters);

        // validate http uri that end-user did not duplicate the http part that 
can be a common error
        String part = httpUri.getSchemeSpecificPart();
        if (part != null) {
            part = part.toLowerCase();
            if (part.startsWith("//http//") || part.startsWith("//https//") || 
part.startsWith("//http://";) || part.startsWith("//https://";)) {
                throw new ResolveEndpointFailedException(uri,
                        "The uri part is not configured correctly. You have 
duplicated the http(s) protocol.");
            }
        }
        endpoint.setHttpUri(httpUri);
        
        if (httpHeaderFilterStrategy != null) {
                        
endpoint.setHeaderFilterStrategy(httpHeaderFilterStrategy);
                } else {
                        setEndpointHeaderFilterStrategy(endpoint);
      }
        
        endpoint.setBinding(getHttpBinding());
        if (httpBinding != null) {
            endpoint.setHttpBinding(httpBinding);
        }
        if (httpClientConfigurer != null) {
            endpoint.setHttpClientConfigurer(httpClientConfigurer);
        }
        endpoint.setHttpContext(getHttpContext());
        if (httpContext != null) {
            endpoint.setHttpContext(httpContext);
        }
        // register port on schema registry
        int port = getPort(httpUri);
        registerPort(secure, x509HostnameVerifier, port, sslContextParameters);

        return endpoint;
    }
   
    private static int getPort(URI uri) {
        int port = uri.getPort();
        if (port < 0) {
            if ("http4".equals(uri.getScheme()) || 
"http".equals(uri.getScheme())) {
                port = 80;
            } else if ("https4".equals(uri.getScheme()) || 
"https".equals(uri.getScheme())) {
                port = 443;
            } else {
                throw new IllegalArgumentException("Unknown scheme, cannot 
determine port number for uri: " + uri);
            }
        }
        return port;
    }


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to