Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel http to http routing (Is it possible?)

I am starting now with Camel. I have seen the http4 component for http clients and the jetty component for http servers.

I have seen several examples that use one or the other. I would like to know if it is possible to combine them together.

Example

from("jetty:http://0.0.0.0:8080/myapp/myservice")
.to("http4://www.google.com");

This would make camel a simple http based router/proxy. Web browsers would hit the camel URL and instead get google. (Google is just an example, I have a real POST based service that I want to use)

Is this route possible? Should I research Camel or do I need a different software framework for this? In the future I would also need to add transformations/filters in between.

I have tried it and got a nullpointer exception

[qtp757856402-14] SendProcessor       DEBUG >>>> Endpoint[http4://www.google.com] Exchange[Message: [Body is instance of java.io.InputStream]]
[qtp757856402-14] DefaultErrorHandler DEBUG Failed delivery for exchangeId: ID-IT12-53265-1302683969823-0-1. On delivery attempt: 0 caught: java.lang.NullPointerException
[qtp757856402-14] DefaultErrorHandler ERROR Failed delivery for exchangeId: ID-IT12-53265-1302683969823-0-1. Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
java.lang.NullPointerException
like image 679
kazanaki Avatar asked Apr 13 '11 08:04

kazanaki


People also ask

How do I create a route in Apache Camel?

There is a new attribute startupOrder which is an Integer that states the order. Camel then sorts the routes before starting time. The routes with the lowest startupOrder are started first and the ones with the highest are started last. All startupOrder defined must be unique among all routes in your CamelContext.

How does Apache Camel route work?

A Camel route is where the integration flow is defined. For example to integrate two systems then a Camel route can be coded to specify how these systems are integrated. An example could be to take files from a FTP server and send to a ActiveMQ messaging system.

What is dynamic routing in Camel?

The Dynamic Router from the EIP patterns allows you to route messages while avoiding the dependency of the router on all possible destinations while maintaining its efficiency.


1 Answers

You need to bridge the endpoint.

from("jetty:http://0.0.0.0:8080/myapp/myservice")
.to("http4://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false");
like image 170
Claus Ibsen Avatar answered Oct 11 '22 04:10

Claus Ibsen