0

How to resolve the 400 The plain HTTP request was sent to HTTPS port issue?

from: empValidation
to: myhost:443/EmpValidation/EmpValidationAPIService
 rules.getRules().forEach(x->{
        final LoadBalanceDefinition lb =  from("jetty:http://0.0.0.0:"+rules.getPort()+"/"+x.getFrom()+"??matchOnUriPrefix=true").log(LoggingLevel.DEBUG, "Processing ${id}").log("Incoming Context Request :"+x.getFrom())
        .loadBalance().roundRobin();
        x.getTo().forEach(z->lb.to("http4://"+z+"?bridgeEndpoint=true&throwExceptionOnFailure=true").log("Outgoing mapping urls :"+z)) ;
      });

if i use "https4" component it's working the above url(empValidation) but it's not working for below url.

Url: myhost:9008/emp-web-service/services/addEmp

Error:
 javax.net.ssl.SSLHandshakeException: Remote host closed connection during 
 handshake
          at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
          at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
          at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
          at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
          at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)

I think if we use default port it's not working, what is solution for the above scenario?

1 Answers1

0

Well, it depends if the endpoint is an http or https endpoint (with server certificate to encrypt the traffic between client and server). No matter under what port number it is published.

  • If the endpoint is https enabled, you need to use URIs like https4://hostname...
  • If the endpoint is a plain http endpoint, you you need to use URIs like http4://hostname...
burki
  • 6,741
  • 1
  • 15
  • 31
  • Thanks for your reply, here the problem is i'm routing the both default port(443) and custom port(7878) url through same logic. Check below for in details. 1. myhost:443/emp-web-service/services/addEmp 2. myhost:7878/emp-web-service/services/addEmp – Naresh Dasari May 15 '18 at 15:53
  • With the single component we should route the urls. (https4 --> it's working for 443 default urls, http4 --> it's working for custom port) – Naresh Dasari May 15 '18 at 15:56
  • If you want the same line of code call both endpoints, the 2 endpoints must both be HTTPS or HTTP. If you cannot align them to use the same protocol you could use a [content based router](https://github.com/apache/camel/blob/master/camel-core/src/main/docs/eips/choice-eip.adoc) or a [recipient list](https://github.com/apache/camel/blob/master/camel-core/src/main/docs/eips/recipientList-eip.adoc) to switch to the correct endpoint based on message headers or similar characteristics. – burki May 16 '18 at 05:40
  • Or you could try to make the endpoint dynamic with `toD()`. See [here](http://camel.apache.org/message-endpoint.html) under `Dynamic To`. This way you could construct the endpoint URI as a String, put it in the message header and then call it like this: `.toD("${header.endpointUri}")` – burki May 16 '18 at 05:44