Hi

You are using restlet so it cannot reuse ports accross other
deployments in the same JVM. For that you need to use the servlet
component which uses the servlet engine of your app server.

That requires a bit more work to setup, eg in the web.xml etc.

For the api, then you can use swagger, see
http://camel.apache.org/swagger-java

There is some examples that does that (which also uses as servlet)
https://github.com/apache/camel/tree/master/examples/camel-example-swagger-xml



On Sun, Feb 21, 2016 at 4:49 PM, zappee <arnold.somo...@gmail.com> wrote:
> Hi Claus,
>
> Thank you for the links. Especially for the first one.
> I do not use Spring, instead of I use simple CDI and my camel route is not
> packaged into war so I do not have any web.xml file.
>
> I've just followed your links and I was able to create a bootstrap java
> class:
>
> @Singleton
> @Startup
> public class Bootstrap {
>
>     private static final Logger LOGGER =
> LoggerFactory.getLogger(Bootstrap.class.getName());
>
>     @Inject
>     private CamelContext context;
>
>     @PostConstruct
>     public void init() {
>         try {
>             LOGGER.info("bootstrapping apache camel");
>             context.addRoutes(new UserServiceRouteBuilder());
>             context.start();
>         } catch (Exception e) {
>             LOGGER.error("an error occurred during bootstrapping camel
> routes", e);
>         }
>     }
>
>     @PreDestroy
>     public void shutdown() {
>         try {
>             context.stop();
>             LOGGER.info("apache camel routes stopped");
>         } catch (Exception e) {
>             LOGGER.error("camel stop error", e);
>         }
>     }
> }
>
>
> I had to move my-camel-restapi.jar from the lib folder to the root of the
> ear file because I got a strange exception. Now the structure of my ear
> looks like this:
>
> *.EAR
>  |-lib/
>  |  |- dependencies, ex.: camel jars
>  |  |- my-common.jar
>  |
>  |- my-web-ui.war
>  |- my-stateless-ejb.jar
>  |- *my-camel-restapi.jar <- it contains my camel rest route*
>
>
> And my camel rote is improved a little bit:
>
> public class UserServiceRouteBuilder extends RouteBuilder {
>     private static final String APPLICATION_JSON_UTF_8 =
> "application/json;charset=UTF-8";
>
>     @Override
>     public void configure() throws Exception {
>         User user = new User();
>         user.set...
>
>         restConfiguration().component(*"restlet"*)
>         *.host("localhost").port(8081)*
>                 .bindingMode(RestBindingMode.json)
>                 .dataFormatProperty("prettyPrint", "true");
>
>         rest("/user")
>                 .description("user rest service")
>                 .produces(APPLICATION_JSON_UTF_8)
>                 .get("/hello")
>
> .outType(User.class).route().routeId("GET@/generate").transform().constant(user).endRest();
>     }
> }
>
> It works fine, if I make a GET call to http://localhost:8081/user/hello then
> I get a proper json answer. Beautiful :) I like Camel, it is a great java
> integration tool/framework. It makes Java stronger :)
>
> But I do not understand something. How it is possible to map the restapi to
> http port 8081? It means for me that somehow camel starts a small web
> container or whatever else on port 8081 inside my GlassFish server. What
> happened inside the EE container of the GlassFish?
>
> If I have more, separated camel group of routes packages in different,
> separated jars, bootstrapped them separately then I need to use different
> ports during the bootstrapping process to avoid the "port in use" error
> message. Am I correct? Or I can configure separated routes to use the same
> host and port (of course paths need to be different)? How many MB memory is
> consumed by my separated jar files with the small "web containers", listen
> on different ports?
>
> Can I bootstrap my routes - locate in different jars - by a common
> Bootstrap.java from example my-commons.jar? In that case theoretically I
> need only one "something" which is listening on ex. port 8081 and all my
> routes (rest api) will be available on the same port.
>
> Thx!
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/camel-rest-route-tp5777992p5778013.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to