0

Technologies used:

  • Karaf
  • Blueprint (Aries implementation)
  • CXF-RS (rsServer rsClient)
  • Camel
  • Jackson

Issue: All of my Jackson annotations are ignored. This causes all methods to be executed in every class that gets serialized.

When working with OSGi in Java, it seems there are three places where declarations come into play regarding dependencies:

  • The dependencies are declared for compiler (for maven, the pom.xml)
  • The dependencies are declared for the OSGi bundle (in the MANIFEST.MF. For maven, this can be generated with Import-Package and Export-Package and Require-Bundle, but don't know how to find out the names of these)
  • The dependencies are declared for the OSGI container operation (for Karaf, features.xml). These must correspond to the MANIFEST.MF.

I probably made a mistake somewhere and two classes are reading the JSON annotations. Any insights?

Relevant pom.xml snippet

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-rs-extension-providers</artifactId>
            <version>3.2.1</version>
        </dependency>

        <!-- Adds Jackson JSON Provider to JAX-RS -->
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>2.9.8</version>
        </dependency>

Relevant features.xml snippet

 <feature version="${jackson.version}">jackson-core</feature>
 <feature version="${jackson.version}">jackson-annotations</feature>

OSGi imports

<Import-Package>
  org.apache.cxf.*,

  <!--org.apache.camel.component.blueprint,-->
  org.apache.camel,
  org.apache.camel.component.cxf,
  <!--org.apache.camel.component.jackson,-->
  org.apache.camel.component.http4,
  <!--org.apache.camel.jaxb,-->
  <!--org.apache.camel.component.jsch,-->
  javax.ws.rs;version="0";resolution:=optional,
  javax.xml.bind.*, 
  com.fasterxml.jackson.jaxrs.json;resolution:=optional,
  com.fasterxml.jackson.jaxrs.annotation,
  com.fasterxml.jackson.jaxrs.base,
</Import-Package>

(rs)Server Implementation in Blueprint

<!-- JAXRS providers -->
<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
<!--<bean id="xmlProvider" class="com.fasterxml.jackson.jaxrs.xml.JacksonJaxbXMLProvider"/>-->
<!--<bean id="jaxbjsonProvider" class="com.fasterxml.jackson.jaxrs.xml.JacksonJaxbJsonProvider" />-->

<!-- CXF Core Bus conveniently called "jaxrs" so that we can bind the jsonProvider to it for all traffic -->
<cxfcore:bus id="jaxrs" bus="jaxrs">
    <!--<cxfcore:properties>
        <entry key="skip.default.json.provider.registration" value="true"/>
    </cxfcore:properties>-->
</cxfcore:bus>

<!-- CXF REST Server using rsServer element -->
<cxf:rsServer id="cxfConsumer" address="/mcs-connect" serviceClass="at.ac.uibk.mcsconnect.api.IMcsService" loggingFeatureEnabled="true" bus="jaxrs">
    <cxf:providers>
        <ref component-id="jsonProvider"/>
        <!--<ref component-id="xmlProvider"/>-->
        <!--<ref component-id="jaxbjsonProvider"/>-->
   </cxf:providers>
</cxf:rsServer>
Jonathan Komar
  • 2,678
  • 4
  • 32
  • 43

1 Answers1

0

I cannot see the relevant code/blueprint that actually publishes the server but to use CXF+Jackson I usually import the org.apache.cxf.jaxrs.provider.* package and put the following configuration in blueprint file:

<jaxrs:server id="your.server.name" address="/template">
    <jaxrs:serviceBeans>
        <ref component-id="your.server.impl" />
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <ref component-id="jsonProvider" />
    </jaxrs:providers>
</jaxrs:server>

<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
matteo rulli
  • 1,443
  • 2
  • 18
  • 30