Hi Thanks for the feedback. Do you mind creating a ticket in the Camel tracker http://camel.apache.org/support
You are welcome to work on patches for the issues you have discovered. Then we can get it fixed faster. Unit tests is much welcome to go along. Also consider creating a new ticket for the bridgeEndpoint option that we have in other components. This allows you to use the restlet component in a proxy mode which is what you want to do. As well as the throwExceptionOnFailure option. See for example http component which has these option http://camel.apache.org/http On Wed, Aug 10, 2011 at 2:49 PM, Cedric de Launois <[email protected]> wrote: > Hi all, > > I discovered what it seems to be multiple bugs while trying to implement a > REST webservice that facades an existing one. > > The goal is to define on the ESB a REST webservice that simply forwards > incoming requests to the real REST webservice (that exists outside the ESB). > The facade must be transparent, i.e. it must reply with the same HTTP error > codes and the same HTTP responses as those returned by the real service. > > Here is the (blueprint) route that I got nearly working (after several > hours...) : > > <route id="restproxy"> > > <from uri="restlet:http://localhost:9080/oe/ws/offre/{id}"/> > > > <doTry> > <to uri="restlet:http://bla.dot.com:8080/oe/ws/offre/{id}"/> > <doCatch> > <exception>org.apache.camel.CamelException</exception> > <setOutHeader headerName="CamelHttpResponseCode"> > <simple>${exception.statusCode}</simple> > </setOutHeader> > <setBody> > <simple>${exception.responseBody}</simple> > </setBody> > <log message="RB=${exception.responseBody} > SC=${exception.statusCode} URI=${exception.uri}"/> > </doCatch> > </doTry> > </route> > > The problems I got/get are the following : > > 1) The real REST service may return a HTTP 404 with some content in the > response body. However, this body get lost by the exception handling. > In the route, this results in ${exception.responseBody} being something > like "org.restlet.data.Response@17bf0a7". > After investigation, the problem is located in the class RestletProducer > (in camel-restlet 2.6.0) at line 126. The body is taken by the statement > String copy = response.toString(); > > This is obviously wrong. It should be instead something like : > String copy = null; > if (response.getEntity() != null) { > // get content text > copy = response.getEntity().getText(); > } > > Additionnally, I would remove the statement LOG.warn(headers) that stand > the line just after (or at least set the LOG level to DEBUG). > > > 2) Another problem is that the value of ${exception.uri} appears to be the > uri of the facade REST service (i.e. > restlet:http://localhost:9080/oe/ws/offre/{id}) while it should be instead > the uri of the endpoint that threw the exception (i.e. > restlet:http://bla.dot.com:8080/oe/ws/offre/{id}). This problem can be > corrected in the same class RestletProducer, at line 123, by replacing > String uri = exchange.getFromEndpoint().getEndpointUri(); > by > String uri = response.getRequest().getResourceRef() > > > 3) I would like to catch only > org.apache.camel.component.restlet.RestletOperationException exception, i.e. > write : > > <exception>org.apache.camel.component.restlet.RestletOperationException</exception> > > However, if I do this, I get a NullPointerException : > java.lang.NullPointerException > at > org.apache.camel.processor.CatchProcessor.catches(CatchProcessor.java:71)[68:org.apache.camel.camel-core:2.6.0] > at > org.apache.camel.processor.TryProcessor$DoCatchProcessor.process(TryProcessor.java:226)[68:org.apache.camel.camel-core:2.6.0] > at > org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)[68:org.apache.camel.camel-core:2.6.0] > ... > > After investigation, the problem lies in CatchDefinition.java (in > camel-core 2.6.0) at line 260 where the statement > ObjectHelper.loadClass(name, getClass().getClassLoader()) on the string > "org.apache.camel.component.restlet.RestletOperationException" returns null, > unless dynamic import is turned on on the camel-core bundle. > > Regards, > Cedric > > > > -- > View this message in context: > http://servicemix.396122.n5.nabble.com/Bugs-found-and-feedback-about-facading-a-REST-web-service-tp4685700p4685700.html > Sent from the ServiceMix - User mailing list archive at Nabble.com. > -- Claus Ibsen ----------------- FuseSource Email: [email protected] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
