camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen" <claus.ib...@gmail.com>
Subject Re: How do i call an HTTP Provider end-pont from the process method?
Date Sun, 11 Jan 2009 08:09:09 GMT
On Sat, Jan 10, 2009 at 8:51 PM, Liav Ezer <liav.ezer@gmail.com> wrote:
>
> Hi Claus,
>
> I changed the notation as needed to:
>
> producer.sendBody("jbi:endpoint:http://localhost:8080/LiavHello/services/LiavHelloImpl",
> "Netania");
>
>  SMX console now output some wierd error - googling it comes up with some
> xml parsing error:
>
> [Fatal Error] :1:1: Content is not allowed in prolog.DEBUG -
> DeliveryChannelImpl            - Exception processing:
> ID:10.236.11.194-11ec1f3a450-2:291 in DeliveryChannel{servicemix-camel}
> ERROR - DeadLetterChannel              - Failed delivery for exchangeId:
> ID-LIAVE02/4519-1231614935663/0-50. On delivery attempt: 0 caught:
> org.apache
> org.apache.servicemix.camel.JbiException:
> javax.jbi.messaging.MessagingException: Could not find route for exchange:
> InOnly[
>  id: ID:10.236.11.194-11ec1f3a450-2:291
>  status: Active
>  role: provider
Yeah when you send data to SMX you must remember that its expecting
the payload to be according to the JBI spec. in XML format. So you
should send the data as XML.

"Content is not allowed in prolog" is a bit cryptical XML parser error
stating that it could not find the <?xml ... ?> declaration in top of
the content it was parsing.

So you should send the payload as XML.

BTW: Which version of SMX and Camel are you using? I think the missing
method from X mails back could be because we added it in Camel 1.4.0
(I think).



>
> Claus Ibsen-2 wrote:
>>
>>
>>
>> This is the SMX Provider xbean:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <beans xmlns:http="http://servicemix.apache.org/http/1.0"
>>        xmlns:wsn="http://com.amdocs.oxp/esb"
>>        xmlns="http://www.springframework.org/schema/beans"
>>        xmlns:xsi="http://http://www.w3.org/2001/XMLSchema-instance"
>>        xsi:schemaLocation="http://servicemix.apache.org/http/1.0
>> http://servicemix.apache.org/schema/servicemix-http-3.3.1.3-fuse.xsd
>>        http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
>>
>>                 <http:endpoint service="wsn:LiavHelloImplService"
>>                  endpoint="wsn:LiavHelloImpl"
>>                  role="provider"
>>
>> locationURI="http://localhost:8080/LiavHello/services/LiavHelloImpl"
>>                  wsdlResource="c:/HTTPReceiverServices/LiavHelloImpl.wsdl"
>>                  defaultMep="http://www.w3.org/2004/08/wsdl/in-out"
>>                  soap="true" />
>> </beans>
>> Any clue?
>> On Sat, Jan 10, 2009 at 4:17 PM, Liav Ezer <liav.ezer@gmail.com> wrote:
>>>
>>> Hi Claus,
>>>
>>> Well i'll stick with the Http SMX provider end-point. I guess it's should
>>> integrate with camel routing with no problem.
>>>
>>> Ok what i did is the advise you gave me a few answers ago:
>>>
>>> ProducerTemplate producer =
>>> exchange.getContext().createProducerTemplate();
>>> Object response =
>>> producer.sendBody("http://localhost:8080/LiavHello/services/LiavHelloImpl",
>>> "Daviv");
>> See below
>>
>>
>>>
>>> And got this exception (SMX console after deply):
>>>
>>> : No endpoint could be found for:
>>> http://localhost:8080/LiavHello/services/LiavHelloImpl
>>> org.apache.camel.NoSuchEndpointException: No endpoint could be found for:
>>> http://localhost:8080/LiavHello/services/LiavHelloImpl
>>>
>>> LiavHelloImpl is the wsdlsoap:address location of the wsdl file
>>> representing
>>> the LiavHelloImp web project (under a running tomcat 6.0).
>>>
>>> Can you advise? It seems that the routing trying to be accomplished but
>>> something "configi" is messed up.
>>>
>>> Here is my provider xbean:
>>>
>>> <http:endpoint service="wsn:LiavHelloImplService"
>>>                 endpoint="wsn:LiavHelloImpl"
>>>                 role="provider"
>>>
>>> locationURI="http://localhost:8080/LiavHello/services/LiavHelloImpl"
>>>                 wsdlResource="c:/HTTPReceiverServices/LiavHelloImpl.wsdl"
>>>                 defaultMep="http://www.w3.org/2004/08/wsdl/in-out"
>>>                 soap="true" />
>> When you want from Camel to call service on SMX then you must use the
>> camel-jbi component that delegates to the SU in SMX.
>> So you need to add the jbi prefix in front.
>> See: http://activemq.apache.org/camel/jbi.html
>>
>> It should be something like this. By by all means I am not SMX expert
>> (yet):
>> producer.sendBody("jbi:service:wsn:LiavHelloImplService", "Daviv");
>>
>> The jbi component have different notation so please check it out.
>>
>> If you manage to get it working, then please write back how to, so we
>> can improve the documentation and help others in the future.
>>
>>
>>
>>>
>>> Thanks!
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>>
>>>> On Sat, Jan 10, 2009 at 3:02 PM, Liav Ezer <liav.ezer@gmail.com> wrote:
>>>>>
>>>>> Hi Claus,
>>>>>
>>>>> I did follow this camel example & set up a timer 'from' end-point
which
>>>>> my
>>>>> processor 'catched'.
>>>>>
>>>>> My will is to query this 'catched' data by sending it to a different
>>>>> end-point such as a service provider.
>>>>>
>>>>> Therefore, i deployed two SU's in my servicemix: One for the camel
>>>>> routing
>>>>> (timer example) & two is for
>>>>>
>>>>> the HTTP servicemix provider which i want to invoke in the proceesor.
>>>>>
>>>>> My question seems simple as long as an API exists for it:
>>>>>
>>>>> When my Processor class is instansiated than the process() method is
>>>>> invoked:
>>>>>
>>>>> public void process(Exchange exchange) throws Exception {
>>>>>
>>>>> The exchange.getIn() consist my 'from' end-point data (=the timer).
>>>>>
>>>>> I need the API to fetch the Http servicemix provider end-point &
to
>>>>> send
>>>>> hime a request with this data.
>>>> If you want to send FROM Camel to SMX then you need to use the
>>>> camel-jbi component. That is you get endpoints FROM Camel starting
>>>> with the "jbi:" prefix. See camel-jbi component.
>>>>
>>>>
>>>>
>>>>>
>>>>> One extra small question: Do i need to replace my provider SU with a
>>>>> camel
>>>>> http producer SU?
>>>> If you are using SMX 3.x then you dont as SMX has one SU for Camel.
>>>> However if you need to use any of the other camel components from SMX
>>>> you need to have them in the classpath as well, such as
>>>> camel-http.jar.
>>>>
>>>>
>>>> (In SMX 4.x its all OSGi land and you need to install features into
>>>> SMX.)
>>>>
>>>> A bit confused now. Which http provider do you want to use?
>>>> - SMX Http provider
>>>> - Camel http provider
>>>>
>>>>
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Claus Ibsen-2 wrote:
>>>>>>
>>>>>> Hi
>>>>>>
>>>>>> Yeah its a bit mixed up since Camel and ServiceMix have classes with
>>>>>> common name: Endpoint, Exchange etc.
>>>>>>
>>>>>> All the code I have shown assumes pure Camel code.
>>>>>>
>>>>>> I advice to check the ServceMix docu about using Camel in ServiceMix.
>>>>>> And get a basic example running. Such as this example
>>>>>> http://servicemix.apache.org/camel-example.html
>>>>>>
>>>>>> You could use that as a starting point to get Camel invoking your
HTTP
>>>>>> server. Just let the timer start it.
>>>>>> Then later your can connect using SMX instead of the camel timer.
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Sat, Jan 10, 2009 at 12:53 PM, Liav Ezer <liav.ezer@gmail.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Claus again,
>>>>>>>
>>>>>>> I addition to what i asked in my previouse response here is a
>>>>>>> question
>>>>>>> regarding the producer snippet which you gave in your last answer:
>>>>>>>
>>>>>>> I indeed wrote the following in my process() method:
>>>>>>>
>>>>>>> ProducerTemplate producer =
>>>>>>>
>>>>>>> exchange.getCamelContext().createProducerTemplate();
>>>>>>>                            Object response =
>>>>>>>
>>>>>>> producer.sendBody("http://myserver.com/myapp?foo=bar", "Liav
Camel
>>>>>>> POC");
>>>>>>>
>>>>>>> but i don't have the camel context at hand (saying "The method
>>>>>>> getCamelContext() is undefined for the type Exchange").
>>>>>>>  & also do i need to deploy a camel http producer su instead
of an
>>>>>>> http
>>>>>>> service mix provider?
>>>>>>>
>>>>>>> Claus Ibsen-2 wrote:
>>>>>>>>
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> When you are working with ServiceMix you must use the JBI
component
>>>>>>>> in
>>>>>>>> Camel
>>>>>>>> http://activemq.apache.org/camel/jbi.html
>>>>>>>>
>>>>>>>> So your endpoints should starting with "jbi:XXXX"
>>>>>>>>
>>>>>>>> And ServiceMix has some Camel docu here:
>>>>>>>> http://servicemix.apache.org/servicemix-camel.html
>>>>>>>>
>>>>>>>> Could you take a look at this docu a bit. There might be
some help
>>>>>>>> there.
>>>>>>>>
>>>>>>>> Try to get something more easier working with SMX and Camel
and then
>>>>>>>> later do the stuff you want with the dynamic add a camel
context.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Sat, Jan 10, 2009 at 12:39 PM, Liav Ezer <liav.ezer@gmail.com>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Claus,
>>>>>>>>>
>>>>>>>>> I read your tutorial & learnt from it. Thanks. I
adopted the cxf
>>>>>>>>> framework
>>>>>>>>> for now.
>>>>>>>>>
>>>>>>>>> Regarding my project (as stated above in snippets):
>>>>>>>>>
>>>>>>>>> I planted the following camel routing logic at my processor
class:
>>>>>>>>>
>>>>>>>>> process method - with camel:
>>>>>>>>>
>>>>>>>>> public void process(Exchange exchange) throws Exception
{
>>>>>>>>>
>>>>>>>>>  CamelContext camel = new DefaultCamelContext();
>>>>>>>>>  camel.start();
>>>>>>>>>
>>>>>>>>>  Component component = (Component)
>>>>>>>>> camel.getComponent("http-provider-su");
>>>>>>>>>
>>>>>>>>>  Endpoint endpoint = (Endpoint) ((org.apache.camel.Component)
>>>>>>>>> component).createEndpoint("provider:com.amdocs.oxp.esb");
>>>>>>>>>
>>>>>>>>>  exchange.getIn().setBody("Liav testing here!");
>>>>>>>>>
>>>>>>>>>  Producer producer = ((org.apache.camel.Endpoint)
>>>>>>>>> endpoint).createProducer();
>>>>>>>>>
>>>>>>>>>  producer.start();
>>>>>>>>>  producer.process(exchange);
>>>>>>>>>  producer.stop();
>>>>>>>>>
>>>>>>>>>  //System.out.println(exchange.getIn().toString() + "process
>>>>>>>>> activated
>>>>>>>>> by
>>>>>>>>> SU");
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> And got the following exception while SA's jar was deployed:
>>>>>>>>>
>>>>>>>>> ERROR - DeadLetterChannel              - Failed delivery
for
>>>>>>>>> exchangeId:
>>>>>>>>> ID-LIAVE02/1885-1231586726193/0-0. On delivery attemp
>>>>>>>>> java.lang.NullPointerException
>>>>>>>>>        at
>>>>>>>>> org.apache.servicemix.tutorial.camel.MyProcessor.process(MyProcessor.java:33)
>>>>>>>>> at
>>>>>>>>> org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:92)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:66)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorT
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:75)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:146)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:90)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.processor.Pipeline.process(Pipeline.java:85)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:39)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:41)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:66)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:91)
>>>>>>>>>        at
>>>>>>>>> org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:48)
>>>>>>>>>        at java.util.TimerThread.mainLoop(Timer.java:512)
>>>>>>>>>        at java.util.TimerThread.run(Timer.java:462)
>>>>>>>>>
>>>>>>>>> Be advise that line 33 is:Endpoint endpoint = (Endpoint)
>>>>>>>>> ((org.apache.camel.Component)
>>>>>>>>> component).createEndpoint("provider:com.amdocs.oxp.esb");
>>>>>>>>>
>>>>>>>>> My questions:
>>>>>>>>>
>>>>>>>>> 1. As bolded above i "fetched" my provider su component
by staing
>>>>>>>>> it's
>>>>>>>>> name
>>>>>>>>> - is it correct?
>>>>>>>>>
>>>>>>>>> 2. I used the following servicemix object (not camel's)
since i
>>>>>>>>> work
>>>>>>>>> with
>>>>>>>>> servicemix provider endpoint. That's the reason for all
the casting
>>>>>>>>> in
>>>>>>>>> my
>>>>>>>>> code:
>>>>>>>>> import org.apache.servicemix.jbi.deployment.Component;
>>>>>>>>> import org.apache.servicemix.jbi.framework.Endpoint;
>>>>>>>>>
>>>>>>>>> Is it correct?
>>>>>>>>>
>>>>>>>>> Thank again,
>>>>>>>>> Liav Ezer.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Claus Ibsen-2 wrote:
>>>>>>>>>>
>>>>>>>>>> Hi
>>>>>>>>>>
>>>>>>>>>> You can use the producer template to call an external
http server
>>>>>>>>>> and
>>>>>>>>>> get the response.
>>>>>>>>>>
>>>>>>>>>> See this tutorial:
>>>>>>>>>> http://activemq.apache.org/camel/tutorial-axis-camel.html
>>>>>>>>>>
>>>>>>>>>> From the section - integrating Camel
>>>>>>>>>>
>>>>>>>>>> Its kinda the same but its just uses the producer
template to save
>>>>>>>>>> a
>>>>>>>>>> file. Its the same API for using any of the camel
components.
>>>>>>>>>>
>>>>>>>>>> Little sidenote:
>>>>>>>>>> And since you use InOut you should use: requestBody
instread of
>>>>>>>>>> sendBody. However Camel is not to stricky about this
yet so if you
>>>>>>>>>> use
>>>>>>>>>> a send instead of request then it should work as
well.
>>>>>>>>>>
>>>>>>>>>> The demo shows how to inject a producer template
from spring into
>>>>>>>>>> your
>>>>>>>>>> bean class = your processor. when you have this template
you can
>>>>>>>>>> call
>>>>>>>>>> the external http server and get the response using
the
>>>>>>>>>> requestBody
>>>>>>>>>> method.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Thu, Jan 8, 2009 at 1:46 PM, Liav Ezer <liav.ezer@gmail.com>
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> Here is my camel-context:
>>>>>>>>>>>
>>>>>>>>>>>  <camelContext id="camel"
>>>>>>>>>>> xmlns="http://activemq.apache.org/camel/schema/spring">
>>>>>>>>>>>    <package>org.apache.servicemix.tutorial.camel</package>
>>>>>>>>>>>  </camelContext>
>>>>>>>>>>>
>>>>>>>>>>>  <bean id="myProcessor"
>>>>>>>>>>> class="org.apache.servicemix.tutorial.camel.MyProcessor"/>
>>>>>>>>>>>
>>>>>>>>>>> Here is my RouteBuilder java file:
>>>>>>>>>>>
>>>>>>>>>>> public class MyRouteBuilder extends RouteBuilder
{
>>>>>>>>>>>        public void configure() {
>>>>>>>>>>>
>>>>>>>>>>> from("timer://tutorial?fixedRate=true&delay=3000&period=10000")
>>>>>>>>>>>                .setBody(constant(".....................Liav
Camel
>>>>>>>>>>> POC......................."))
>>>>>>>>>>>                        .to("myProcessor");
>>>>>>>>>>>
>>>>>>>>>>>    }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> Here is my processor java file:
>>>>>>>>>>> public class MyProcessor implements Processor
{
>>>>>>>>>>>          public void process(Exchange exchange)
throws Exception
>>>>>>>>>>> {
>>>>>>>>>>>              //WANT TO INITIATE A CALL TO http
pROVIDER END POINT
>>>>>>>>>>> &
>>>>>>>>>>> PASS
>>>>>>>>>>> THE
>>>>>>>>>>> 'FROM'
>>>>>>>>>>>                  // PARAMETRS RECIEVED PROIRE
TO THE PROCESSOR
>>>>>>>>>>> INVOKE.
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> Thanks.
>>>>>>>>>>> --
>>>>>>>>>>> View this message in context:
>>>>>>>>>>> http://www.nabble.com/How-do-i-call-an-HTTP-Provider-end-pont-from-the-process-method--tp21351142s22882p21351142.html
>>>>>>>>>>> Sent from the Camel - Users mailing list archive
at Nabble.com.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>>
>>>>>>>>>> /Claus Ibsen
>>>>>>>>>> Apache Camel Committer
>>>>>>>>>> Blog: http://davsclaus.blogspot.com/
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> View this message in context:
>>>>>>>>> http://www.nabble.com/How-do-i-call-an-HTTP-Provider-end-pont-from-the-process-method--tp21351142s22882p21387207.html
>>>>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>> /Claus Ibsen
>>>>>>>> Apache Camel Committer
>>>>>>>> Blog: http://davsclaus.blogspot.com/
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> View this message in context:
>>>>>>> http://www.nabble.com/How-do-i-call-an-HTTP-Provider-end-pont-from-the-process-method--tp21351142s22882p21387318.html
>>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>> /Claus Ibsen
>>>>>> Apache Camel Committer
>>>>>> Blog: http://davsclaus.blogspot.com/
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/How-do-i-call-an-HTTP-Provider-end-pont-from-the-process-method--tp21351142s22882p21388391.html
>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> /Claus Ibsen
>>>> Apache Camel Committer
>>>> Blog: http://davsclaus.blogspot.com/
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/How-do-i-call-an-HTTP-Provider-end-pont-from-the-process-method--tp21351142s22882p21389069.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>>
>> /Claus Ibsen
>> Apache Camel Committer
>> Blog: http://davsclaus.blogspot.com/
>>
>>
>
> --
> View this message in context: http://www.nabble.com/How-do-i-call-an-HTTP-Provider-end-pont-from-the-process-method--tp21351142s22882p21390941.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Mime
View raw message