You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by David Ventimiglia <dv...@gmail.com> on 2014/10/06 07:40:12 UTC

Olingo Java v2 : how to inject context info into servlet application

Hi,

I'm using the ODataServlet.  As far as I can tell, the only interaction
that users of this class have with the rest of their Olingo application
components--which comprise the ODataServiceFactory, EdmProvider, and
ODataSingleProcessor implementations--is that setting
the ODataServiceFactory.FACTORY_LABEL init parameter for the servlet in the
web.xml is the way that you tell the servlet to use a particular
ODataServiceFactory.  Suppose you have other configuration or context
information you want to get into the ODataServiceFactory implementation and
related classes, such as JNDI resource names (e.g., for a JDBC DataSource),
login credentials, configuration settings, etc., and that this information
is recorded in the web.xml file.  How do you get that information into the
ODataServiceFactory?  There don't seem to be any "hooks."  It takes a
ODataContext parameter, but I don't know what that is or how I can control
its value at all.

Thanks,
David

Re: AW: Olingo Java v2 : how to inject context info into servlet application

Posted by David Ventimiglia <dv...@gmail.com>.
Hi Stefan.  I could do that, and it might be worthwhile.  But in the end I
just said, "The Hell with it" and put servlet init parameters that
influence Olingo into the System properties and moved on with my life. :-)
But, thanks!

Best regards,
David
On Oct 15, 2014 7:54 AM, "Roehrig, Stefan" <
stefan.roehrig@vaillant-group.com> wrote:

>  Hi David,
>
>
>
> if you have to inject something, how about the following approach:
>
> ·         Create a filter and a singleton with a thread local variable
>
> ·         Create the object you want to inject in the filter and store it
> in the thread local variable of the singleton
>
> ·         Get the singleton in the Olingo service and fetch the object
> from the thread local variable.
>
>
>
> Regards,
>
> Stefan
>
>
>
> --
> *Stefan Röhrig* – Consultant Group IT - BPM
>
> Vaillant Group IT
> Tel. +49 2191 18 4725 Ÿ Mobile +49 175 2951 757 Ÿ Fax +49 2191 18 74725
>
> E-Mail: stefan.roehrig@vaillant-group.com
> <fi...@vaillant-group.com> Ÿ http://www.vaillant-group.com
>
> Vaillant Group Business Services GmbH, Berghauser Str. 63, D-42859
> Remscheid
> Sitz: Remscheid Ÿ Registergericht: Amtsgericht Wuppertal HRB 11591 Ÿ
> Geschäftsführer: Dr. Stefan Borchers, Cahit Gürdal Ergüven
> *Always think green before printing! *
>
>
>
> *Von:* David Ventimiglia [mailto:dventimi@gmail.com]
> *Gesendet:* Montag, 6. Oktober 2014 14:28
> *An:* user@olingo.apache.org
> *Betreff:* Re: Olingo Java v2 : how to inject context info into servlet
> application
>
>
>
> Hi Michael,
>
>
>
> Terrific!  Thanks.  I look forward to switching to Olingo v4 when it's out
> of beta.
>
>
>
> Best regards,
>
> David
>
>
>
> On Mon, Oct 6, 2014 at 5:24 AM, Michael <mi...@apache.org> wrote:
>
> Hi David,
>
> based on the experience in Olingo Java V2 the approach to create an
> OData service has changed for Olingo Java V4.
> Although it is now necessary to implement your own e.g. "HttpServlet",
> however the Olingo library provide more support to create just the
> parts which you need for your own service.
>
> As example you can take a look into
> "org.apache.olingo.server.tecsvc.TechnicalServlet" in the
> "server-tecsvc" module.
> This sample service servlet overrides the "service()" method in which
> the own "*Processor" and "EdmProvider" are created and then from
> Apache Olingo the according OData service and OData handler are used
> to further process the request base on OData specification.
>
> {code snippet}
>      OData odata = OData.newInstance();
>       Edm edm = odata.createEdm(new EdmTechProvider());
>       ODataHttpHandler handler = odata.createHandler(edm);
>       handler.register(new TechnicalProcessor(dataProvider));
>       handler.process(req, resp);
> {code snippet}
>
> Kind regards,
> Michael
>
>
>
> On Mon, Oct 6, 2014 at 1:08 PM, David Ventimiglia <dv...@gmail.com>
> wrote:
> > Hi Michael,
> >
> > That's good advice.  Thank you.  Are things any different in Olingo Java
> v4?
> >
> > Best regards,
> > David
> >
> > On Mon, Oct 6, 2014 at 12:17 AM, Michael <mi...@apache.org> wrote:
> >>
> >> Hi David,
> >>
> >> unfortunately there is now supported way to pass init parameters from
> >> the "web.xml" into the ODataServlet or ODataServiceFactory.
> >> Either you read your additional configuration during the
> >> initialization of your ODataServiceFactory implementation (e.g. in
> >> "createService()") or your have to implement your own version of an
> >> ODataServlet (which is not recommended).
> >>
> >> IMHO in my project I would create an additional "ConfigService" as
> >> singleton which a) read all necessary configurations once from a
> >> "Properties" file and b) then is called from my ODataServiceFactory
> >> implementation.
> >>
> >> Kind regards,
> >> Michael
> >>
> >> On Mon, Oct 6, 2014 at 7:40 AM, David Ventimiglia <dv...@gmail.com>
> >> wrote:
> >> > Hi,
> >> >
> >> > I'm using the ODataServlet.  As far as I can tell, the only
> interaction
> >> > that
> >> > users of this class have with the rest of their Olingo application
> >> > components--which comprise the ODataServiceFactory, EdmProvider, and
> >> > ODataSingleProcessor implementations--is that setting the
> >> > ODataServiceFactory.FACTORY_LABEL init parameter for the servlet in
> the
> >> > web.xml is the way that you tell the servlet to use a particular
> >> > ODataServiceFactory.  Suppose you have other configuration or context
> >> > information you want to get into the ODataServiceFactory
> implementation
> >> > and
> >> > related classes, such as JNDI resource names (e.g., for a JDBC
> >> > DataSource),
> >> > login credentials, configuration settings, etc., and that this
> >> > information
> >> > is recorded in the web.xml file.  How do you get that information into
> >> > the
> >> > ODataServiceFactory?  There don't seem to be any "hooks."  It takes a
> >> > ODataContext parameter, but I don't know what that is or how I can
> >> > control
> >> > its value at all.
> >> >
> >> > Thanks,
> >> > David
> >
> >
>
>
>

AW: Olingo Java v2 : how to inject context info into servlet application

Posted by "Roehrig, Stefan" <st...@vaillant-group.com>.
Hi David,

if you have to inject something, how about the following approach:

·         Create a filter and a singleton with a thread local variable

·         Create the object you want to inject in the filter and store it in the thread local variable of the singleton

·         Get the singleton in the Olingo service and fetch the object from the thread local variable.

Regards,
Stefan

--
Stefan Röhrig – Consultant Group IT - BPM

Vaillant Group IT
Tel. +49 2191 18 4725 • Mobile +49 175 2951 757 • Fax +49 2191 18 74725
E-Mail: stefan.roehrig@vaillant-group.com<ma...@vaillant-group.com> • http://www.vaillant-group.com<http://www.vaillant-group.com/>

Vaillant Group Business Services GmbH, Berghauser Str. 63, D-42859 Remscheid
Sitz: Remscheid • Registergericht: Amtsgericht Wuppertal HRB 11591 • Geschäftsführer: Dr. Stefan Borchers, Cahit Gürdal Ergüven
Always think green before printing!


Von: David Ventimiglia [mailto:dventimi@gmail.com]
Gesendet: Montag, 6. Oktober 2014 14:28
An: user@olingo.apache.org
Betreff: Re: Olingo Java v2 : how to inject context info into servlet application

Hi Michael,

Terrific!  Thanks.  I look forward to switching to Olingo v4 when it's out of beta.

Best regards,
David

On Mon, Oct 6, 2014 at 5:24 AM, Michael <mi...@apache.org>> wrote:
Hi David,

based on the experience in Olingo Java V2 the approach to create an
OData service has changed for Olingo Java V4.
Although it is now necessary to implement your own e.g. "HttpServlet",
however the Olingo library provide more support to create just the
parts which you need for your own service.

As example you can take a look into
"org.apache.olingo.server.tecsvc.TechnicalServlet" in the
"server-tecsvc" module.
This sample service servlet overrides the "service()" method in which
the own "*Processor" and "EdmProvider" are created and then from
Apache Olingo the according OData service and OData handler are used
to further process the request base on OData specification.

{code snippet}
     OData odata = OData.newInstance();
      Edm edm = odata.createEdm(new EdmTechProvider());
      ODataHttpHandler handler = odata.createHandler(edm);
      handler.register(new TechnicalProcessor(dataProvider));
      handler.process(req, resp);
{code snippet}

Kind regards,
Michael


On Mon, Oct 6, 2014 at 1:08 PM, David Ventimiglia <dv...@gmail.com>> wrote:
> Hi Michael,
>
> That's good advice.  Thank you.  Are things any different in Olingo Java v4?
>
> Best regards,
> David
>
> On Mon, Oct 6, 2014 at 12:17 AM, Michael <mi...@apache.org>> wrote:
>>
>> Hi David,
>>
>> unfortunately there is now supported way to pass init parameters from
>> the "web.xml" into the ODataServlet or ODataServiceFactory.
>> Either you read your additional configuration during the
>> initialization of your ODataServiceFactory implementation (e.g. in
>> "createService()") or your have to implement your own version of an
>> ODataServlet (which is not recommended).
>>
>> IMHO in my project I would create an additional "ConfigService" as
>> singleton which a) read all necessary configurations once from a
>> "Properties" file and b) then is called from my ODataServiceFactory
>> implementation.
>>
>> Kind regards,
>> Michael
>>
>> On Mon, Oct 6, 2014 at 7:40 AM, David Ventimiglia <dv...@gmail.com>>
>> wrote:
>> > Hi,
>> >
>> > I'm using the ODataServlet.  As far as I can tell, the only interaction
>> > that
>> > users of this class have with the rest of their Olingo application
>> > components--which comprise the ODataServiceFactory, EdmProvider, and
>> > ODataSingleProcessor implementations--is that setting the
>> > ODataServiceFactory.FACTORY_LABEL init parameter for the servlet in the
>> > web.xml is the way that you tell the servlet to use a particular
>> > ODataServiceFactory.  Suppose you have other configuration or context
>> > information you want to get into the ODataServiceFactory implementation
>> > and
>> > related classes, such as JNDI resource names (e.g., for a JDBC
>> > DataSource),
>> > login credentials, configuration settings, etc., and that this
>> > information
>> > is recorded in the web.xml file.  How do you get that information into
>> > the
>> > ODataServiceFactory?  There don't seem to be any "hooks."  It takes a
>> > ODataContext parameter, but I don't know what that is or how I can
>> > control
>> > its value at all.
>> >
>> > Thanks,
>> > David
>
>


Re: Olingo Java v2 : how to inject context info into servlet application

Posted by David Ventimiglia <dv...@gmail.com>.
Hi Michael,

Terrific!  Thanks.  I look forward to switching to Olingo v4 when it's out
of beta.

Best regards,
David

On Mon, Oct 6, 2014 at 5:24 AM, Michael <mi...@apache.org> wrote:

> Hi David,
>
> based on the experience in Olingo Java V2 the approach to create an
> OData service has changed for Olingo Java V4.
> Although it is now necessary to implement your own e.g. "HttpServlet",
> however the Olingo library provide more support to create just the
> parts which you need for your own service.
>
> As example you can take a look into
> "org.apache.olingo.server.tecsvc.TechnicalServlet" in the
> "server-tecsvc" module.
> This sample service servlet overrides the "service()" method in which
> the own "*Processor" and "EdmProvider" are created and then from
> Apache Olingo the according OData service and OData handler are used
> to further process the request base on OData specification.
>
> {code snippet}
>      OData odata = OData.newInstance();
>       Edm edm = odata.createEdm(new EdmTechProvider());
>       ODataHttpHandler handler = odata.createHandler(edm);
>       handler.register(new TechnicalProcessor(dataProvider));
>       handler.process(req, resp);
> {code snippet}
>
> Kind regards,
> Michael
>
>
> On Mon, Oct 6, 2014 at 1:08 PM, David Ventimiglia <dv...@gmail.com>
> wrote:
> > Hi Michael,
> >
> > That's good advice.  Thank you.  Are things any different in Olingo Java
> v4?
> >
> > Best regards,
> > David
> >
> > On Mon, Oct 6, 2014 at 12:17 AM, Michael <mi...@apache.org> wrote:
> >>
> >> Hi David,
> >>
> >> unfortunately there is now supported way to pass init parameters from
> >> the "web.xml" into the ODataServlet or ODataServiceFactory.
> >> Either you read your additional configuration during the
> >> initialization of your ODataServiceFactory implementation (e.g. in
> >> "createService()") or your have to implement your own version of an
> >> ODataServlet (which is not recommended).
> >>
> >> IMHO in my project I would create an additional "ConfigService" as
> >> singleton which a) read all necessary configurations once from a
> >> "Properties" file and b) then is called from my ODataServiceFactory
> >> implementation.
> >>
> >> Kind regards,
> >> Michael
> >>
> >> On Mon, Oct 6, 2014 at 7:40 AM, David Ventimiglia <dv...@gmail.com>
> >> wrote:
> >> > Hi,
> >> >
> >> > I'm using the ODataServlet.  As far as I can tell, the only
> interaction
> >> > that
> >> > users of this class have with the rest of their Olingo application
> >> > components--which comprise the ODataServiceFactory, EdmProvider, and
> >> > ODataSingleProcessor implementations--is that setting the
> >> > ODataServiceFactory.FACTORY_LABEL init parameter for the servlet in
> the
> >> > web.xml is the way that you tell the servlet to use a particular
> >> > ODataServiceFactory.  Suppose you have other configuration or context
> >> > information you want to get into the ODataServiceFactory
> implementation
> >> > and
> >> > related classes, such as JNDI resource names (e.g., for a JDBC
> >> > DataSource),
> >> > login credentials, configuration settings, etc., and that this
> >> > information
> >> > is recorded in the web.xml file.  How do you get that information into
> >> > the
> >> > ODataServiceFactory?  There don't seem to be any "hooks."  It takes a
> >> > ODataContext parameter, but I don't know what that is or how I can
> >> > control
> >> > its value at all.
> >> >
> >> > Thanks,
> >> > David
> >
> >
>

Re: Olingo Java v2 : how to inject context info into servlet application

Posted by Michael <mi...@apache.org>.
Hi David,

based on the experience in Olingo Java V2 the approach to create an
OData service has changed for Olingo Java V4.
Although it is now necessary to implement your own e.g. "HttpServlet",
however the Olingo library provide more support to create just the
parts which you need for your own service.

As example you can take a look into
"org.apache.olingo.server.tecsvc.TechnicalServlet" in the
"server-tecsvc" module.
This sample service servlet overrides the "service()" method in which
the own "*Processor" and "EdmProvider" are created and then from
Apache Olingo the according OData service and OData handler are used
to further process the request base on OData specification.

{code snippet}
     OData odata = OData.newInstance();
      Edm edm = odata.createEdm(new EdmTechProvider());
      ODataHttpHandler handler = odata.createHandler(edm);
      handler.register(new TechnicalProcessor(dataProvider));
      handler.process(req, resp);
{code snippet}

Kind regards,
Michael


On Mon, Oct 6, 2014 at 1:08 PM, David Ventimiglia <dv...@gmail.com> wrote:
> Hi Michael,
>
> That's good advice.  Thank you.  Are things any different in Olingo Java v4?
>
> Best regards,
> David
>
> On Mon, Oct 6, 2014 at 12:17 AM, Michael <mi...@apache.org> wrote:
>>
>> Hi David,
>>
>> unfortunately there is now supported way to pass init parameters from
>> the "web.xml" into the ODataServlet or ODataServiceFactory.
>> Either you read your additional configuration during the
>> initialization of your ODataServiceFactory implementation (e.g. in
>> "createService()") or your have to implement your own version of an
>> ODataServlet (which is not recommended).
>>
>> IMHO in my project I would create an additional "ConfigService" as
>> singleton which a) read all necessary configurations once from a
>> "Properties" file and b) then is called from my ODataServiceFactory
>> implementation.
>>
>> Kind regards,
>> Michael
>>
>> On Mon, Oct 6, 2014 at 7:40 AM, David Ventimiglia <dv...@gmail.com>
>> wrote:
>> > Hi,
>> >
>> > I'm using the ODataServlet.  As far as I can tell, the only interaction
>> > that
>> > users of this class have with the rest of their Olingo application
>> > components--which comprise the ODataServiceFactory, EdmProvider, and
>> > ODataSingleProcessor implementations--is that setting the
>> > ODataServiceFactory.FACTORY_LABEL init parameter for the servlet in the
>> > web.xml is the way that you tell the servlet to use a particular
>> > ODataServiceFactory.  Suppose you have other configuration or context
>> > information you want to get into the ODataServiceFactory implementation
>> > and
>> > related classes, such as JNDI resource names (e.g., for a JDBC
>> > DataSource),
>> > login credentials, configuration settings, etc., and that this
>> > information
>> > is recorded in the web.xml file.  How do you get that information into
>> > the
>> > ODataServiceFactory?  There don't seem to be any "hooks."  It takes a
>> > ODataContext parameter, but I don't know what that is or how I can
>> > control
>> > its value at all.
>> >
>> > Thanks,
>> > David
>
>

Re: Olingo Java v2 : how to inject context info into servlet application

Posted by David Ventimiglia <dv...@gmail.com>.
Hi Michael,

That's good advice.  Thank you.  Are things any different in Olingo Java
v4?

Best regards,
David

On Mon, Oct 6, 2014 at 12:17 AM, Michael <mi...@apache.org> wrote:

> Hi David,
>
> unfortunately there is now supported way to pass init parameters from
> the "web.xml" into the ODataServlet or ODataServiceFactory.
> Either you read your additional configuration during the
> initialization of your ODataServiceFactory implementation (e.g. in
> "createService()") or your have to implement your own version of an
> ODataServlet (which is not recommended).
>
> IMHO in my project I would create an additional "ConfigService" as
> singleton which a) read all necessary configurations once from a
> "Properties" file and b) then is called from my ODataServiceFactory
> implementation.
>
> Kind regards,
> Michael
>
> On Mon, Oct 6, 2014 at 7:40 AM, David Ventimiglia <dv...@gmail.com>
> wrote:
> > Hi,
> >
> > I'm using the ODataServlet.  As far as I can tell, the only interaction
> that
> > users of this class have with the rest of their Olingo application
> > components--which comprise the ODataServiceFactory, EdmProvider, and
> > ODataSingleProcessor implementations--is that setting the
> > ODataServiceFactory.FACTORY_LABEL init parameter for the servlet in the
> > web.xml is the way that you tell the servlet to use a particular
> > ODataServiceFactory.  Suppose you have other configuration or context
> > information you want to get into the ODataServiceFactory implementation
> and
> > related classes, such as JNDI resource names (e.g., for a JDBC
> DataSource),
> > login credentials, configuration settings, etc., and that this
> information
> > is recorded in the web.xml file.  How do you get that information into
> the
> > ODataServiceFactory?  There don't seem to be any "hooks."  It takes a
> > ODataContext parameter, but I don't know what that is or how I can
> control
> > its value at all.
> >
> > Thanks,
> > David
>

Re: Olingo Java v2 : how to inject context info into servlet application

Posted by Michael <mi...@apache.org>.
Hi David,

unfortunately there is now supported way to pass init parameters from
the "web.xml" into the ODataServlet or ODataServiceFactory.
Either you read your additional configuration during the
initialization of your ODataServiceFactory implementation (e.g. in
"createService()") or your have to implement your own version of an
ODataServlet (which is not recommended).

IMHO in my project I would create an additional "ConfigService" as
singleton which a) read all necessary configurations once from a
"Properties" file and b) then is called from my ODataServiceFactory
implementation.

Kind regards,
Michael

On Mon, Oct 6, 2014 at 7:40 AM, David Ventimiglia <dv...@gmail.com> wrote:
> Hi,
>
> I'm using the ODataServlet.  As far as I can tell, the only interaction that
> users of this class have with the rest of their Olingo application
> components--which comprise the ODataServiceFactory, EdmProvider, and
> ODataSingleProcessor implementations--is that setting the
> ODataServiceFactory.FACTORY_LABEL init parameter for the servlet in the
> web.xml is the way that you tell the servlet to use a particular
> ODataServiceFactory.  Suppose you have other configuration or context
> information you want to get into the ODataServiceFactory implementation and
> related classes, such as JNDI resource names (e.g., for a JDBC DataSource),
> login credentials, configuration settings, etc., and that this information
> is recorded in the web.xml file.  How do you get that information into the
> ODataServiceFactory?  There don't seem to be any "hooks."  It takes a
> ODataContext parameter, but I don't know what that is or how I can control
> its value at all.
>
> Thanks,
> David