Why doesn't this REST service work?

One Star

Why doesn't this REST service work?

Trying to create a proof-of-concept REST service bundle.
It compiles fine.
Karaf starts the bundle with no errors.
But when I go the the URL where it should be, I get no response, and no errors in the log. Nothing.
here's the Interface:
@Path("greeter")
public interface Greeter {

@GET
@Path("greet/{name}")
@Produces(MediaType.TEXT_PLAIN)
public String greeter(@PathParam("name") String name);

}

The implementation:
public class GreeterImpl implements Greeter {

public String greeter(String name) {
return "hello "+name;
}

}

The bundle activator:
public class Activator implements BundleActivator {
private ServiceRegistration registration;
public void start(BundleContext bc) throws Exception {
Dictionary props = new Hashtable();
props.put("service.exported.interfaces", "*");
props.put("service.exported.configs", "org.apache.cxf.rs");
props.put("service.exported.intents", "HTTP");
props.put("org.apache.cxf.rs.address", "http://0.0.0.0:9118/");

registration = bc.registerService(Greeter.class.getName(), new GreeterImpl(), props);

System.out.println("CXF REST Test: http://0.0.0.0:9118/");
}
public void stop(BundleContext bc) throws Exception {
registration.unregister();
}

}

When I go to this URL:
http://localhost:9118/greeter/greet/miles
I get nothing. This is in Talend ESB 5.2.2. What am I doing wrong?
Employee

Re: Why doesn't this REST service work?

Hi - I think you are going the DOSGi path and we do not support it in ESB AFAIK.
Please have a look at /examples/cxf/jaxrs-intro/services, check how Blueprint context (in resources/OSGI_INF) can be used to activate an endpoint.
One Star

Re: Why doesn't this REST service work?

Thank you for you help sberyozkin, yes, I was using a DOSGi example from the web.
Basically, I'm trying to build some services using JAX annotation and no configuration files, like I can do on TomEE.
So I looked up the example you mentioned and made these changes to my Greeter service:
1. Removed the Activator class.
2. copied the service.xml file from example to my src/main/java/resources/OSGI-INF/blueprint directory in my Maven project, with the changes below.
3. removed reference to bundle activator in my pom.xml file.
src/main/java/resources/OSGI-INF/blueprint/service.xml:
     <jaxrs:server id="greeterService" address="/cxf">
<jaxrs:serviceBeans>
<ref component-id="greeterBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="greeterBean" class="com.cn.dsa.greet.GreeterImpl"/>

The builds with no errors, and karaf launches it with no errors.
But again, there is no service at the URL.
I've tried:
http://localhost:8040/services/cxf/greeter/greet/miles
and
http://localhost:8040/cxf/greeter/greet/miles

If I go here:
http://localhost:8040/services/
it says "No services have been found" so are there a few more things I need to do?
One Star

Re: Why doesn't this REST service work?

I have the service working now with blueprint.
The problem was that the @Path attribute value must start with a slash. That was it.
@Path("/greeter")
public interface Greeter {

@GET
@Path("greet/{name}")
@Produces(MediaType.TEXT_PLAIN)
public String greeter(@PathParam("name") String name);

}

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Talend API Designer – Technical Overview

Take a look at this technical overview video of Talend API Designer

Watch Now

Getting Started with APIs

Find out how to get started with APIs

Read