...
A resource class is a Java Class annotated with JAX-RS annotations to represent a Web resource. A typical resource class in JAX-RS looks like this below:
Code Block | ||||
---|---|---|---|---|
| ||||
package demo.jaxrs.server; import java.util.HashMap; import java.util.Map; import javax.ws.rs.GET; import javax.ws.rs.ProduceMime; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @Path("/customerservice/") @ProduceMime("application/xml") public class CustomerService { public CustomerService() { } @GET public Customers getCustomers() { ...... } @GET @Path("/customers/{id}") @ProduceMime("application/json") public Customer getCustomer(@PathParam("id") String id) { ...... } @PUT @Path("/customers/{id}") @ConsumeMime("application/xml") public Response updateCustomer(@PathParam("id") Long id, Customer customer) { ...... } @POST @Path("/customers") public Response addCustomer(Customer customer) { ...... } @DELETE @Path("/customers/{id}/") public Response deleteCustomer(@PathParam("id") String id) { ...... } @Path("/orders/{orderId}/") public Order getOrder(@PathParam("orderId") String orderId) { ...... } } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- JAX-RS --> <jaxrs:server id="customerService" address="/"> <jaxrs:serviceBeans> <ref bean="customerService" /> </jaxrs:serviceBeans> </jaxrs:server> <!-- JAX-WS --> <jaxws:endpoint implementor="#customerService" address="/CustomerWorld" wsdlLocation="..."/> <bean id="customerService" class="demo.jaxrs.server.CustomerService" /> </beans> |
If demo.jaxrs.server.CustomerService was used to serve SOAP requests then either Either contract-first or Java-first could've been usedapproach can be used for JAX-WS. JAX-RS annotations can be added to the existing service class. Some custome custom providers may need to be created, depending on the complexity of the method signatures.
When a WSDL-first approach is used then a document-literal-wrapped style may or may not be z a good fit as the code generator unwraps all the types into a signature, for example :
...