1
votes

I am new to cxf and camel and I am running into some issues when trying to use JacksonJsonProvider.

I am trying to define a cxf service endpoint which consumes a json object and sends the request to a camel route. The camel route is not important for my issue.

In my blueprint.xml file I have defined a bean for JacksonJsonProvider:

<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>

When I try to install my feature in karaf I receive the following error:

BlueprintContainerImpl | ?
? | 21 - org.apache.aries.blueprint.core - 1.4.2 | Unable to start blueprint container for bundle test-mgw-api org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to load class org.codehaus.jackson.jaxrs.JacksonJsonProvider from recipe BeanRecipe[name='jsonProvider']

I have already added the correct dependency to my pom.xml

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-jaxrs</artifactId>
        <version>1.9.13</version>
    </dependency>

There must be something simple I am missing here, but I have spend many hours to figure it out now and I am getting nowhere. Does anybody know what I am doing wrong here?

I have provided my code below here.

Service interface:

@Path("/auth/")
public interface AuthService {

    @POST
    @Path("/login")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    Response login(LoginRequest loginRequest);

    @GET
    @Path("/person/get/{id}/")
    @Produces("application/xml")
    Response getPerson(@PathParam("id") String id);

    @DELETE
    @Path("/person/delete/{id}")
    void deletePerson(@PathParam("id") String id);
}

Request model:

@XmlRootElement(name="Login")
public class LoginRequest {
    private String username;
    private String password;
    private int loginType;

    public LoginRequest(String username, String password) {
        this.username = username;
        this.password = password;
        this.loginType = 1;
    }

    public LoginRequest() {
    }
}

Blueprint.xml

<blueprint
        xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
        xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
        xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
        xsi:schemaLocation="
        http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

        <cm:property-placeholder persistent-id="test.mgw.cxf.receive" update-strategy="reload">
            <cm:default-properties>
                <cm:property name="CXFserver" value="http://localhost:8989/"/>
                <cm:property name="service" value="rest" />
            </cm:default-properties>
        </cm:property-placeholder>

        <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>

    <cxf:rsServer id="rsServer" address="${CXFserver}${service}"
                  serviceClass="test.mgw.api.AuthService"
                  loggingFeatureEnabled="true" loggingSizeLimit="20">
        <cxf:providers>
            <ref component-id="jsonProvider"/>
        </cxf:providers>
    </cxf:rsServer>
</blueprint>
1
Did you declare camel-cxf dependencies in your pom.xml? I am not sure it is 100% necessary but in our environment it is needed to bridge the Jackson Jax-RS with Camel.рüффп
Did you install the jackson dependency in Karaf as well? And not just your bundle.Souciance Eqdam Rashti
@ruffp I do also have <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cxf</artifactId> </dependency> in my pom.xmlRingbo
@SoucianceEqdamRashti I tried installing osgi bundles in karaf using install mvn:org.codehaus.jackson/jackson-core-asl/1.9.13 install mvn:org.codehaus.jackson/jackson-jaxrs/1.9.13 install mvn:org.codehaus.jackson/jackson-mapper-asl/1.9.13 I also started the bundles, but it still does not work. I get the same error.Ringbo
@Ringbo and the feature camel-cxf is also deployed in the OSGI as 'Souciance' said? I notice we also have a feature camel-jackson in our environment.рüффп

1 Answers

0
votes

You should change in the blueprint the tag to jaxrs like this:

<jaxrs:server id="endpoint1">
    <jaxrs:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
    </jaxrs:providers>
</jaxrs:server>