restlet usage

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

restlet usage

Nolan Johnson
I'm possibly interested in working with camel-restlet (2.0, since it doesn't exist before then).  First off, is there any documentation besides that on the restlet component page?

I'm having two problems.  The first is conceptual - the page that I linked above really doesn't describe how camel integrates with Restlet, it just shows a trivial "Hello, world!" level example.  I can probably figure it out if I can get things working in general, but more documentation there would be helpful.

Secondly, I can't get a (simpler) "Hello world" sample to work.  At this point, I'm not interested in the authentication part.  The following is the class that I'm using:

public class CamelRest extends RouteBuilder
{

        /**
         * @param args
         * @throws Exception
         */
        public static void main(String[] args) throws Exception
        {
                CamelContext context = new DefaultCamelContext();
                context.addRoutes(new CamelRest());
                context.start();
                System.out.println("Server is ready");
                while (true)
                {
                        Thread.sleep(10000);
                }
        }

        @Override
        public void configure() throws Exception
        {
                from("restlet:http://localhost:8080/users").process(new Processor()
                {
                        public void process(Exchange exchange) throws Exception
                        {
                                exchange.getOut().setBody("Hello World!");
                        }
                });
        }

}

(with appropriate imports).  When I hit http://localhost:8080/users, the following is the output that I see on my console:

Jan 20, 2009 2:28:49 PM com.noelios.restlet.StatusFilter getStatus
SEVERE: Unhandled exception or error intercepted
java.lang.NoSuchMethodError: org.restlet.data.Form.getValuesMap()Ljava/util/Map;
        at org.apache.camel.component.restlet.DefaultRestletBinding.populateExchangeFromRestletRequest(DefaultRestletBinding.java:75)
        at org.apache.camel.component.restlet.RestletConsumer$1.handle(RestletConsumer.java:53)
        at org.apache.camel.component.restlet.MethodBasedRouter.handle(MethodBasedRouter.java:55)
        at org.restlet.Filter.doHandle(Filter.java:114)
        at org.restlet.Filter.handle(Filter.java:144)
        at org.restlet.Router.handle(Router.java:454)
        at org.restlet.Filter.doHandle(Filter.java:114)
        at org.restlet.Filter.handle(Filter.java:144)
        at org.restlet.Router.handle(Router.java:454)
        at org.restlet.Filter.doHandle(Filter.java:114)
        at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:98)
        at org.restlet.Filter.handle(Filter.java:144)
        at org.restlet.Filter.doHandle(Filter.java:114)
        at org.restlet.Filter.handle(Filter.java:144)
        at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:129)
        at org.restlet.Component.handle(Component.java:240)
        at org.restlet.Server.handle(Server.java:291)
        at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:109)
        at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:103)
        at com.noelios.restlet.ext.jetty.JettyServerHelper$WrappedServer.handle(JettyServerHelper.java:242)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
        at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
        at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)

Being new to Camel, I really don't know where to start.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: restlet usage

P.Budzik
nojonojo wrote
I'm possibly interested in working with camel-restlet (2.0, since it doesn't exist before then).  First off, is there any documentation besides that on the restlet component page?

I'm having two problems.  The first is conceptual - the page that I linked above really doesn't describe how camel integrates with Restlet, it just shows a trivial "Hello, world!" level example.  I can probably figure it out if I can get things working in general, but more documentation there would be helpful.
This component is really fresh stuff delivered recently however I'm glad to see folks being interested in it. You're right, the documentation is sparse. I was going to extend that, but as usual there was no time :) I assure you anyway it works in a real project not only for "hello world". You can count at least on me and William for working out your problem.

Secondly, I can't get a (simpler) "Hello world" sample to work.  At this point, I'm not interested in the authentication part.  The following is the class that I'm using:
....
Being new to Camel, I really don't know where to start.
Seems that you have some dependency problem. Look at the excerpt from my libs:

  <classpathentry kind="var" path="M2_REPO/com/noelios/restlet/com.noelios.restlet/1.1.1/com.noelios.restlet-1.1.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/noelios/restlet/com.noelios.restlet.ext.simple/1.1.1/com.noelios.restlet.ext.simple-1.1.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/restlet/org.restlet/1.1.1/org.restlet-1.1.1.jar"/>

Do your versions match with that? It looks like the binding class is calling Form.getValuesMap() and the one on the classpath has a different signature.
Reply | Threaded
Open this post in threaded view
|

Re: restlet usage

Nolan Johnson

Thanks much - not sure why I didn't notice that.  I had been using restlet 1.0.11 instead of 1.1.1.

Understood about the documentation.  It's better to have something working with sparse documentation than to have it well documented and not working!

P.Budzik wrote
nojonojo wrote
I'm possibly interested in working with camel-restlet (2.0, since it doesn't exist before then).  First off, is there any documentation besides that on the restlet component page?

I'm having two problems.  The first is conceptual - the page that I linked above really doesn't describe how camel integrates with Restlet, it just shows a trivial "Hello, world!" level example.  I can probably figure it out if I can get things working in general, but more documentation there would be helpful.
This component is really fresh stuff delivered recently however I'm glad to see folks being interested in it. You're right, the documentation is sparse. I was going to extend that, but as usual there was no time :) I assure you anyway it works in a real project not only for "hello world". You can count at least on me and William for working out your problem.

Secondly, I can't get a (simpler) "Hello world" sample to work.  At this point, I'm not interested in the authentication part.  The following is the class that I'm using:
....
Being new to Camel, I really don't know where to start.
Seems that you have some dependency problem. Look at the excerpt from my libs:

  <classpathentry kind="var" path="M2_REPO/com/noelios/restlet/com.noelios.restlet/1.1.1/com.noelios.restlet-1.1.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/noelios/restlet/com.noelios.restlet.ext.simple/1.1.1/com.noelios.restlet.ext.simple-1.1.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/restlet/org.restlet/1.1.1/org.restlet-1.1.1.jar"/>

Do your versions match with that? It looks like the binding class is calling Form.getValuesMap() and the one on the classpath has a different signature.
Reply | Threaded
Open this post in threaded view
|

Re: restlet usage

Nolan Johnson
In reply to this post by P.Budzik

Okay, next question on usage of the restlet component.

I'm trying to POST a new resource via a rest call.  My route looks something like:

from("restlet:http://localhost:8080/users/{username}?restletMethod=POST").process(new SetUserProcessor());

Where SetUserProcessor might do some processing.

I'm POSTing a request with a url like http://localhost:8080/users/homer, and the body is a JSON-encoded String.  I'll worry about processing the JSON later - right now, that's just some payload representing a user.  The process method in the processor is being invoked appropriately, and the username header is populated properly in the input.  However, the body of the Message is empty by the time it makes it to the processor.  The data that I have in the body is nowhere to be seen, as far as I can tell.

Name-value pairs in the POST body do appear in the headers, it's just that when there's a block of data (as you'd do in a POST or a PUT using REST), it doesn't come through.
Reply | Threaded
Open this post in threaded view
|

Re: restlet usage / process

Nolan Johnson

I see that http://issues.apache.org/activemq/browse/CAMEL-1284 was created and fixed as a response to this issue.  I have a process question - when will the 2.0-SNAPSHOT downloads contain this fix?  (Preferable to compiling it myself, though that wouldn't be that big of a deal).

Thanks.

Nolan

nojonojo wrote
Okay, next question on usage of the restlet component.

I'm trying to POST a new resource via a rest call.  My route looks something like:

from("restlet:http://localhost:8080/users/{username}?restletMethod=POST").process(new SetUserProcessor());

Where SetUserProcessor might do some processing.

I'm POSTing a request with a url like http://localhost:8080/users/homer, and the body is a JSON-encoded String.  I'll worry about processing the JSON later - right now, that's just some payload representing a user.  The process method in the processor is being invoked appropriately, and the username header is populated properly in the input.  However, the body of the Message is empty by the time it makes it to the processor.  The data that I have in the body is nowhere to be seen, as far as I can tell.

Name-value pairs in the POST body do appear in the headers, it's just that when there's a block of data (as you'd do in a POST or a PUT using REST), it doesn't come through.