Hi ,

I am trying to configure the Netty4-Http for https url. I am using the
tomcat server on the server side with port 8443 configured for https. I have
created the certificate from the server machine and used the path in client
machine for configuring the keystore. I am able to work with Netty4-Http
perfectly when I use http url. but when I use https I am getting a resonse
like "No Response from the server xx.xxx.xx.xx:8443 ." error.
Please find my code below.

public class NorthboundDataWriter {

    private static final Logger LOG =
LoggerFactory.getLogger(NorthboundDataWriter.class);

    private static NorthboundDataWriter northboundDataWriter;

    public static NorthboundDataWriter getInstance() {
        if (NorthboundDataWriter.northboundDataWriter == null) {
            NorthboundDataWriter.northboundDataWriter = new
NorthboundDataWriter();
        }
        return NorthboundDataWriter.northboundDataWriter;
    }
    private final CamelContext context;

    private final Map<String, Object> headers = new HashMap<>();

    private NettyHttpEndpoint nettyHttpEndpoint;

    private final ProducerTemplate template;

    private NorthboundDataWriter() {
        this.context = new DefaultCamelContext();




        NettyHttpComponent nettyHttpComponent =
this.context.getComponent("netty4-http",org.apache.camel.component.netty4.http.NettyHttpComponent.class);

        NettyHttpConfiguration nettyconfig = new NettyHttpConfiguration();





        nettyconfig.setKeepAlive(true);
       nettyconfig.setProtocol("tcp");
      
nettyconfig.setKeyStoreResource("file:C:/Users/jdavis/Desktop/certs/keystore.jks");
       nettyconfig.setPassphrase("fcpaliaspwd");
        nettyconfig.setSync(true);
        //nettyconfig.setTcpNoDelay(true);
        nettyconfig.setReuseChannel(true);
       
//nettyconfig.setTrustStoreResource("file:C:/Users/jdavis/Desktop/certs/truststore.jks");
        nettyconfig.setRequestTimeout(30000);
        nettyconfig.setConnectTimeout(30000);
        nettyconfig.setReuseAddress(true);
       // nettyconfig.setTextline(true);
        nettyconfig.setHost("xx.xxx.xxx.xx");
        nettyconfig.setPort(8443);
        //nettyconfig.setNeedClientAuth(true);
       // nettyconfig.setDisconnect(false);
      //  nettyconfig.setDisconnectOnNoReply(false);
       // nettyconfig.setBridgeEndpoint(true);
        nettyconfig.setSsl(true);
 /*       nettyconfig.setBridgeEndpoint(true);
        nettyconfig.setClientMode(true);*/


/*       KeyStoreParameters ksp = new KeyStoreParameters();
        //ksp.setResource("C:\\Program
Files\\Java\\jdk1.8.0_101\\bin\\store.jks");
        ksp.setResource("C:/Users/jdavis/Desktop/server10Keystore");
        ksp.setPassword("changeit");

        KeyManagersParameters kmp = new KeyManagersParameters();
        kmp.setKeyStore(ksp);
        kmp.setKeyPassword("changeit");

        SSLContextParameters sslContextParameters = new
SSLContextParameters();
        sslContextParameters.setKeyManagers(kmp);*/

       // nettyconfig.setSslContextParameters(sslContextParameters);
      //  nettyHttpComponent.setConfiguration(nettyconfig);

        this.context.addComponent("fcpnettyhttpComponent",
nettyHttpComponent);
        /*try {
            this.context.addRoutes(new RouteBuilder() {

                public void configure() {
                   
from("direct:start").to("netty4-http:https://xx.xxx.xxx.xx:8443";);
                }
            });
        } catch (Exception e1) {
          LOG.error("Error in routing : ",e1);
        }*/
        this.template = this.context.createProducerTemplate();


        this.headers.put("Content-Type", "text/plain");
        this.headers.put("CamelHttpMethod", HttpMethods.POST);
        this.headers.put("Connection", "Keep-Alive");
       
//this.headers.put("CamelHttpUrl","https://xx.xxx.xxx.xx:8443/NorthBound/server";);

        String endpoint =
"netty4-http:https://xx.xxx.xxx.xx:8443/NorthBound/server";;

        try {
            this.nettyHttpEndpoint = this.context.getEndpoint(endpoint,
org.apache.camel.component.netty4.http.NettyHttpEndpoint.class);
            this.nettyHttpEndpoint.configureProperties(this.headers);
            this.nettyHttpEndpoint.setConfiguration(nettyconfig);
           
this.nettyHttpEndpoint.setExchangePattern(ExchangePattern.InOnly);
            this.template.start();
            this.context.start();
        } catch (final Exception e) {
            NorthboundDataWriter.LOG.error("Exception while starting Camel
context ", e);
        }
    }

    public void sendDataNorthbound(final String message) {
        try {

            
this.template.requestBodyAndHeaders(this.nettyHttpEndpoint,message,
this.headers);
          
//this.template.asyncRequestBodyAndHeaders(this.nettyHttpEndpoint, message,
this.headers);

        } catch (final CamelExecutionException e) {
            NorthboundDataWriter.LOG.error("Error while sending data", e);
        }
    }

    public void stop() {
        try {
            this.template.stop();
            this.context.stop();
        } catch (final Exception e) {
            NorthboundDataWriter.LOG.error("Exception while stopping Camel
context ", e);
        }
    }

}





--
View this message in context: 
http://camel.465427.n5.nabble.com/Netty4-HTTP-component-for-HTTPS-Issues-tp5798629.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to