You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Andrew Clegg <an...@gmail.com> on 2008/10/01 13:04:08 UTC

Persistent helper objects on server side

Morning all,

This is a slightly noob-ish question that reflects my lack of
experience with Java web apps in general.

I have some objects for database access and business logic which I
want to create on deploying my service WAR. I want these to hang
around within the CXF servlet so they can by called on by my service
implementation classes.

Where do I put the code to initialize them? And how do I call them
from my services?

A pointer to a relevant example would be ideal, unless it's just a
two-line answer.

Thanks in advance,

Andrew.

(PS... The objects in question use Guice for dependency injection, if
anyone has any extra tips about linking CXF to Guice then fire away,
otherwise I'm sure I can figure that part out from a general example.)

Re: Persistent helper objects on server side

Posted by Andrew Clegg <an...@gmail.com>.
2008/10/1 Glen Mazza <gl...@gmail.com>:
>
> For a rather primitive example, you can use a static { } block in your
> service implementation bean as shown here[1] in Step #6.  It's a start at
> least.

I didn't think of that. Nice one. I'm sure there's a 'proper' way with
servlet context listeners or something, but this will get me off the
ground quickly.

> But note that other portions of the below blog entry (not covering
> the static {} ) have since been heavily updated, with the new link at the
> top of [1].

I'm very familiar with the later version already, it got me started
with JAX-WS and helped me choose between CXF and Metro. In short it's
been indispensable, so thanks :-)

Andrew.

Re: Persistent helper objects on server side

Posted by Glen Mazza <gl...@gmail.com>.
For a rather primitive example, you can use a static { } block in your
service implementation bean as shown here[1] in Step #6.  It's a start at
least.  But note that other portions of the below blog entry (not covering
the static {} ) have since been heavily updated, with the new link at the
top of [1].

HTH,
Glen

[1] http://www.jroller.com/gmazza/date/20071019



Andrew Clegg wrote:
> 
> Morning all,
> 
> This is a slightly noob-ish question that reflects my lack of
> experience with Java web apps in general.
> 
> I have some objects for database access and business logic which I
> want to create on deploying my service WAR. I want these to hang
> around within the CXF servlet so they can by called on by my service
> implementation classes.
> 
> Where do I put the code to initialize them? And how do I call them
> from my services?
> 
> A pointer to a relevant example would be ideal, unless it's just a
> two-line answer.
> 
> Thanks in advance,
> 
> Andrew.
> 
> (PS... The objects in question use Guice for dependency injection, if
> anyone has any extra tips about linking CXF to Guice then fire away,
> otherwise I'm sure I can figure that part out from a general example.)
> 



-- 
View this message in context: http://www.nabble.com/Persistent-helper-objects-on-server-side-tp19758230p19759680.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Persistent helper objects on server side

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday 01 October 2008, Andrew Clegg wrote:
> Thanks, I'll look into the bus option. I guess the advantage of this
> over Glen's static initializer is that you could share objects on the
> bus between different services?

Yep.   The Bus has add/get extension things that you can use to 
store/retrieve objects.   All users of that bus can share those things.

Dan


> Bit reluctant to go for a Spring solution as there's only one coder on
> this project -- me -- with a total of 0 days Spring experience.
>
> Cheers,
>
> Andrew.
>
> On 1 Oct 2008, at 17:53, Daniel Kulp <dk...@apache.org> wrote:
> > I guess the "proper" answer for us at this point would be to define
> > the
> > objects in Spring and let spring inject them into your service beans
> > and
> > stuff.   That's more or less the normal way we do it.
> >
> > Another option it to inject the Bus into your service with:
> > @Resource
> > Bus bus;
> >
> > And save things on the bus that you could retrieve later.
> >
> > Dan
> >
> > On Wednesday 01 October 2008, Andrew Clegg wrote:
> >> Morning all,
> >>
> >> This is a slightly noob-ish question that reflects my lack of
> >> experience with Java web apps in general.
> >>
> >> I have some objects for database access and business logic which I
> >> want to create on deploying my service WAR. I want these to hang
> >> around within the CXF servlet so they can by called on by my
> >> service implementation classes.
> >>
> >> Where do I put the code to initialize them? And how do I call them
> >> from my services?
> >>
> >> A pointer to a relevant example would be ideal, unless it's just a
> >> two-line answer.
> >>
> >> Thanks in advance,
> >>
> >> Andrew.
> >>
> >> (PS... The objects in question use Guice for dependency injection,
> >> if anyone has any extra tips about linking CXF to Guice then fire
> >> away, otherwise I'm sure I can figure that part out from a general
> >> example.)
> >
> > --
> > J. Daniel Kulp
> > Principal Engineer, IONA
> > dkulp@apache.org
> > http://www.dankulp.com/blog



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: Persistent helper objects on server side

Posted by Andrew Clegg <an...@gmail.com>.
Thanks, I'll look into the bus option. I guess the advantage of this  
over Glen's static initializer is that you could share objects on the  
bus between different services?

Bit reluctant to go for a Spring solution as there's only one coder on  
this project -- me -- with a total of 0 days Spring experience.

Cheers,

Andrew.


On 1 Oct 2008, at 17:53, Daniel Kulp <dk...@apache.org> wrote:

>
> I guess the "proper" answer for us at this point would be to define  
> the
> objects in Spring and let spring inject them into your service beans  
> and
> stuff.   That's more or less the normal way we do it.
>
> Another option it to inject the Bus into your service with:
> @Resource
> Bus bus;
>
> And save things on the bus that you could retrieve later.
>
> Dan
>
>
>
>
> On Wednesday 01 October 2008, Andrew Clegg wrote:
>> Morning all,
>>
>> This is a slightly noob-ish question that reflects my lack of
>> experience with Java web apps in general.
>>
>> I have some objects for database access and business logic which I
>> want to create on deploying my service WAR. I want these to hang
>> around within the CXF servlet so they can by called on by my service
>> implementation classes.
>>
>> Where do I put the code to initialize them? And how do I call them
>> from my services?
>>
>> A pointer to a relevant example would be ideal, unless it's just a
>> two-line answer.
>>
>> Thanks in advance,
>>
>> Andrew.
>>
>> (PS... The objects in question use Guice for dependency injection, if
>> anyone has any extra tips about linking CXF to Guice then fire away,
>> otherwise I'm sure I can figure that part out from a general  
>> example.)
>
>
>
> -- 
> J. Daniel Kulp
> Principal Engineer, IONA
> dkulp@apache.org
> http://www.dankulp.com/blog

Re: Persistent helper objects on server side

Posted by Daniel Kulp <dk...@apache.org>.
I guess the "proper" answer for us at this point would be to define the 
objects in Spring and let spring inject them into your service beans and 
stuff.   That's more or less the normal way we do it.

Another option it to inject the Bus into your service with:
@Resource
Bus bus;

And save things on the bus that you could retrieve later.  

Dan




On Wednesday 01 October 2008, Andrew Clegg wrote:
> Morning all,
>
> This is a slightly noob-ish question that reflects my lack of
> experience with Java web apps in general.
>
> I have some objects for database access and business logic which I
> want to create on deploying my service WAR. I want these to hang
> around within the CXF servlet so they can by called on by my service
> implementation classes.
>
> Where do I put the code to initialize them? And how do I call them
> from my services?
>
> A pointer to a relevant example would be ideal, unless it's just a
> two-line answer.
>
> Thanks in advance,
>
> Andrew.
>
> (PS... The objects in question use Guice for dependency injection, if
> anyone has any extra tips about linking CXF to Guice then fire away,
> otherwise I'm sure I can figure that part out from a general example.)



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog