Search code examples
httpsapache-camelmaven-jetty-plugin

How to define camel jetty routes for https request and pass the parameter to some api for authentication?


I want to send https consumer request using camel-jetty component and that address returns some response in JSON format, below I mention my DSL code.

from("jetty:https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__").to("stream:out"); 

I am getting this warning:  
[WARNING]   
java.net.SocketException: Permission denied  
at sun.nio.ch.Net.bind0 (Native Method)  
at sun.nio.ch.Net.bind (Net.java:433)
at sun.nio.ch.Net.bind (Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind 

But whenever I hit this HTTP URL in browser it will execute perfectly with authentication.
If anyone knows what to do to perform this action in apache camel please help me it will be very cheerful for me and others.

And how could I know which method camel using for sending a request like POST or GET.
Thank You


Solution

  • Could you try this instead? I'll comment each line to help understand your problem.

    // endpoint to start your route. could be a http endpoint you expose via jetty, jms, vm, seda or any other option. Here I'm using the simplest one.
    from("direct:start")
        // logs on
        .to("log:DEBUG?showBody=true&showHeaders=true")
        // consume the endpoint
        .to("https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__"")
        // log the body to the console so you could process the response later knowing what to do (the token you are mentioning should be in here.
        .to("log:DEBUG?showBody=true&showHeaders=true")
        .to("stream:out") //or whatever you want to
    

    Don't forget the camel-http dependency for this example to work:

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http</artifactId>
    </dependency>
    

    Cheers!