You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by liugang594 Liu <cl...@gmail.com> on 2013/09/06 05:36:53 UTC

CxfProducer cache problem on Camel

Hi All:

I found the CxfProducer object will be cached to reuse in Camel, however
this may can's suatable for any time, to make things simple, assume we have
below route:

class CustomDefaultCxfBinding extends DefaultCxfBinding {
private String a;
public CustomDefaultCxfBinding(String a) {
this.a = a;
setHeaderFilterStrategy(new CxfHeaderFilterStrategy());
}

@Override
public void populateCxfRequestFromExchange(org.apache.cxf.message.Exchange
cxfExchange,
Exchange camelExchange, Map<String, Object> requestContext) {
System.out.println(a);
super.populateCxfRequestFromExchange(cxfExchange,camelExchange,
requestContext);
}
}

String url = "...";
CxfEndpoint cxfEndpoint1 = (CxfEndpoint) endpoint(url);
cxfEndpoint1.setCxfBinding(new CustomDefaultCxfBinding("a1"));
 CxfEndpoint cxfEndpoint2 = (CxfEndpoint) endpoint(url);
cxfEndpoint2.setCxfBinding(new CustomDefaultCxfBinding("a2"));

from("timer:foo?repeatCount=1") .setBody(constant(content)).to(cxfEndpoint1)
.setBody(constant(content)).to(cxfEndpoint2);


both "a1" and "a2" are expected to be printed, but only "a2" for now.

Does anybody knows how to handle this situation?
Thanks alot


-- 
Thanks
GangLiu
Mail: clevers594@gmail.com

Re: CxfProducer cache problem on Camel

Posted by liugang594 Liu <cl...@gmail.com>.
Hi Claus:

Thanks in advance.

After changed to use different uri, both a1 and a2 can be printed
correctly, however I found another problem, *If I stored this value into
requestContext with a static kay*, then all request has the same value. for
example changed CustomDefaultCxfBinding  as below

class CustomDefaultCxfBinding extends DefaultCxfBinding {
private String a;
public CustomDefaultCxfBinding(String a) {
this.a = a;
setHeaderFilterStrategy(new CxfHeaderFilterStrategy());
}

@Override
public void populateCxfRequestFromExchange(org.apache.cxf.message.Exchange
cxfExchange,
Exchange camelExchange, Map<String, Object> requestContext) {
*requestContext.put("ZZZZZ", **a);*
super.populateCxfRequestFromExchange(cxfExchange,camelExchange,
requestContext);
}
}

then the value of *"ZZZZZ" in requestContext will always be a1* when
sending the request.

so I can't get the right value corresponding to each request.



2013/9/6 liugang594 Liu <cl...@gmail.com>

> but it's not a bug? because all endpoint have the same CxfBinding instance
> even I specified individually.
>
>
> 2013/9/6 Claus Ibsen <cl...@gmail.com>
>
>> Hi
>>
>> The url is the same in the endpoint(url) so you get the same instance.
>> And then afterwards you set the custom cxf binding. You need 2
>> different urls, so its 2 different endpoint instances. Or you can
>> crate the cxf endpoints using java code, with the new constructor.
>>
>> On Fri, Sep 6, 2013 at 5:36 AM, liugang594 Liu <cl...@gmail.com>
>> wrote:
>> > Hi All:
>> >
>> > I found the CxfProducer object will be cached to reuse in Camel, however
>> > this may can's suatable for any time, to make things simple, assume we
>> have
>> > below route:
>> >
>> > class CustomDefaultCxfBinding extends DefaultCxfBinding {
>> > private String a;
>> > public CustomDefaultCxfBinding(String a) {
>> > this.a = a;
>> > setHeaderFilterStrategy(new CxfHeaderFilterStrategy());
>> > }
>> >
>> > @Override
>> > public void
>> populateCxfRequestFromExchange(org.apache.cxf.message.Exchange
>> > cxfExchange,
>> > Exchange camelExchange, Map<String, Object> requestContext) {
>> > System.out.println(a);
>> > super.populateCxfRequestFromExchange(cxfExchange,camelExchange,
>> > requestContext);
>> > }
>> > }
>> >
>> > String url = "...";
>> > CxfEndpoint cxfEndpoint1 = (CxfEndpoint) endpoint(url);
>> > cxfEndpoint1.setCxfBinding(new CustomDefaultCxfBinding("a1"));
>> >  CxfEndpoint cxfEndpoint2 = (CxfEndpoint) endpoint(url);
>> > cxfEndpoint2.setCxfBinding(new CustomDefaultCxfBinding("a2"));
>> >
>> > from("timer:foo?repeatCount=1")
>> .setBody(constant(content)).to(cxfEndpoint1)
>> > .setBody(constant(content)).to(cxfEndpoint2);
>> >
>> >
>> > both "a1" and "a2" are expected to be printed, but only "a2" for now.
>> >
>> > Does anybody knows how to handle this situation?
>> > Thanks alot
>> >
>> >
>> > --
>> > Thanks
>> > GangLiu
>> > Mail: clevers594@gmail.com
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>
>
>
>
> --
> Thanks
> GangLiu
> Mail: clevers594@gmail.com
>
>


-- 
Thanks
GangLiu
Mail: clevers594@gmail.com

Re: CxfProducer cache problem on Camel

Posted by liugang594 Liu <cl...@gmail.com>.
but it's not a bug? because all endpoint have the same CxfBinding instance
even I specified individually.


2013/9/6 Claus Ibsen <cl...@gmail.com>

> Hi
>
> The url is the same in the endpoint(url) so you get the same instance.
> And then afterwards you set the custom cxf binding. You need 2
> different urls, so its 2 different endpoint instances. Or you can
> crate the cxf endpoints using java code, with the new constructor.
>
> On Fri, Sep 6, 2013 at 5:36 AM, liugang594 Liu <cl...@gmail.com>
> wrote:
> > Hi All:
> >
> > I found the CxfProducer object will be cached to reuse in Camel, however
> > this may can's suatable for any time, to make things simple, assume we
> have
> > below route:
> >
> > class CustomDefaultCxfBinding extends DefaultCxfBinding {
> > private String a;
> > public CustomDefaultCxfBinding(String a) {
> > this.a = a;
> > setHeaderFilterStrategy(new CxfHeaderFilterStrategy());
> > }
> >
> > @Override
> > public void
> populateCxfRequestFromExchange(org.apache.cxf.message.Exchange
> > cxfExchange,
> > Exchange camelExchange, Map<String, Object> requestContext) {
> > System.out.println(a);
> > super.populateCxfRequestFromExchange(cxfExchange,camelExchange,
> > requestContext);
> > }
> > }
> >
> > String url = "...";
> > CxfEndpoint cxfEndpoint1 = (CxfEndpoint) endpoint(url);
> > cxfEndpoint1.setCxfBinding(new CustomDefaultCxfBinding("a1"));
> >  CxfEndpoint cxfEndpoint2 = (CxfEndpoint) endpoint(url);
> > cxfEndpoint2.setCxfBinding(new CustomDefaultCxfBinding("a2"));
> >
> > from("timer:foo?repeatCount=1")
> .setBody(constant(content)).to(cxfEndpoint1)
> > .setBody(constant(content)).to(cxfEndpoint2);
> >
> >
> > both "a1" and "a2" are expected to be printed, but only "a2" for now.
> >
> > Does anybody knows how to handle this situation?
> > Thanks alot
> >
> >
> > --
> > Thanks
> > GangLiu
> > Mail: clevers594@gmail.com
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>



-- 
Thanks
GangLiu
Mail: clevers594@gmail.com

Re: CxfProducer cache problem on Camel

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

The url is the same in the endpoint(url) so you get the same instance.
And then afterwards you set the custom cxf binding. You need 2
different urls, so its 2 different endpoint instances. Or you can
crate the cxf endpoints using java code, with the new constructor.

On Fri, Sep 6, 2013 at 5:36 AM, liugang594 Liu <cl...@gmail.com> wrote:
> Hi All:
>
> I found the CxfProducer object will be cached to reuse in Camel, however
> this may can's suatable for any time, to make things simple, assume we have
> below route:
>
> class CustomDefaultCxfBinding extends DefaultCxfBinding {
> private String a;
> public CustomDefaultCxfBinding(String a) {
> this.a = a;
> setHeaderFilterStrategy(new CxfHeaderFilterStrategy());
> }
>
> @Override
> public void populateCxfRequestFromExchange(org.apache.cxf.message.Exchange
> cxfExchange,
> Exchange camelExchange, Map<String, Object> requestContext) {
> System.out.println(a);
> super.populateCxfRequestFromExchange(cxfExchange,camelExchange,
> requestContext);
> }
> }
>
> String url = "...";
> CxfEndpoint cxfEndpoint1 = (CxfEndpoint) endpoint(url);
> cxfEndpoint1.setCxfBinding(new CustomDefaultCxfBinding("a1"));
>  CxfEndpoint cxfEndpoint2 = (CxfEndpoint) endpoint(url);
> cxfEndpoint2.setCxfBinding(new CustomDefaultCxfBinding("a2"));
>
> from("timer:foo?repeatCount=1") .setBody(constant(content)).to(cxfEndpoint1)
> .setBody(constant(content)).to(cxfEndpoint2);
>
>
> both "a1" and "a2" are expected to be printed, but only "a2" for now.
>
> Does anybody knows how to handle this situation?
> Thanks alot
>
>
> --
> Thanks
> GangLiu
> Mail: clevers594@gmail.com



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen