Hi

On 25/10/11 14:30, Marcin Cylke wrote:
Hi

I've been playing lately with REST services. I've created my service
with Apache CXF and deploy it to OSGI container - which is Apache
Servicemix 4.

I've managed to get it to work, but encountered a couple of caveats:

the first attempt to deploy the JaxRS server in Servicemix was to use
bundle Activator. Despite the fact that the class of the Activator is
being run, the server does not start. I suspect my configuration is
wrong. These are the contents of Activator class:

#v+
public void start(BundleContext context) throws Exception {
System.out.println("TEST");
Dictionary restProps = new Hashtable();

restProps.put("service.exported.interfaces", "*");
restProps.put("service.exported.configs", "org.apache.cxf.rs");
restProps.put("service.exported.intents", "HTTP");
restProps.put("org.apache.cxf.rs.provider",
MessageWriterProvider.class.getName());
restProps.put("org.apache.cxf.rs.address", "http://localhost:8080/";);
context.registerService(MyService.class.getName(), new MyServiceImpl(),
restProps);
}

This is the way services can be deployed in DOSGI CXF, in other cases just use JAXRSServerFactoryBean or attach a context to OSGI HTTP Service (see a patch at https://issues.apache.org/jira/browse/CXF-3859 how to get hold of HTTPService correctly), ServiceMix also has a demo showing how Spring can be used to deploy the endpoint.



#v-

The second problem was with REST annotations. I needed to add REST
annotations both on MyServiceImpl and on MyService (interface).

Explanation for this - it was needed on because:

MyServiceImpl - becasue deployed project would not execute all methods -
only the first one in the given class
MyService - because I was unable to create a client instance for this WS
Actually I've seen in CXF tests that there is no interface-implementing
class example. Generally annotations are put on simple POJO methods and
Client class is declared programaticly, but this seems tedious and
repetitive.

What's more, despite the fact, that the service is deployable and is
working correctly my tests won't pass and I can't think of a reason for
this. Perhaps someone could have a quick look.
I've put all the code on github:
https://github.com/zygm0nt/cxf-playground in case anyone would be
interested to look into this issues.

I'm not sure why you decided to annotate both interface and implementation, having them on the interface only should do - but the annotations look fine to me

Cheers, Sergey


Please bear in mind, I haven't used CXF much before, so theses may be
some simple problems, but searching google didn't give a definitive
answers on them.

Marcin

Reply via email to