1 2 Previous Next 20 Replies Latest reply on Feb 16, 2011 5:11 AM by praga

    Problem in getting browser values through camel

    praga

      Hi,

       

      My requirement is that i need to get browser values through a http invoke and those browser values should be sent to a activemq queue. I tried using camel http. but could not excute the project successfully

       

      http://localhost:8080/?name=praga. If I run this in the IE browser the value name=praga should be received by camel endpoint and published in activemq queue.

       

      I tried refering fuse source docs.. but could not understand what is

       

      from("direct:start")        

      .to("http://oldhost");

       

      http://fusesource.com/docs/router/2.2/component_ref/_IDU_HTTP.html

       

      can somebody help me with this requirement please !!!

        • 1. Re: Problem in getting browser values through camel
          davsclaus

          You can use the Jetty component to setup a HTTP server in Camel.

           

          And then route that to the AMQ queue

           

          from("jetty:0.0.0.0:9080/myserver/mypath")
             .to("activemq:queue:foo")
          

           

          http://camel.apache.org/jetty

          • 2. Re: Problem in getting browser values through camel
            praga

            Hi,

             

            Thanks for your reply... what does myserver/mypath ?? refers to?

            if you have any examples on this regard can you kindly share, it would really be helpful and kind of you.

             

            Thanks in advance.

            • 3. Re: Problem in getting browser values through camel
              davsclaus

              Thats just whatever you wanna call it. In you case you may want it as:

              from("jetty:0.0.0.0:80").to("activemq:queue:foo);
              

               

              So there is no context path at all.

               

              That means a client can hit the url: http:localhost and access the jetty server.

              • 4. Re: Problem in getting browser values through camel
                praga

                Hi,

                 

                I get following error. Can somebody help

                 

                HTTP ERROR: 404

                Problem accessing /. Reason:

                 

                    NOT_FOUND

                -


                Powered by Jetty://

                 

                PFA of my project zip file. Kindly let me know where iam going wrong. Iam just trying to get browser values and print in the method "MyBookService". If this part is working fine I can easily write it into queue.

                • 5. Re: Problem in getting browser values through camel
                  davsclaus

                  You can try with a context path, like foo

                  from("jetty:0.0.0.0:80/foo")...
                  

                   

                  Then hit the url from the webbrowser: http://localhost/foo?something=someValue

                  • 6. Re: Problem in getting browser values through camel
                    praga

                    Hi,

                     

                    When I start the bundle , the routebuilder starts automatically and the "from" gets executed even before i invoke the browser. What should be done in such a situation?

                    starting of  the bundle automatically invoke the flow and gives no time to invoke the browser and throws error

                    • 7. Re: Problem in getting browser values through camel
                      davsclaus

                      What do you mean? Which error do you see?

                       

                      When the bundle start it start the Camel route (eg the from). In the from you use Jetty which is a HTTP Server.

                       

                      Just like any other HTTP server on the internet, eg http://www.google.com. So clients can "talk to it" using HTTP from a web browser by its url.

                       

                      Edited by: davsclaus on Feb 10, 2011 10:33 AM

                      • 8. Re: Problem in getting browser values through camel
                        praga

                        Hi,

                         

                        Thanks . Iam able to print back to the browser. Actually jetty component feature has not be installed properly in the fuse server. i installed the feature already. but when i listed features:list camel-jetty showed uninstalled. now i installed and it is working fine now. thanks a lot

                        • 9. Re: Problem in getting browser values through camel
                          praga

                          Hi,

                           

                          One more clarification pleaseeeeeeeee.  now what i have done is give input value in browser and the value is now stored in queue. that is from http to queue.

                           

                          Now i need to get the values back from the queue and post it in the browser.

                           

                          that is from queue endpoint to jetty:http endpoint. is that possible? if yes how?

                           

                          from("jms:queue:HTTPQueue")

                          .process(new MyBookService())

                          .to("jetty:http://localhost:8080/HHTPtoJMSInFuse");

                           

                          is this correct? when we fetch data from queue it comes as an object right? how do decode the value alone?

                          • 10. Re: Problem in getting browser values through camel
                            davsclaus

                            No thats not doable.

                             

                            HTTP is request/response, so when a client hit the url from a webbrowser, that webbrowser sends a request and waits for the response.

                             

                            So when you receive the request from jetty in the Camel route, you must process the request, and set a message which is used as reply. Camel will send back the reply to the web browser, with whatever the message contains at the end of the route.

                             

                            So during that routing you need to grab that message from the queue and put it into the camel message.

                             

                            For that you can use the Content Enricher EIP pattern. Or the Polling Consumer EIP.

                            http://camel.apache.org/content-enricher.html

                            http://camel.apache.org/polling-consumer.html

                             

                            When you grab the message from the queue, you have to consider what to do if there is no message. And also do you need to use message selector or some sort to select the desired message from the queue in case there are more messages.

                             

                            Those EIP patterns support a timeout, so you can wait a bit in case the message is late. You can also use noWait to just check if there is a message asap, and not wait if there is not.

                            • 11. Re: Problem in getting browser values through camel
                              praga

                              Hi,

                               

                              iam trying with polling consumer. But where is the context declared? Is it a object of camelcontext? how should it be declared? I get a error saying context cannot be resolved.

                               

                              Endpoint endpoint = context.getEndpoint("activemq:my.queue");

                              • 12. Re: Problem in getting browser values through camel
                                davsclaus

                                context is the CamelContext which is essential Camel.

                                 

                                If you use a Processor then you can access it from the exchange parameter

                                • 13. Re: Problem in getting browser values through camel
                                  davsclaus

                                  If you want to get the hands on how to developer with Camel and ActiveMQ, then you can consider the virtual trainings

                                  http://fusesource.com/enterprise-support/virtual-training/

                                  • 14. Re: Problem in getting browser values through camel
                                    praga

                                    Hi,

                                     

                                    Thanks a lot for that reply. I tried using polling consumer

                                     

                                    CamelContext context = new DefaultCamelContext();

                                    Endpoint endpoint = context.getEndpoint("jms:queue:HTTPQueue");

                                             PollingConsumer consumer = endpoint.createPollingConsumer();

                                             exchange = consumer.receive();

                                     

                                    My router has :

                                     

                                    from("jetty:http://localhost:8080/HHTPtoJMSInFuse?name=praga")

                                              .inOnly("jms:queue:HTTPQueue")

                                              .process(new MyBookService())

                                              ;

                                     

                                    When i try to run the bundle in browser i get the following error

                                     

                                    org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jms://queue:HTTPQueue due to: No component found with scheme: jms     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:398)

                                         at com.nokia.fuse.http.MyBookService.process(MyBookService.java:33)

                                         at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)

                                         at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)

                                         at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)

                                         at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)

                                         at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:68)

                                         at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)

                                    1 2 Previous Next