Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
@Path("greeter")
public interface Greeter {
@GET
@Path("greet/{name}")
@Produces(MediaType.TEXT_PLAIN)
public String greeter(@PathParam("name") String name);
}
public class GreeterImpl implements Greeter {
public String greeter(String name) {
return "hello "+name;
}
}
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();
}
}
<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"/>
@Path("/greeter")
public interface Greeter {
@GET
@Path("greet/{name}")
@Produces(MediaType.TEXT_PLAIN)
public String greeter(@PathParam("name") String name);
}