Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preferred Semantics for CXF JAX-RS

I was wondering what the preferred semantics are for jaxrs:server configurations in a CXF XML context file.

For example, if I have two service implementations for users and orders, and they're accessible from a relative path "/user" and "/order".

Would I configure the services this way:

<jaxrs:server id="userService" address="/user">
    <jaxrs:serviceBeans>
        <bean class="com.example.UserServiceImpl />
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
    </jaxrs:providers>
</jaxrs:server>

<jaxrs:server id="orderService" address="/order">
    <jaxrs:serviceBeans>
        <bean class="com.example.OrderServiceImpl />
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
    </jaxrs:providers>
</jaxrs:server>

Or this way:

<jaxrs:server id="appService" address="/">
    <jaxrs:serviceBeans>
        <!-- 
            Path configured using @Path annotations on the class definition:

            @Path(value="/user")
            public class UserServiceImpl {...}
        -->
        <bean class="com.example.UserServiceImpl />
        <bean class="com.example.OrderServiceImpl />
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
    </jaxrs:providers>
</jaxrs:server>

It seems like it's only a semantic difference. The second way allows us to not repeat the providers. But I was wondering what I should be considering when performing this configuration?

Thank you!

like image 590
Ivan Gozali Avatar asked Nov 23 '25 02:11

Ivan Gozali


1 Answers

I use the second way and try to group services together if they relate... if you can get orders for specific user, then they relate. So I usually have one "v1" api server (versioning support), one for documentation of it (there I use different providers or extension mappings), one for specialized (like admin with more strict security) access, etc. But i would use some address and not leave it empty, for example "api" or version "v1" at least.

In other way, your cxf.xml can be full of jaxrs servers. And if they relate, there is little chance that they will need different providers, mappings, extensions.

But this question is about opinion and perhaps will be closed.

like image 123
Zavael Avatar answered Nov 24 '25 14:11

Zavael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!