You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Nguyen Minh Tuan <mi...@gmail.com> on 2011/07/12 12:31:37 UTC

Initialize service context

Hi all,

In my service implementation, I want to refer to some properties set in my
service context. Based on these properties, the implementation logic
changes. And such properties are set before I deploy the service, i.e.
before invoking Endpoint.publish() to create an implementor. By this way, I
can change the service's behavior via different values set to the
properties.

I read about WebServiceContext but it seems not what I am looking for. Since
all values in WebServiceContext are only retrievable and usable in out
interceptors. What I needs is to use those values in my service
implementation.

Could anyone explain to me what I should do in this case?

-- 
Best regards,
Tuan.

Re: Initialize service context

Posted by Nguyen Minh Tuan <mi...@gmail.com>.
Thanks Glen,

These are very good articles.

On Wed, Jul 13, 2011 at 3:50 AM, Glen Mazza <gm...@talend.com> wrote:

> On these two blog entries, search on "WebServiceContext" and you'll see how
> they can be filled used from either JAX-WS handlers or CXF Interceptors, and
> accessed within the web service implementation:
>
> http://www.jroller.com/gmazza/**entry/jaxws_handler_tutorial<http://www.jroller.com/gmazza/entry/jaxws_handler_tutorial>
> http://www.jroller.com/gmazza/**entry/jaxwshandlers_to_**cxfinterceptors<http://www.jroller.com/gmazza/entry/jaxwshandlers_to_cxfinterceptors>
>
> HTH,
> Glen
>
>
> On 07/12/2011 06:31 AM, Nguyen Minh Tuan wrote:
>
>> Hi all,
>>
>> In my service implementation, I want to refer to some properties set in my
>> service context. Based on these properties, the implementation logic
>> changes. And such properties are set before I deploy the service, i.e.
>> before invoking Endpoint.publish() to create an implementor. By this way,
>> I
>> can change the service's behavior via different values set to the
>> properties.
>>
>> I read about WebServiceContext but it seems not what I am looking for.
>> Since
>> all values in WebServiceContext are only retrievable and usable in out
>> interceptors. What I needs is to use those values in my service
>> implementation.
>>
>> Could anyone explain to me what I should do in this case?
>>
>>
>
> --
> Glen Mazza
> Application Integration Division
> Talend (http://www.talend.com/ai)
> blog: http://www.jroller.com/gmazza
>
>
>


-- 
Best regards,
Tuan.

Re: Initialize service context

Posted by Glen Mazza <gm...@talend.com>.
On these two blog entries, search on "WebServiceContext" and you'll see 
how they can be filled used from either JAX-WS handlers or CXF 
Interceptors, and accessed within the web service implementation:

http://www.jroller.com/gmazza/entry/jaxws_handler_tutorial
http://www.jroller.com/gmazza/entry/jaxwshandlers_to_cxfinterceptors

HTH,
Glen

On 07/12/2011 06:31 AM, Nguyen Minh Tuan wrote:
> Hi all,
>
> In my service implementation, I want to refer to some properties set in my
> service context. Based on these properties, the implementation logic
> changes. And such properties are set before I deploy the service, i.e.
> before invoking Endpoint.publish() to create an implementor. By this way, I
> can change the service's behavior via different values set to the
> properties.
>
> I read about WebServiceContext but it seems not what I am looking for. Since
> all values in WebServiceContext are only retrievable and usable in out
> interceptors. What I needs is to use those values in my service
> implementation.
>
> Could anyone explain to me what I should do in this case?
>


-- 
Glen Mazza
Application Integration Division
Talend (http://www.talend.com/ai)
blog: http://www.jroller.com/gmazza



Re: Initialize service context

Posted by Nguyen Minh Tuan <mi...@gmail.com>.
Thanks Sergey,

yes, I registered an input interceptor and it worked as recommended. Thanks
a lot for your help.

On Wed, Jul 13, 2011 at 2:55 AM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi, JAX-WS WebServiceContext is probably doing get() on the current
> Message but does not check contextualProperties (the ones set up
> before the endpoint has been published). Dan can probably confirm that
> - try registering a basic CXF input interceptor and set needed
> properties on the in message, the added bonus is that you can analyze
> the incoming payload if needed and add some dynamism to the way
> properties are set
> Cheers, Sergey
>
> On Tue, Jul 12, 2011 at 4:29 PM, Nguyen Minh Tuan
> <mi...@gmail.com> wrote:
> > Hi Sergey,
> >
> > I tried to set properties using JaxWsServerFactoryBean and then retrieve
> the
> > properties from the service implementation but couldn't do it.
> >
> > Btw, I have the following code snippet to set properties before
> deployment:
> >
> >        JaxWsServerFactoryBean serverFactoryBean = new
> > JaxWsServerFactoryBean();
> >        serverFactoryBean.setServiceClass(CustomerServiceImpl.class);
> >        serverFactoryBean.setAddress("
> > http://localhost:9090/CustomerServicePort");
> >
> >        serverFactoryBean.setProperties(new HashMap<String, Object>());
> >        serverFactoryBean.getProperties().put("ContentBasedCheck",
> > Boolean.TRUE);
> >        serverFactoryBean.getProperties().put("URLBasedCheck",
> > Boolean.FALSE);
> >
> >        serverFactoryBean.create();
> >
> > And in my service implementation, I have the following:
> >    @Resource
> >    private WebServiceContext context;
> >
> > Then I tried to use context.getMessageContext() to retrieve those
> properties
> > but couldn't find any. What did I do wrong?
> >
> > On Tue, Jul 12, 2011 at 10:24 PM, Sergey Beryozkin <sberyozkin@gmail.com
> >wrote:
> >
> >> You can set the properties on JAXWSServerFactoryBean or using
> >> jaxws:endpoint/jaxws:properties and WebServiceContext.get() should
> >> provide an access to those properties
> >> Alternatively, set the properties on a current message from the in
> >> interceptor
> >> Cheers, Sergey
> >>
> >> On Tue, Jul 12, 2011 at 12:48 PM, Nguyen Minh Tuan
> >> <mi...@gmail.com> wrote:
> >> > Thanks Sergey,
> >> >
> >> > How do you set values to properties in WebServiceContext before
> >> deployment?
> >> >
> >> > On Tue, Jul 12, 2011 at 8:42 PM, Sergey Beryozkin <
> sberyozkin@gmail.com
> >> >wrote:
> >> >
> >> >> Hi,
> >> >>
> >> >> On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
> >> >> <mi...@gmail.com> wrote:
> >> >> > Hi all,
> >> >> >
> >> >> > In my service implementation, I want to refer to some properties
> set
> >> in
> >> >> my
> >> >> > service context. Based on these properties, the implementation
> logic
> >> >> > changes. And such properties are set before I deploy the service,
> i.e.
> >> >> > before invoking Endpoint.publish() to create an implementor. By
> this
> >> way,
> >> >> I
> >> >> > can change the service's behavior via different values set to the
> >> >> > properties.
> >> >> >
> >> >> > I read about WebServiceContext but it seems not what I am looking
> for.
> >> >> Since
> >> >> > all values in WebServiceContext are only retrievable and usable in
> out
> >> >> > interceptors. What I needs is to use those values in my service
> >> >> > implementation.
> >> >> >
> >> >> > Could anyone explain to me what I should do in this case?
> >> >> >
> >> >> I think WebServiceContext.get() can be used to get to propreties
> which
> >> >> have been set before the endpoint publication,
> >> >> CXF specific
> >> >> PhaseInterceptorChain.getCurrentMessage().getContextualProperty()
> >> >> will also work
> >> >>
> >> >> Cheers. Sergey
> >> >>
> >> >> > --
> >> >> > Best regards,
> >> >> > Tuan.
> >> >> >
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Sergey Beryozkin
> >> >>
> >> >> http://sberyozkin.blogspot.com
> >> >> Talend - http://www.talend.com
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Best regards,
> >> > Tuan.
> >> >
> >>
> >>
> >>
> >> --
> >> Sergey Beryozkin
> >>
> >> http://sberyozkin.blogspot.com
> >> Talend - http://www.talend.com
> >>
> >
> >
> >
> > --
> > Best regards,
> > Tuan.
> >
>
>
>
> --
> Sergey Beryozkin
>
> http://sberyozkin.blogspot.com
> Talend - http://www.talend.com
>



-- 
Best regards,
Tuan.

Re: Initialize service context

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi, JAX-WS WebServiceContext is probably doing get() on the current
Message but does not check contextualProperties (the ones set up
before the endpoint has been published). Dan can probably confirm that
- try registering a basic CXF input interceptor and set needed
properties on the in message, the added bonus is that you can analyze
the incoming payload if needed and add some dynamism to the way
properties are set
Cheers, Sergey

On Tue, Jul 12, 2011 at 4:29 PM, Nguyen Minh Tuan
<mi...@gmail.com> wrote:
> Hi Sergey,
>
> I tried to set properties using JaxWsServerFactoryBean and then retrieve the
> properties from the service implementation but couldn't do it.
>
> Btw, I have the following code snippet to set properties before deployment:
>
>        JaxWsServerFactoryBean serverFactoryBean = new
> JaxWsServerFactoryBean();
>        serverFactoryBean.setServiceClass(CustomerServiceImpl.class);
>        serverFactoryBean.setAddress("
> http://localhost:9090/CustomerServicePort");
>
>        serverFactoryBean.setProperties(new HashMap<String, Object>());
>        serverFactoryBean.getProperties().put("ContentBasedCheck",
> Boolean.TRUE);
>        serverFactoryBean.getProperties().put("URLBasedCheck",
> Boolean.FALSE);
>
>        serverFactoryBean.create();
>
> And in my service implementation, I have the following:
>    @Resource
>    private WebServiceContext context;
>
> Then I tried to use context.getMessageContext() to retrieve those properties
> but couldn't find any. What did I do wrong?
>
> On Tue, Jul 12, 2011 at 10:24 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
>
>> You can set the properties on JAXWSServerFactoryBean or using
>> jaxws:endpoint/jaxws:properties and WebServiceContext.get() should
>> provide an access to those properties
>> Alternatively, set the properties on a current message from the in
>> interceptor
>> Cheers, Sergey
>>
>> On Tue, Jul 12, 2011 at 12:48 PM, Nguyen Minh Tuan
>> <mi...@gmail.com> wrote:
>> > Thanks Sergey,
>> >
>> > How do you set values to properties in WebServiceContext before
>> deployment?
>> >
>> > On Tue, Jul 12, 2011 at 8:42 PM, Sergey Beryozkin <sberyozkin@gmail.com
>> >wrote:
>> >
>> >> Hi,
>> >>
>> >> On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
>> >> <mi...@gmail.com> wrote:
>> >> > Hi all,
>> >> >
>> >> > In my service implementation, I want to refer to some properties set
>> in
>> >> my
>> >> > service context. Based on these properties, the implementation logic
>> >> > changes. And such properties are set before I deploy the service, i.e.
>> >> > before invoking Endpoint.publish() to create an implementor. By this
>> way,
>> >> I
>> >> > can change the service's behavior via different values set to the
>> >> > properties.
>> >> >
>> >> > I read about WebServiceContext but it seems not what I am looking for.
>> >> Since
>> >> > all values in WebServiceContext are only retrievable and usable in out
>> >> > interceptors. What I needs is to use those values in my service
>> >> > implementation.
>> >> >
>> >> > Could anyone explain to me what I should do in this case?
>> >> >
>> >> I think WebServiceContext.get() can be used to get to propreties which
>> >> have been set before the endpoint publication,
>> >> CXF specific
>> >> PhaseInterceptorChain.getCurrentMessage().getContextualProperty()
>> >> will also work
>> >>
>> >> Cheers. Sergey
>> >>
>> >> > --
>> >> > Best regards,
>> >> > Tuan.
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Sergey Beryozkin
>> >>
>> >> http://sberyozkin.blogspot.com
>> >> Talend - http://www.talend.com
>> >>
>> >
>> >
>> >
>> > --
>> > Best regards,
>> > Tuan.
>> >
>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> http://sberyozkin.blogspot.com
>> Talend - http://www.talend.com
>>
>
>
>
> --
> Best regards,
> Tuan.
>



-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com

Re: Initialize service context

Posted by Nguyen Minh Tuan <mi...@gmail.com>.
Hi Sergey,

I tried to set properties using JaxWsServerFactoryBean and then retrieve the
properties from the service implementation but couldn't do it.

Btw, I have the following code snippet to set properties before deployment:

        JaxWsServerFactoryBean serverFactoryBean = new
JaxWsServerFactoryBean();
        serverFactoryBean.setServiceClass(CustomerServiceImpl.class);
        serverFactoryBean.setAddress("
http://localhost:9090/CustomerServicePort");

        serverFactoryBean.setProperties(new HashMap<String, Object>());
        serverFactoryBean.getProperties().put("ContentBasedCheck",
Boolean.TRUE);
        serverFactoryBean.getProperties().put("URLBasedCheck",
Boolean.FALSE);

        serverFactoryBean.create();

And in my service implementation, I have the following:
    @Resource
    private WebServiceContext context;

Then I tried to use context.getMessageContext() to retrieve those properties
but couldn't find any. What did I do wrong?

On Tue, Jul 12, 2011 at 10:24 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> You can set the properties on JAXWSServerFactoryBean or using
> jaxws:endpoint/jaxws:properties and WebServiceContext.get() should
> provide an access to those properties
> Alternatively, set the properties on a current message from the in
> interceptor
> Cheers, Sergey
>
> On Tue, Jul 12, 2011 at 12:48 PM, Nguyen Minh Tuan
> <mi...@gmail.com> wrote:
> > Thanks Sergey,
> >
> > How do you set values to properties in WebServiceContext before
> deployment?
> >
> > On Tue, Jul 12, 2011 at 8:42 PM, Sergey Beryozkin <sberyozkin@gmail.com
> >wrote:
> >
> >> Hi,
> >>
> >> On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
> >> <mi...@gmail.com> wrote:
> >> > Hi all,
> >> >
> >> > In my service implementation, I want to refer to some properties set
> in
> >> my
> >> > service context. Based on these properties, the implementation logic
> >> > changes. And such properties are set before I deploy the service, i.e.
> >> > before invoking Endpoint.publish() to create an implementor. By this
> way,
> >> I
> >> > can change the service's behavior via different values set to the
> >> > properties.
> >> >
> >> > I read about WebServiceContext but it seems not what I am looking for.
> >> Since
> >> > all values in WebServiceContext are only retrievable and usable in out
> >> > interceptors. What I needs is to use those values in my service
> >> > implementation.
> >> >
> >> > Could anyone explain to me what I should do in this case?
> >> >
> >> I think WebServiceContext.get() can be used to get to propreties which
> >> have been set before the endpoint publication,
> >> CXF specific
> >> PhaseInterceptorChain.getCurrentMessage().getContextualProperty()
> >> will also work
> >>
> >> Cheers. Sergey
> >>
> >> > --
> >> > Best regards,
> >> > Tuan.
> >> >
> >>
> >>
> >>
> >> --
> >> Sergey Beryozkin
> >>
> >> http://sberyozkin.blogspot.com
> >> Talend - http://www.talend.com
> >>
> >
> >
> >
> > --
> > Best regards,
> > Tuan.
> >
>
>
>
> --
> Sergey Beryozkin
>
> http://sberyozkin.blogspot.com
> Talend - http://www.talend.com
>



-- 
Best regards,
Tuan.

Re: Initialize service context

Posted by Sergey Beryozkin <sb...@gmail.com>.
You can set the properties on JAXWSServerFactoryBean or using
jaxws:endpoint/jaxws:properties and WebServiceContext.get() should
provide an access to those properties
Alternatively, set the properties on a current message from the in interceptor
Cheers, Sergey

On Tue, Jul 12, 2011 at 12:48 PM, Nguyen Minh Tuan
<mi...@gmail.com> wrote:
> Thanks Sergey,
>
> How do you set values to properties in WebServiceContext before deployment?
>
> On Tue, Jul 12, 2011 at 8:42 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
>
>> Hi,
>>
>> On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
>> <mi...@gmail.com> wrote:
>> > Hi all,
>> >
>> > In my service implementation, I want to refer to some properties set in
>> my
>> > service context. Based on these properties, the implementation logic
>> > changes. And such properties are set before I deploy the service, i.e.
>> > before invoking Endpoint.publish() to create an implementor. By this way,
>> I
>> > can change the service's behavior via different values set to the
>> > properties.
>> >
>> > I read about WebServiceContext but it seems not what I am looking for.
>> Since
>> > all values in WebServiceContext are only retrievable and usable in out
>> > interceptors. What I needs is to use those values in my service
>> > implementation.
>> >
>> > Could anyone explain to me what I should do in this case?
>> >
>> I think WebServiceContext.get() can be used to get to propreties which
>> have been set before the endpoint publication,
>> CXF specific
>> PhaseInterceptorChain.getCurrentMessage().getContextualProperty()
>> will also work
>>
>> Cheers. Sergey
>>
>> > --
>> > Best regards,
>> > Tuan.
>> >
>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> http://sberyozkin.blogspot.com
>> Talend - http://www.talend.com
>>
>
>
>
> --
> Best regards,
> Tuan.
>



-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com

Re: Initialize service context

Posted by Nguyen Minh Tuan <mi...@gmail.com>.
Thanks Sergey,

How do you set values to properties in WebServiceContext before deployment?

On Tue, Jul 12, 2011 at 8:42 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi,
>
> On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
> <mi...@gmail.com> wrote:
> > Hi all,
> >
> > In my service implementation, I want to refer to some properties set in
> my
> > service context. Based on these properties, the implementation logic
> > changes. And such properties are set before I deploy the service, i.e.
> > before invoking Endpoint.publish() to create an implementor. By this way,
> I
> > can change the service's behavior via different values set to the
> > properties.
> >
> > I read about WebServiceContext but it seems not what I am looking for.
> Since
> > all values in WebServiceContext are only retrievable and usable in out
> > interceptors. What I needs is to use those values in my service
> > implementation.
> >
> > Could anyone explain to me what I should do in this case?
> >
> I think WebServiceContext.get() can be used to get to propreties which
> have been set before the endpoint publication,
> CXF specific
> PhaseInterceptorChain.getCurrentMessage().getContextualProperty()
> will also work
>
> Cheers. Sergey
>
> > --
> > Best regards,
> > Tuan.
> >
>
>
>
> --
> Sergey Beryozkin
>
> http://sberyozkin.blogspot.com
> Talend - http://www.talend.com
>



-- 
Best regards,
Tuan.

Re: Initialize service context

Posted by Nguyen Minh Tuan <mi...@gmail.com>.
Thanks Daniel,

yes, PhaseInterceptorChain.getCurrentMessage().getContextualProperty() also
worked.

On Wed, Jul 13, 2011 at 5:00 AM, Daniel Kulp <dk...@apache.org> wrote:

> On Tuesday, July 12, 2011 11:42:02 AM Sergey Beryozkin wrote:
> > Hi,
> >
> > On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
> >
> > <mi...@gmail.com> wrote:
> > > Hi all,
> > >
> > > In my service implementation, I want to refer to some properties set in
> > > my service context. Based on these properties, the implementation logic
> > > changes. And such properties are set before I deploy the service, i.e.
> > > before invoking Endpoint.publish() to create an implementor. By this
> > > way, I can change the service's behavior via different values set to
> > > the properties.
> > >
> > > I read about WebServiceContext but it seems not what I am looking for.
> > > Since all values in WebServiceContext are only retrievable and usable
> > > in out interceptors. What I needs is to use those values in my service
> > > implementation.
> > >
> > > Could anyone explain to me what I should do in this case?
> >
> > I think WebServiceContext.get() can be used to get to propreties which
> > have been set before the endpoint publication,
>
> Actually, I don't think it does.  I think the context just provides access
> to
> the properties explicitly set during the processing of the message.  It
> doesn't         query the contextual properties.
>
> > CXF specific
> > PhaseInterceptorChain.getCurrentMessage().getContextualProperty() will
> also
> > work
>
> That would definitely work.
>
> Dan
>
> >
> > Cheers. Sergey
> >
> > > --
> > > Best regards,
> > > Tuan.
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
> Talend - http://www.talend.com
>



-- 
Best regards,
Tuan.

Re: Initialize service context

Posted by Daniel Kulp <dk...@apache.org>.
On Tuesday, July 12, 2011 11:42:02 AM Sergey Beryozkin wrote:
> Hi,
> 
> On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
> 
> <mi...@gmail.com> wrote:
> > Hi all,
> > 
> > In my service implementation, I want to refer to some properties set in
> > my service context. Based on these properties, the implementation logic
> > changes. And such properties are set before I deploy the service, i.e.
> > before invoking Endpoint.publish() to create an implementor. By this
> > way, I can change the service's behavior via different values set to
> > the properties.
> > 
> > I read about WebServiceContext but it seems not what I am looking for.
> > Since all values in WebServiceContext are only retrievable and usable
> > in out interceptors. What I needs is to use those values in my service
> > implementation.
> > 
> > Could anyone explain to me what I should do in this case?
> 
> I think WebServiceContext.get() can be used to get to propreties which
> have been set before the endpoint publication,

Actually, I don't think it does.  I think the context just provides access to 
the properties explicitly set during the processing of the message.  It 
doesn't 	query the contextual properties.

> CXF specific
> PhaseInterceptorChain.getCurrentMessage().getContextualProperty() will also
> work

That would definitely work.

Dan

> 
> Cheers. Sergey
> 
> > --
> > Best regards,
> > Tuan.
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: Initialize service context

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,

On Tue, Jul 12, 2011 at 11:31 AM, Nguyen Minh Tuan
<mi...@gmail.com> wrote:
> Hi all,
>
> In my service implementation, I want to refer to some properties set in my
> service context. Based on these properties, the implementation logic
> changes. And such properties are set before I deploy the service, i.e.
> before invoking Endpoint.publish() to create an implementor. By this way, I
> can change the service's behavior via different values set to the
> properties.
>
> I read about WebServiceContext but it seems not what I am looking for. Since
> all values in WebServiceContext are only retrievable and usable in out
> interceptors. What I needs is to use those values in my service
> implementation.
>
> Could anyone explain to me what I should do in this case?
>
I think WebServiceContext.get() can be used to get to propreties which
have been set before the endpoint publication,
CXF specific PhaseInterceptorChain.getCurrentMessage().getContextualProperty()
will also work

Cheers. Sergey

> --
> Best regards,
> Tuan.
>



-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com