mkopylec / charon-spring-boot-starter

Reverse proxy implementation in form of a Spring Boot starter.
Apache License 2.0
245 stars 55 forks source link

HTTPS required? #33

Closed CSchnackenberg closed 6 years ago

CSchnackenberg commented 7 years ago

When I do this:

build.gradle

compile 'com.github.mkopylec:charon-spring-boot-starter:2.0.2'

application.properties:

charon.mappings[0].name: HTTP anyone
charon.mappings[0].path: /somepath
charon.mappings[0].destinations: http://localhost:8080/otherpath

I get this:

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/otherpath/api/": not an SSL/TLS record: 485454502f312e3120343030200d0a5472616e736665722d456e636f64696e673a206368756e6b65640d0a446174653a205468752c203237204a756c20323031372030393a31343a323420474d540d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a300d0a0d0a; nested exception is io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 485454502f312e3120343030200d0a5472616e736665722d456e636f64696e673a206368756e6b65640d0a446174653a205468752c203237204a756c20323031372030393a31343a323420474d540d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a300d0a0d0a
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:633) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:595) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:557) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at com.github.mkopylec.charon.core.http.RequestForwarder.sendRequest(RequestForwarder.java:96) ~[charon-spring-boot-starter-2.0.2.jar:na]
    at com.github.mkopylec.charon.core.http.RequestForwarder.forwardHttpRequest(RequestForwarder.java:64) ~[charon-spring-boot-starter-2.0.2.jar:na]
    at com.github.mkopylec.charon.core.http.ReverseProxyFilter.lambda$forwardToDestination$2(ReverseProxyFilter.java:123) ~[charon-spring-boot-starter-2.0.2.jar:na]
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:276) ~[spring-retry-1.1.4.RELEASE.jar:na]
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:157) ~[spring-retry-1.1.4.RELEASE.jar:na]
    at com.github.mkopylec.charon.core.http.ReverseProxyFilter.forwardToDestination(ReverseProxyFilter.java:123) ~[charon-spring-boot-starter-2.0.2.jar:na]
    at com.github.mkopylec.charon.core.http.ReverseProxyFilter.doFilterInternal(ReverseProxyFilter.java:93) ~[charon-spring-boot-starter-2.0.2.jar:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
[...]

To fix this I had to do this:

    // Disable TLS protocols required by default.
    @Bean
    public HttpClientProvider charonHttpClientProvider(
            CharonProperties charonProperties) {
        return new HttpClientProvider(charonProperties) {

            @Override
            protected RestOperations createHttpClient(MappingProperties mapping) {
                Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory();

                //requestFactory.setSslContext(sslContext); << I think not doing this is the key
                int time = mapping.getTimeout().getConnect();
                requestFactory.setConnectTimeout(time);
                requestFactory.setReadTimeout(mapping.getTimeout().getRead());

                return new RestTemplate(requestFactory);
            }
        };
    }

Is this how I have to do it? Or did I simply miss a property for that?

mkopylec commented 7 years ago

Hi, HTTPS should not be required. I have tested Charon against HTTP and HTTPS destinations and didn't find any issues. I will analyze your problem and eventually release a fix for this.

mkopylec commented 6 years ago

The newest version of Charon supports requesting HTTP and HTTPS domains.