Hi Also the bean method name issue has been fixed in trunk. So if possible please test it at your side by building from source or try SNAPSHOT when a new build is published to apache maven repos.
On Wed, Aug 5, 2009 at 1:55 PM, Claus Ibsen<[email protected]> wrote: > Hi > > Okay I am committing a fix in short time. > > You can grab it using 2 ways > - from the body using the camel type converter, to avoid ugly java type casts > - using java type cast to cast the message to HttpMessage > > // we have access to the HttpServletRequest here and we > can grab it if we need it > HttpServletRequest req = > exchange.getIn().getBody(HttpServletRequest.class); > assertNotNull(req); > > // we have access to the HttpServletResponse here and we > can grab it if we need it > HttpServletResponse res = > exchange.getIn().getBody(HttpServletResponse.class); > assertNotNull(res); > > // and they should also be on HttpMessage > HttpMessage msg = (HttpMessage) exchange.getIn(); > assertNotNull(msg.getRequest()); > assertNotNull(msg.getResponse()); > > And use the output stream to write to the servlet response > > // and we can use servlet response to write to output stream also > res.getOutputStream().print("Written by servlet response"); > > > On Wed, Aug 5, 2009 at 10:55 AM, Claus Ibsen<[email protected]> wrote: >> Hi >> >> Cool I have added a ticket to get it back >> https://issues.apache.org/activemq/browse/CAMEL-1879 >> >> >> On Wed, Aug 5, 2009 at 10:52 AM, jjb<[email protected]> wrote: >>> >>> Hi, Claus. >>> >>> I built a framework to receive status related messages from a topic as the >>> route is traversed. Consider the routes the define DerivedClass -> A -> B >>> -> C. As each segment in the route executes, it sends JAXB/XML messages to >>> a topic that are then forwarded back to the client via a callback. As the >>> DerivedClass receives these messages, it sends them back over the HTTP >>> socket (via the HttpServletResponse) to the invoking web client. This gives >>> the web client a realtime flow of XML status updates while the different >>> endpoints are traversed. Since I do not want DerivedClass to know about >>> Camel or JMS, there is a class which DerivedClass submits a request to >>> (manager instance below) that also listens on this topic for related status >>> messages. These I get via callback and write them to the web client >>> accordingly: >>> >>> >>> public interface Client >>> { >>> public void notify(String status); >>> } >>> >>> public DerivedClass implements Client >>> { >>> HttpServletResponse response; >>> >>> public void process(Exchange exchange) >>> { >>> HttpServletResponse response = ....; // need to know how to get >>> this >>> String request = "MY XML REQUEST"; // this is actually a JAXB >>> serialized object >>> >>> // submit XML request to class which listens on topic and calls >>> notify with stuff for us >>> manager.submit(request, this); >>> } >>> >>> // we get our stuff from the manager object which listens on a topic and >>> correlates status >>> // messages and calls this notify method >>> public notify(String status) >>> { >>> response.getWriter().println(status); >>> } >>> } >>> >>> I was hoping 2.0-M3 Camel would allow access to HttpServletRequest as before >>> 2.0-M3 so I can make my own synchronous writes to the HTTP client from >>> DerivedClass with no dependence on Camel. >>> >>> Regards >>> >>> response.getWriter().println(statusStr) >>> >>> Claus Ibsen-2 wrote: >>>> >>>> Hi >>>> >>>> Ah the response may be missing on the HttpMessage. >>>> >>>> What do you need it for? >>>> >>>> On Wed, Aug 5, 2009 at 9:51 AM, jjb<[email protected]> wrote: >>>>> >>>>> Hi, Claus. >>>>> >>>>> Thank you so much for looking into the issue. My last request has to do >>>>> with how to obtain a reference to the HttpServletResponse in the new (>= >>>>> 2.0-M3) Camel API. I can get the HttpServletRequest as you suggested >>>>> (using >>>>> HttpMessage), but how do I obtain a reference to the HttpServletResponse >>>>> from a method with is the "to" endpoint of a camel-jetty "from" route >>>>> that >>>>> takes an Exchange parameter as so: >>>>> >>>>> public void process(Exchange exchange) >>>>> { >>>>> HttpMessage in = (HttpMessag) exchange.getIn(); >>>>> HttpServletRequest = in.getRequest(); >>>>> >>>>> // how do I get to the HttpServletResponse which used to be accessed < >>>>> 2.0-M3 >>>>> // like this: HttpServletResponse response = >>>>> ((HttpExchange)exchange).getResponse(); >>>>> } >>>>> >>>>> Regards >>>>> >>>>> >>>>> Claus Ibsen-2 wrote: >>>>>> >>>>>> Hi >>>>>> >>>>>> Thanks for the sample. I can reproduce the issue. >>>>>> >>>>>> The issue is that your base class implements the >>>>>> javax.jms.MessageListener. >>>>>> I will dig into why Camel prefers to invoke this method over the >>>>>> method name specified. >>>>>> >>>>>> >>>>>> On Tue, Aug 4, 2009 at 8:02 PM, jjb<[email protected]> wrote: >>>>>>> >>>>>>> Hi. >>>>>>> >>>>>>> Attached is an example which recreates the bean issue. My goal is to >>>>>>> create >>>>>>> a framework which localizes JMS/ActiveMQ and Camel stuff to one >>>>>>> package. >>>>>>> Then none of our business logic depends on it (it just passes POJOs >>>>>>> around >>>>>>> that are created from XSD using JAXB). This is why I can't put the >>>>>>> @Handler >>>>>>> annotation in the DerivedClass. >>>>>>> http://www.nabble.com/file/p24813432/camel_bug.tgz camel_bug.tgz >>>>>>> >>>>>>> About the 2.0-M3 Camel interface for HttpServletResponse - how do I get >>>>>>> it >>>>>>> from the Exchange? >>>>>>> >>>>>>> Thanks! >>>>>>> >>>>>>> >>>>>>> Claus Ibsen-2 wrote: >>>>>>>> >>>>>>>> On Tue, Aug 4, 2009 at 9:26 AM, jjb<[email protected]> wrote: >>>>>>>>> >>>>>>>>> Hi. >>>>>>>>> >>>>>>>>> Thanks for the quick response. I switched to 2.0-M3 and still had >>>>>>>>> the >>>>>>>>> problem - the BaseClass.onMessage still gets called. Is there a >>>>>>>>> newer >>>>>>>>> release or something I can check out that might have this fix? Also, >>>>>>>>> when I >>>>>>>>> use 2.0-M3, how do I get the HttpServletResponse (your suggestion to >>>>>>>>> get >>>>>>>>> the >>>>>>>>> HttpServletRequest worked for me - thanks)? >>>>>>>>> >>>>>>>>> Regards >>>>>>>> >>>>>>>> Hi >>>>>>>> >>>>>>>> About the bean problem. Could you create a ticket for it and attach a >>>>>>>> small sample with the issue? >>>>>>>> >>>>>>>> You can use the @Handler annotation to mark the method that Camel >>>>>>>> should use and then avoid using the ?method=xxxx. >>>>>>>> But I am interested in fixing why method=xxx does not work for you. >>>>>>>> >>>>>>>> See more here >>>>>>>> http://camel.apache.org/bean-binding.html >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Claus Ibsen-2 wrote: >>>>>>>>>> >>>>>>>>>> Hi >>>>>>>>>> >>>>>>>>>> On Tue, Aug 4, 2009 at 7:52 AM, jjb<[email protected]> wrote: >>>>>>>>>>> >>>>>>>>>>> I have a hierarchy of objects which looks like this: >>>>>>>>>>> >>>>>>>>>>> public BaseClass implements javax.jms.MessageListener >>>>>>>>>>> { >>>>>>>>>>> public void onMessage(javax.jms.Message message) >>>>>>>>>>> { >>>>>>>>>>> // do something >>>>>>>>>>> } >>>>>>>>>>> } >>>>>>>>>>> >>>>>>>>>>> public DerivedClass extends BaseClass >>>>>>>>>>> { >>>>>>>>>>> public void process(String body) >>>>>>>>>>> { >>>>>>>>>>> // do something >>>>>>>>>>> } >>>>>>>>>>> } >>>>>>>>>>> >>>>>>>>>>> I then have the following XML in my camel-context.xml: >>>>>>>>>>> >>>>>>>>>>> <bean id="processor" class="DerivedClass"/> >>>>>>>>>>> >>>>>>>>>>> <route> >>>>>>>>>>> <from uri="activemq:request.queue"/> >>>>>>>>>>> <to uri="bean:processor?method=process"/> >>>>>>>>>>> </route> >>>>>>>>>>> >>>>>>>>>>> When I run this code, all messages from request.queue always go to >>>>>>>>>>> BaseClass.onMessage, even though I explicitly want them to go to >>>>>>>>>>> DerivedClass.process. Have I done something wrong or is this a bug >>>>>>>>>>> (I >>>>>>>>>>> read >>>>>>>>>>> through the bean binding and it said it would first use methods >>>>>>>>>>> that >>>>>>>>>>> were >>>>>>>>>>> explicitly specified in the bean's method parameter)? >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> We have fixed a bug in this relation in 2.0.x (cant remember the >>>>>>>>>> version, might be the 2.0m3). >>>>>>>>>> >>>>>>>>>> In older versions you can work around this by adding an @Body >>>>>>>>>> annotation to your base class >>>>>>>>>> public void process(@Body String body) >>>>>>>>>> And Camel should prefer to use this method. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> I also notice that the new 2.0-M3 version of camel-http no longer >>>>>>>>>>> contains >>>>>>>>>>> the class org.apache.camel.component.http.HttpExchange. Therefore, >>>>>>>>>>> this >>>>>>>>>>> code no longer compiles: >>>>>>>>>>> >>>>>>>>>>> public void process(Exchange exchange) >>>>>>>>>>> { >>>>>>>>>>> try >>>>>>>>>>> { >>>>>>>>>>> HttpServletResponse response = >>>>>>>>>>> ((HttpExchange)exchange).getResponse(); >>>>>>>>>>> HttpServletRequest request = >>>>>>>>>>> ((HttpExchange)exchange).getRequest(); >>>>>>>>>>> HttpSession session = null; >>>>>>>>>>> if (request != null) >>>>>>>>>>> session = request.getSession(true); >>>>>>>>>>> } >>>>>>>>>>> catch (Exception e) >>>>>>>>>>> { e.printStackTrace(); } >>>>>>>>>>> } >>>>>>>>>>> >>>>>>>>>>> Is there a new way to get the HttpServletResponse and such from the >>>>>>>>>>> Exchange >>>>>>>>>>> parameter? >>>>>>>>>> >>>>>>>>>> Its on the HttpMessage instead. >>>>>>>>>> >>>>>>>>>> HttpMessage in = (HttpMessag) exchange.getIn(); >>>>>>>>>> HttpServletRequest = in.getRequest(); >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Regards >>>>>>>>>>> -- >>>>>>>>>>> View this message in context: >>>>>>>>>>> http://www.nabble.com/bean-binding-with-inheritance---2.0-M3-camel-http-tp24802648p24802648.html >>>>>>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Claus Ibsen >>>>>>>>>> Apache Camel Committer >>>>>>>>>> >>>>>>>>>> Open Source Integration: http://fusesource.com >>>>>>>>>> Blog: http://davsclaus.blogspot.com/ >>>>>>>>>> Twitter: http://twitter.com/davsclaus >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> View this message in context: >>>>>>>>> http://www.nabble.com/bean-binding-with-inheritance---2.0-M3-camel-http-tp24802648p24803535.html >>>>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Claus Ibsen >>>>>>>> Apache Camel Committer >>>>>>>> >>>>>>>> Open Source Integration: http://fusesource.com >>>>>>>> Blog: http://davsclaus.blogspot.com/ >>>>>>>> Twitter: http://twitter.com/davsclaus >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> -- >>>>>>> View this message in context: >>>>>>> http://www.nabble.com/bean-binding-with-inheritance---2.0-M3-camel-http-tp24802648p24813432.html >>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Claus Ibsen >>>>>> Apache Camel Committer >>>>>> >>>>>> Open Source Integration: http://fusesource.com >>>>>> Blog: http://davsclaus.blogspot.com/ >>>>>> Twitter: http://twitter.com/davsclaus >>>>>> >>>>>> >>>>> >>>>> -- >>>>> View this message in context: >>>>> http://www.nabble.com/bean-binding-with-inheritance---2.0-M3-camel-http-tp24802648p24822320.html >>>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> Claus Ibsen >>>> Apache Camel Committer >>>> >>>> Open Source Integration: http://fusesource.com >>>> Blog: http://davsclaus.blogspot.com/ >>>> Twitter: http://twitter.com/davsclaus >>>> >>>> >>> >>> -- >>> View this message in context: >>> http://www.nabble.com/bean-binding-with-inheritance---2.0-M3-camel-http-tp24802648p24823165.html >>> Sent from the Camel - Users mailing list archive at Nabble.com. >>> >>> >> >> >> >> -- >> Claus Ibsen >> Apache Camel Committer >> >> Open Source Integration: http://fusesource.com >> Blog: http://davsclaus.blogspot.com/ >> Twitter: http://twitter.com/davsclaus >> > > > > -- > Claus Ibsen > Apache Camel Committer > > Open Source Integration: http://fusesource.com > Blog: http://davsclaus.blogspot.com/ > Twitter: http://twitter.com/davsclaus > -- Claus Ibsen Apache Camel Committer Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus
