2
votes

I tried to develop a rest service and expose the same via Apache Camel's CXFRS. I followed all the steps given in http://camel.apache.org/cxfrs.html and also referred to many samples given. I already referred to the question Can't find the the request for url Observer, but in my case it is a simple rest request. Below are the Service class, Route class, and cxf context used:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"  xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"

   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring
   http://camel.apache.org/schema/spring/camel-spring.xsd
   http://camel.apache.org/schema/cxf
   http://camel.apache.org/schema/cxf/camel-cxf.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://cxf.apache.org/jaxrs
   http://cxf.apache.org/schemas/jaxrs.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<context:annotation-config />

<!-- enable Spring @Component scan -->
<context:component-scan base-package="org.camelsample.rest" />

<cxf:rsServer id="rsServer" address="/rest"
    serviceClass="org.camelsample.rest.service.SampleRestService"
    loggingFeatureEnabled="true" loggingSizeLimit="20">
    <cxf:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
    </cxf:providers>
</cxf:rsServer>

<camel:camelContext id="samplerestservice"
    xmlns="http://camel.apache.org/schema/spring">
    <contextScan />
    <jmxAgent id="agent" createConnector="true" />
</camel:camelContext>

</beans>

The Service Class:

package org.camelsample.rest.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

public class SampleRestService {

    @GET
    @Path("/")
    public String sampleService() {
      return null;
    }
}

The Route Class:

package org.camelsample.rest.route;

import org.apache.camel.spring.SpringRouteBuilder;

public class SampleRestRoute extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {
        // TODO Auto-generated method stub
        from("cxfrs:bean:rsServer").log("Into Sample   Route").setBody(constant("Success"));
    }
}

But when I try to hit and test using http://localhost:8080/rest, I always get the following error message:

2015-05-29 13:38:37.920  WARN 6744 --- [nio-8080-exec-2] o.a.c.t.servlet.ServletController        : Can't find the the request for http://localhost:8080/favicon.ico's Observer 
2015-05-29 13:38:40.295  WARN 6744 --- [nio-8080-exec-3] o.a.c.t.servlet.ServletController        : Can't find the the request for http://localhost:8080/rest's Observer 

Am using Spring boot to test the rest sample.

1

1 Answers

1
votes

Does it work with this URL instead ?

http://localhost:8181/cxf/rest

If you just use address="/rest" as your address then you will probably get the default Jetty port 8181 and default CXF servlet path /cxf as the base URL.

If you specifically want to use the URL you have given then try this instead:

address="http://0.0.0.0:8080/rest"