Search code examples
apache-camelosgiapache-karafjbossfuse

Camel REST DSL - Address already in use: bind Exception


I am using REST DSL Component in my project with Jboss Fuse Karaf 6.3 instance. I got two problems

  1. With the restConfiguration, i have to always specify a port number. tried with component as "servlet", still have to provide a port number. Is there way to avoid this? Please note I am not creating a web project here.

  2. One Bundle is exposing rest endpoints with "restlet" component at port 8080 which works fine. Another Bundle trying to expose couple of endpoints with the same restConfiguration. Now this bundle is not getting started because of the below exception

    Caused by: java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method)[:1.8.0_111]

I am using Spring DSL like below in both bundles one with binding off and one with json.

Bundle1

    <restConfiguration bindingMode="json" component="restlet" port="8080"/>
    <rest path="HelloService/rs">

Bundle2

    <restConfiguration bindingMode="off" component="restlet" port="8080"/>
    <rest path="AnotherService/rs">

Any solutions or suggestions for this please?


Solution

  • You cannot do this with multiple bundles in karaf/jboss fuse, when using restlet, jetty, etc. You can only re-use the same port when you use servlet as then you are using the shared http service/servlet that comes out of the box with JBoss Fuse.

    So you should do

     <restConfiguration bindingMode="off" component="servlet"/>
    

    The port number when using servlet is only for documentation purpose if you use swagger api-docs with camel-swagger-java.