How to call another service?

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

How to call another service?

Ihor Lozinsky
Hello.
I have a problem.
I have one SE for the ServiceMix 3.2.2 and I wont to call another
service from the same SM.
I found next code:

/InOnly exchange = client.createInOnlyExchange();

NormalizedMessage message = exchange.getInMessage();
message.setProperty("name", "James");
message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));

// lets use a specific service to dispatch to
QName service = new QName("http://servicemix.org/cheese/", "receiver");
exchange.setService(service);
client.send(exchange);/

But I have no idea how to incorporate it into my endpoint class:

/protected void processInOnly(MessageExchange exchange,
NormalizedMessage in) throws Exception {      
       // do smth
        System.out.println("[Calling other service]");
       // CALL OTHER SERVICE!
}


/Thanks for any idea.
Ihor. aigor(dog)iforma(dot)com(dot)ua
Reply | Threaded
Open this post in threaded view
|

Re: How to call another service?

Jean-Baptiste Onofré
 What's the component used in your SE ?
 What do you mean by "call another service" : take the output of the
first SE and push the a second one ?

 In fact, it depends that you want to do :
 - in your existing SE is base on CXF, you can push the output
message (depending of your MEP) to your other SE
 - if you need more advanced routing, you can use camel component to
route the message through your different SE (depending of the EIP) ?

 Regards
 JB
 --
 Jean-Baptiste Onofré
 [hidden email]
 BuildProcess/AutoDeploy Project Leader
 http://buildprocess.sourceforge.net

 On Mon 24/11/08 17:51, aigor [hidden email] wrote:
 Hello.
 I have a problem.
 I have one SE for the ServiceMix 3.2.2 and I wont to call another
 service from the same SM.
 I found next code:

 /InOnly exchange = client.createInOnlyExchange();

 NormalizedMessage message = exchange.getInMessage();
 message.setProperty("name", "James");
 message.setContent(new StreamSource(new StringReader("world")));

 // lets use a specific service to dispatch to
 QName service = new QName("http://servicemix.org/cheese/", [1]
"receiver");
 exchange.setService(service);
 client.send(exchange);/

 But I have no idea how to incorporate it into my endpoint class:

 /protected void processInOnly(MessageExchange exchange,
 NormalizedMessage in) throws Exception {
 // do smth
 System.out.println("[Calling other service]");
 // CALL OTHER SERVICE!
 }

 /Thanks for any idea.
 Ihor. aigor(dog)iforma(dot)com(dot)ua



Links:
------
[1] http://servicemix.org/cheese/
Reply | Threaded
Open this post in threaded view
|

Re: How to call another service?

Freeman-2
In reply to this post by Ihor Lozinsky
Hi,
I guess you mean you don't know how to get client instance here, right?
If so, this code piece should be helpful
ServiceMixClient client = new ServiceMixClientFacade(context);  //
context is instance of ComponentContext, you can get it from your endpoint

Freeman

aigor wrote:

> Hello.
> I have a problem.
> I have one SE for the ServiceMix 3.2.2 and I wont to call another
> service from the same SM.
> I found next code:
>
> /InOnly exchange = client.createInOnlyExchange();
>
> NormalizedMessage message = exchange.getInMessage();
> message.setProperty("name", "James");
> message.setContent(new StreamSource(new
> StringReader("<hello>world</hello>")));
>
> // lets use a specific service to dispatch to
> QName service = new QName("http://servicemix.org/cheese/", "receiver");
> exchange.setService(service);
> client.send(exchange);/
>
> But I have no idea how to incorporate it into my endpoint class:
>
> /protected void processInOnly(MessageExchange exchange,
> NormalizedMessage in) throws Exception {            // do smth
>        System.out.println("[Calling other service]");
>       // CALL OTHER SERVICE!
> }
>
>
> /Thanks for any idea.
> Ihor. aigor(dog)iforma(dot)com(dot)ua
>

Reply | Threaded
Open this post in threaded view
|

Re: How to call another service?

Ihor Lozinsky
Freeman, thank you.
This really  have helped me.


Freeman Fang wrote:

> Hi,
> I guess you mean you don't know how to get client instance here, right?
> If so, this code piece should be helpful
> ServiceMixClient client = new ServiceMixClientFacade(context);  //
> context is instance of ComponentContext, you can get it from your
> endpoint
>
> Freeman
>
> aigor wrote:
>> Hello.
>> I have a problem.
>> I have one SE for the ServiceMix 3.2.2 and I wont to call another
>> service from the same SM.
>> I found next code:
>>
>> /InOnly exchange = client.createInOnlyExchange();
>>
>> NormalizedMessage message = exchange.getInMessage();
>> message.setProperty("name", "James");
>> message.setContent(new StreamSource(new
>> StringReader("<hello>world</hello>")));
>>
>> // lets use a specific service to dispatch to
>> QName service = new QName("http://servicemix.org/cheese/", "receiver");
>> exchange.setService(service);
>> client.send(exchange);/
>>
>> But I have no idea how to incorporate it into my endpoint class:
>>
>> /protected void processInOnly(MessageExchange exchange,
>> NormalizedMessage in) throws Exception {            // do smth
>>        System.out.println("[Calling other service]");
>>       // CALL OTHER SERVICE!
>> }
>>
>>
>> /Thanks for any idea.
>> Ihor. aigor(dog)iforma(dot)com(dot)ua
>>
>
>