Sergey, Thanks, copying the @Path annotation into the implementation fixed the problem. Also, you're right, @GET etc. are inherited, but the @PathParam are not.
John Baker -- Web SSO IT Infrastructure Deutsche Bank London URL: http://websso.cto.gt.intranet.db.com "Sergey Beryozkin" <[EMAIL PROTECTED]> 30/04/2008 10:51 Please respond to [email protected] To <[email protected]> cc <[email protected]> Subject Re: CXF 2.1, Rest and Spring configuration 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 --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
