TomEE CXF configuration tip: link Services and Resources


TomEE CXF configuration is mainly done in openejb-jar.xml to either use qualified name or service id to reference to more complicated objects.

For instance you can reference jsonProvider in openejb-jar.xml and define it in resources.xml like it:

<Service id="jsonProvider" class-name="org.superbiz.MyJsonProvider">
  rootName = foo
</Service>

It is also possible to link two services together using $:

<Service id="jsonProvider" class-name="org.superbiz.MyJsonProvider">
  cache = $cacheService
</Service>
<Service id="cacheService" class-name="org.superbiz.MyCache">
  size = 1000
</Service>

Then the issue is when you want the same instance of a service referenced in two other ones:

<Service id="jsonProvider" class-name="org.superbiz.MyJsonProvider">
  cache = $cacheService
</Service>
<Service id="jaxbProvider" class-name="org.superbiz.MyJaxbProvider">
  cache = $cacheService
</Service>
<Service id="cacheService" class-name="org.superbiz.MyCache">
  size = 1000
</Service>

Here you’ll get two instances of the cacheService.

To avoid it you can either create a factory and handle a singleton or use a resource. If you write yourself the two providers no issue doing a lookup of the resource but if you don’t own the providers that’s harder (or you need to wrap it). To avoid it TomEE now allows you to reference using “@” a resource. So basically to share our cache across both providers we’ll just do:

<Service id="jsonProvider" class-name="org.superbiz.MyJsonProvider">
  cache = @cacheService
</Service>
<Service id="jaxbProvider" class-name="org.superbiz.MyJaxbProvider">
  cache = @cacheService
</Service>
<Resource id="cacheService" class-name="org.superbiz.MyCache">
  size = 1000
</Resource>
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s