You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Svetlin Zarev <sv...@gmail.com> on 2016/06/27 12:19:05 UTC

TomEE default service providers

Hello,



Let’s assume that I have an object: org.example.ExampleObject and a service
provider: org.example.ExampleObjectProvider

The service provider has a service-jar.xml:



<ServiceJar>
    <ServiceProvider id=
*"Default ExampleObject Provider"                      *service=
*"Resource"                      *types=
*"org.example.ExampleObject"                      *class-name=
*"org.example.ExampleObjectProvider"                      *factory-name=
*"provide"                      *constructor=*"ServiceId"*>
    </ServiceProvider>
</ServiceJar>



Can I register that service provider to be the *default* service provider
for ExampleObject objects without having to declare every single
ExampleObject resource in tome.xml/resource.xml ? In other words – I want
it to behave exactly like the default service-providers (for instance like
the javax.sql.DataSource provider) declared in
org.apache.openejb/service-jar.xml.



Kind regards,

Svetlin

Re: TomEE default service providers

Posted by Romain Manni-Bucau <rm...@gmail.com>.
The only issue doing it I know - but can be fine for you - is you break in
embedded mode, ie you need to override few services like security service
and default datasources JdbcUrl if used to switch between openejb and
tomcat implementations depending tomcat part of tomee is in used or not.
This is not a hard code (check openejb.loader property basically) but some
additional noise if you want your solution to work in both modes.

In short: if you only use tomee no problem, if you also use openejb without
tomcat you can hit it.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-06-28 12:53 GMT+02:00 Svetlin Zarev <sv...@gmail.com>:

> > if you speak about the service-provider system property (
> > openejb.provider.default) to override defaults and service-jar.xml: it is
> > stable
> That's great.
>
> > if you speak about the class: internal (i'd like to kill it to bind it to
> > the container instance and not keep it global to be honest but never got
> > time and that's a serious change)
> It turns out that it can be done even without the observer and the
> ServiceUtils, as the SPs are registered even if there are no resources that
> use them, so I only need to change the system property.
>
>
> Thanks a lot Romain!
>
> Best regards,
> Svetlin
>

Re: TomEE default service providers

Posted by Svetlin Zarev <sv...@gmail.com>.
> if you speak about the service-provider system property (
> openejb.provider.default) to override defaults and service-jar.xml: it is
> stable
That's great.

> if you speak about the class: internal (i'd like to kill it to bind it to
> the container instance and not keep it global to be honest but never got
> time and that's a serious change)
It turns out that it can be done even without the observer and the
ServiceUtils, as the SPs are registered even if there are no resources that
use them, so I only need to change the system property.


Thanks a lot Romain!

Best regards,
Svetlin

Re: TomEE default service providers

Posted by Romain Manni-Bucau <rm...@gmail.com>.
2016-06-28 10:56 GMT+02:00 Svetlin Zarev <sv...@gmail.com>:

> Hi,
>
> >Oh I see, then Template can be set as a component using the fully
> qualified
> name:
>
> The Template API is very nice, but the AutoConfig deployer fails too early
> if it cannot find a service provider and hence the template is never
> invoked.
> But while digging through it, I found that AutoConfig::autoCreateResource
> looks for service provider by type and I was able to register a *default*
> SP
> during the AssemblerCreated event :). So at the end the observer approach
> seems to be the right one.
>
> I just wonder how stable is the ServiceUtils API ?
>
>
if you speak about the service-provider system property (
openejb.provider.default) to override defaults and service-jar.xml: it is
stable
if you speak about the class: internal (i'd like to kill it to bind it to
the container instance and not keep it global to be honest but never got
time and that's a serious change)


> Kind regards,
> Svetlin
>
> 2016-06-27 17:33 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> > 2016-06-27 16:23 GMT+02:00 Svetlin Zarev <
> svetlin.angelov.zarev@gmail.com
> > >:
> >
> > > HI,
> > >
> > > Are there any resources for the Template API ? I was not able to find
> > any.
> > >
> > >
> > Javadoc mainly:
> >
> >
> https://github.com/apache/tomee/blob/master/container/openejb-api/src/main/java/org/apache/openejb/api/resource/Template.java
> >
> > here is a sample
> >
> >
> https://github.com/apache/tomee/blob/master/container/openejb-core/src/test/java/org/apache/openejb/resource/TemplateTest.java#L54
> > and here how to configure it
> >
> >
> https://github.com/apache/tomee/blob/master/container/openejb-core/src/test/java/org/apache/openejb/resource/TemplateTest.java#L46
> >
> >
> > >
> > > > your custom tomee.xml you would write in this observer
> > > Generating a tomee.xml on the fly (or any other declaration of the
> > > resources) is not an option, because the resources are not known at
> that
> > > time.  I cannot know what resources they have declared in their
> > > web.xml/web-fragment.xmls or through annotations.
> > >
> > > Basically I need a mechanism to tell tomee to create a resource using a
> > > "default" object factory/service provider for every resource that does
> > not
> > > have an explicit one set.
> > >
> > >
> > Oh I see, then Template can be set as a component using the fully
> qualified
> > name:
> >
> > org.apache.openejb.api.resource.Template = com.foo.MyTemplate
> >
> > Note: it will also affects datasources, queues etc...
> >
> >
> > > Kind regards,
> > > Svetlin
> > >
> > >
> > >
> > > 2016-06-27 15:33 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:
> > >
> > > > Hi
> > > >
> > > > there are two things:
> > > >
> > > > 1. being able to inherit from default to auto configure a declared
> > object
> > > > (this is doable using plain new Template API or old service-provider)
> > > > 2. being able to declare on the fly resources (this requires you to
> > > write a
> > > > small openejb observer to add resources before they get created. this
> > can
> > > > be done observing AssemblerCreated event and overriding
> > openejb.conf.file
> > > > to point on your custom tomee.xml you would write in this observer,
> > > > alternative is to set system properties for resources using
> properties
> > > > syntax)
> > > >
> > > >
> > > >
> > > >
> > > > Romain Manni-Bucau
> > > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > > > <http://rmannibucau.wordpress.com> | Github <
> > > > https://github.com/rmannibucau> |
> > > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > > <http://www.tomitribe.com> | JavaEE Factory
> > > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > > >
> > > > 2016-06-27 14:19 GMT+02:00 Svetlin Zarev <
> > > svetlin.angelov.zarev@gmail.com
> > > > >:
> > > >
> > > > > Hello,
> > > > >
> > > > >
> > > > >
> > > > > Let’s assume that I have an object: org.example.ExampleObject and a
> > > > service
> > > > > provider: org.example.ExampleObjectProvider
> > > > >
> > > > > The service provider has a service-jar.xml:
> > > > >
> > > > >
> > > > >
> > > > > <ServiceJar>
> > > > >     <ServiceProvider id=
> > > > > *"Default ExampleObject Provider"                      *service=
> > > > > *"Resource"                      *types=
> > > > > *"org.example.ExampleObject"                      *class-name=
> > > > > *"org.example.ExampleObjectProvider"
> > > *factory-name=
> > > > > *"provide"                      *constructor=*"ServiceId"*>
> > > > >     </ServiceProvider>
> > > > > </ServiceJar>
> > > > >
> > > > >
> > > > >
> > > > > Can I register that service provider to be the *default* service
> > > provider
> > > > > for ExampleObject objects without having to declare every single
> > > > > ExampleObject resource in tome.xml/resource.xml ? In other words –
> I
> > > want
> > > > > it to behave exactly like the default service-providers (for
> instance
> > > > like
> > > > > the javax.sql.DataSource provider) declared in
> > > > > org.apache.openejb/service-jar.xml.
> > > > >
> > > > >
> > > > >
> > > > > Kind regards,
> > > > >
> > > > > Svetlin
> > > > >
> > > >
> > >
> >
>

Re: TomEE default service providers

Posted by Svetlin Zarev <sv...@gmail.com>.
Hi,

>Oh I see, then Template can be set as a component using the fully qualified
name:

The Template API is very nice, but the AutoConfig deployer fails too early
if it cannot find a service provider and hence the template is never
invoked.
But while digging through it, I found that AutoConfig::autoCreateResource
looks for service provider by type and I was able to register a *default*
SP
during the AssemblerCreated event :). So at the end the observer approach
seems to be the right one.

I just wonder how stable is the ServiceUtils API ?

Kind regards,
Svetlin

2016-06-27 17:33 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:

> 2016-06-27 16:23 GMT+02:00 Svetlin Zarev <svetlin.angelov.zarev@gmail.com
> >:
>
> > HI,
> >
> > Are there any resources for the Template API ? I was not able to find
> any.
> >
> >
> Javadoc mainly:
>
> https://github.com/apache/tomee/blob/master/container/openejb-api/src/main/java/org/apache/openejb/api/resource/Template.java
>
> here is a sample
>
> https://github.com/apache/tomee/blob/master/container/openejb-core/src/test/java/org/apache/openejb/resource/TemplateTest.java#L54
> and here how to configure it
>
> https://github.com/apache/tomee/blob/master/container/openejb-core/src/test/java/org/apache/openejb/resource/TemplateTest.java#L46
>
>
> >
> > > your custom tomee.xml you would write in this observer
> > Generating a tomee.xml on the fly (or any other declaration of the
> > resources) is not an option, because the resources are not known at that
> > time.  I cannot know what resources they have declared in their
> > web.xml/web-fragment.xmls or through annotations.
> >
> > Basically I need a mechanism to tell tomee to create a resource using a
> > "default" object factory/service provider for every resource that does
> not
> > have an explicit one set.
> >
> >
> Oh I see, then Template can be set as a component using the fully qualified
> name:
>
> org.apache.openejb.api.resource.Template = com.foo.MyTemplate
>
> Note: it will also affects datasources, queues etc...
>
>
> > Kind regards,
> > Svetlin
> >
> >
> >
> > 2016-06-27 15:33 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:
> >
> > > Hi
> > >
> > > there are two things:
> > >
> > > 1. being able to inherit from default to auto configure a declared
> object
> > > (this is doable using plain new Template API or old service-provider)
> > > 2. being able to declare on the fly resources (this requires you to
> > write a
> > > small openejb observer to add resources before they get created. this
> can
> > > be done observing AssemblerCreated event and overriding
> openejb.conf.file
> > > to point on your custom tomee.xml you would write in this observer,
> > > alternative is to set system properties for resources using properties
> > > syntax)
> > >
> > >
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > > <http://rmannibucau.wordpress.com> | Github <
> > > https://github.com/rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > <http://www.tomitribe.com> | JavaEE Factory
> > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > >
> > > 2016-06-27 14:19 GMT+02:00 Svetlin Zarev <
> > svetlin.angelov.zarev@gmail.com
> > > >:
> > >
> > > > Hello,
> > > >
> > > >
> > > >
> > > > Let’s assume that I have an object: org.example.ExampleObject and a
> > > service
> > > > provider: org.example.ExampleObjectProvider
> > > >
> > > > The service provider has a service-jar.xml:
> > > >
> > > >
> > > >
> > > > <ServiceJar>
> > > >     <ServiceProvider id=
> > > > *"Default ExampleObject Provider"                      *service=
> > > > *"Resource"                      *types=
> > > > *"org.example.ExampleObject"                      *class-name=
> > > > *"org.example.ExampleObjectProvider"
> > *factory-name=
> > > > *"provide"                      *constructor=*"ServiceId"*>
> > > >     </ServiceProvider>
> > > > </ServiceJar>
> > > >
> > > >
> > > >
> > > > Can I register that service provider to be the *default* service
> > provider
> > > > for ExampleObject objects without having to declare every single
> > > > ExampleObject resource in tome.xml/resource.xml ? In other words – I
> > want
> > > > it to behave exactly like the default service-providers (for instance
> > > like
> > > > the javax.sql.DataSource provider) declared in
> > > > org.apache.openejb/service-jar.xml.
> > > >
> > > >
> > > >
> > > > Kind regards,
> > > >
> > > > Svetlin
> > > >
> > >
> >
>

Re: TomEE default service providers

Posted by Romain Manni-Bucau <rm...@gmail.com>.
2016-06-27 16:23 GMT+02:00 Svetlin Zarev <sv...@gmail.com>:

> HI,
>
> Are there any resources for the Template API ? I was not able to find any.
>
>
Javadoc mainly:
https://github.com/apache/tomee/blob/master/container/openejb-api/src/main/java/org/apache/openejb/api/resource/Template.java

here is a sample
https://github.com/apache/tomee/blob/master/container/openejb-core/src/test/java/org/apache/openejb/resource/TemplateTest.java#L54
and here how to configure it
https://github.com/apache/tomee/blob/master/container/openejb-core/src/test/java/org/apache/openejb/resource/TemplateTest.java#L46


>
> > your custom tomee.xml you would write in this observer
> Generating a tomee.xml on the fly (or any other declaration of the
> resources) is not an option, because the resources are not known at that
> time.  I cannot know what resources they have declared in their
> web.xml/web-fragment.xmls or through annotations.
>
> Basically I need a mechanism to tell tomee to create a resource using a
> "default" object factory/service provider for every resource that does not
> have an explicit one set.
>
>
Oh I see, then Template can be set as a component using the fully qualified
name:

org.apache.openejb.api.resource.Template = com.foo.MyTemplate

Note: it will also affects datasources, queues etc...


> Kind regards,
> Svetlin
>
>
>
> 2016-06-27 15:33 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> > Hi
> >
> > there are two things:
> >
> > 1. being able to inherit from default to auto configure a declared object
> > (this is doable using plain new Template API or old service-provider)
> > 2. being able to declare on the fly resources (this requires you to
> write a
> > small openejb observer to add resources before they get created. this can
> > be done observing AssemblerCreated event and overriding openejb.conf.file
> > to point on your custom tomee.xml you would write in this observer,
> > alternative is to set system properties for resources using properties
> > syntax)
> >
> >
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > <http://rmannibucau.wordpress.com> | Github <
> > https://github.com/rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com> | JavaEE Factory
> > <https://javaeefactory-rmannibucau.rhcloud.com>
> >
> > 2016-06-27 14:19 GMT+02:00 Svetlin Zarev <
> svetlin.angelov.zarev@gmail.com
> > >:
> >
> > > Hello,
> > >
> > >
> > >
> > > Let’s assume that I have an object: org.example.ExampleObject and a
> > service
> > > provider: org.example.ExampleObjectProvider
> > >
> > > The service provider has a service-jar.xml:
> > >
> > >
> > >
> > > <ServiceJar>
> > >     <ServiceProvider id=
> > > *"Default ExampleObject Provider"                      *service=
> > > *"Resource"                      *types=
> > > *"org.example.ExampleObject"                      *class-name=
> > > *"org.example.ExampleObjectProvider"
> *factory-name=
> > > *"provide"                      *constructor=*"ServiceId"*>
> > >     </ServiceProvider>
> > > </ServiceJar>
> > >
> > >
> > >
> > > Can I register that service provider to be the *default* service
> provider
> > > for ExampleObject objects without having to declare every single
> > > ExampleObject resource in tome.xml/resource.xml ? In other words – I
> want
> > > it to behave exactly like the default service-providers (for instance
> > like
> > > the javax.sql.DataSource provider) declared in
> > > org.apache.openejb/service-jar.xml.
> > >
> > >
> > >
> > > Kind regards,
> > >
> > > Svetlin
> > >
> >
>

Re: TomEE default service providers

Posted by Svetlin Zarev <sv...@gmail.com>.
HI,

Are there any resources for the Template API ? I was not able to find any.


> your custom tomee.xml you would write in this observer
Generating a tomee.xml on the fly (or any other declaration of the
resources) is not an option, because the resources are not known at that
time.  I cannot know what resources they have declared in their
web.xml/web-fragment.xmls or through annotations.

Basically I need a mechanism to tell tomee to create a resource using a
"default" object factory/service provider for every resource that does not
have an explicit one set.

Kind regards,
Svetlin



2016-06-27 15:33 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:

> Hi
>
> there are two things:
>
> 1. being able to inherit from default to auto configure a declared object
> (this is doable using plain new Template API or old service-provider)
> 2. being able to declare on the fly resources (this requires you to write a
> small openejb observer to add resources before they get created. this can
> be done observing AssemblerCreated event and overriding openejb.conf.file
> to point on your custom tomee.xml you would write in this observer,
> alternative is to set system properties for resources using properties
> syntax)
>
>
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-06-27 14:19 GMT+02:00 Svetlin Zarev <svetlin.angelov.zarev@gmail.com
> >:
>
> > Hello,
> >
> >
> >
> > Let’s assume that I have an object: org.example.ExampleObject and a
> service
> > provider: org.example.ExampleObjectProvider
> >
> > The service provider has a service-jar.xml:
> >
> >
> >
> > <ServiceJar>
> >     <ServiceProvider id=
> > *"Default ExampleObject Provider"                      *service=
> > *"Resource"                      *types=
> > *"org.example.ExampleObject"                      *class-name=
> > *"org.example.ExampleObjectProvider"                      *factory-name=
> > *"provide"                      *constructor=*"ServiceId"*>
> >     </ServiceProvider>
> > </ServiceJar>
> >
> >
> >
> > Can I register that service provider to be the *default* service provider
> > for ExampleObject objects without having to declare every single
> > ExampleObject resource in tome.xml/resource.xml ? In other words – I want
> > it to behave exactly like the default service-providers (for instance
> like
> > the javax.sql.DataSource provider) declared in
> > org.apache.openejb/service-jar.xml.
> >
> >
> >
> > Kind regards,
> >
> > Svetlin
> >
>

Re: TomEE default service providers

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

there are two things:

1. being able to inherit from default to auto configure a declared object
(this is doable using plain new Template API or old service-provider)
2. being able to declare on the fly resources (this requires you to write a
small openejb observer to add resources before they get created. this can
be done observing AssemblerCreated event and overriding openejb.conf.file
to point on your custom tomee.xml you would write in this observer,
alternative is to set system properties for resources using properties
syntax)




Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-06-27 14:19 GMT+02:00 Svetlin Zarev <sv...@gmail.com>:

> Hello,
>
>
>
> Let’s assume that I have an object: org.example.ExampleObject and a service
> provider: org.example.ExampleObjectProvider
>
> The service provider has a service-jar.xml:
>
>
>
> <ServiceJar>
>     <ServiceProvider id=
> *"Default ExampleObject Provider"                      *service=
> *"Resource"                      *types=
> *"org.example.ExampleObject"                      *class-name=
> *"org.example.ExampleObjectProvider"                      *factory-name=
> *"provide"                      *constructor=*"ServiceId"*>
>     </ServiceProvider>
> </ServiceJar>
>
>
>
> Can I register that service provider to be the *default* service provider
> for ExampleObject objects without having to declare every single
> ExampleObject resource in tome.xml/resource.xml ? In other words – I want
> it to behave exactly like the default service-providers (for instance like
> the javax.sql.DataSource provider) declared in
> org.apache.openejb/service-jar.xml.
>
>
>
> Kind regards,
>
> Svetlin
>