Hi
I'm actually not sure why it works in the standalone mode :-) You set the
resource class be the interface
and not the actual class but the actual implementation is availbale from the resource provider. I think the reason it works is that
at the introspection stage it's not checked whether the class is the interface or not and thus the @Path annotation availbale at the
interface level is found.
Now the reason ot does not work with Spring being involved is that
sf.setResourceClasses(ApplicationConfigurationService.class);
not called and annotations are checked starting from the actual implementation
class.
Annotations can actually be inherited from the interface but not those which
target the interface itself, only those which
target the (interface) methods. I think this is what JAX-RS 0.7 spec actually says. CXF can inherit the annotations applied to the
subclass class though as there's no ambiguity there (as opposed to the possibility of multiple interfaces haveing different Path
annotations). Still, I'll ask for some clarifications on the JAX-RS users list...
So, you just need to have a @Path("applicationConfiguration") annotation be rooted at the ApplicationConfigurationServiceImpl. In
your ApplicationConfigurationServiceImpl you can also drop all method level annotation like @Path/@GET because those will be
inherited from the interface, except for those which apply to actual parameters like @PathParam - I'll need to clarify if those can
be inherited as well.
Cheers, Sergey
As requested by Sergey (this works fine when run through the standalone
server - see main method - but fails when configured through Spring):
import javax.jws.WebService;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
@WebService(endpointInterface = "ApplicationConfigurationService")
public class ApplicationConfigurationServiceImpl
implements ApplicationConfigurationService
{
protected final Log logger =
LogFactory.getLog(this.getClass().getName());
@POST
@Path("/push/")
public Response addApplicationConfiguration(ApplicationConfiguration
ac)
{
logger.info("ApplicationConfiguration: "+ac);
return Response.ok(ac).build();
}
@POST
@Path("/push/")
public Response updateApplicationConfiguration(ApplicationConfiguration
ac)
{
logger.info("ApplicationConfiguration: "+ac);
return Response.ok(ac).build();
}
@GET
@Path("/get/{id}/")
public Response getApplicationConfiguration(@PathParam("id") String id)
{
logger.info("id: "+id);
ApplicationConfiguration ac = new ApplicationConfiguration();
ac.setId(id);
ac.setName("test");
return Response.ok(ac).build();
}
/**
* Set up the server to allow testing.
*/
public static final void main(String[] argv)
{
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(ApplicationConfigurationService.class);
sf.setResourceProvider(ApplicationConfigurationService.class,
new SingletonResourceProvider(new
ApplicationConfigurationServiceImpl()));
sf.setAddress("http://localhost:9000/");
Server svr = sf.create();
System.out.println("Server started");
}
}
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import javax.jws.WebService;
@Path("/applicationConfiguration/")
@WebService
public interface ApplicationConfigurationService
{
/**
* Add an application configuration.
*/
@POST
@Path("/push/")
Response addApplicationConfiguration(ApplicationConfiguration ac);
/**
* Update an application configuration.
*/
@PUT
@Path("/push/{id}/")
Response updateApplicationConfiguration(ApplicationConfiguration ac);
/**
* Retrieve an application configuration by id.
*/
@GET
@Path("/get/{id}/")
Response getApplicationConfiguration(@PathParam("id") String id);
}
John Baker
--
Web SSO
IT Infrastructure
Deutsche Bank London
URL: http://websso.cto.gt.intranet.db.com
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland