org.fusesource.examples.cxf.jaxrs.security
Class CustomerService
java.lang.Object
org.fusesource.examples.cxf.jaxrs.security.CustomerService
public class CustomerService
- extends java.lang.Object
This Java class with be hosted in the URI path defined by the @Path annotation. @Path annotations on the methods
of this class always refer to a path relative to the path defined at the class level.
For example, with 'http://localhost:8181/cxf' as the default CXF servlet path and '/crm' as the JAX-RS server path,
this class will be hosted in 'http://localhost:8181/cxf/crm/customerservice'. An @Path("/customers") annotation on
one of the methods would result in 'http://localhost:8181/cxf/customerservice/customers'.
|
Method Summary |
javax.ws.rs.core.Response |
addCustomer(Customer customer)
Using HTTP POST, we can add a new customer to the system by uploading the XML representation for the customer. |
javax.ws.rs.core.Response |
deleteCustomer(java.lang.String id)
This method is mapped to an HTTP DELETE of 'http://localhost:8181/cxf/crm/customerservice/customers/{id}'. |
Customer |
getCustomer(java.lang.String id)
This method is mapped to an HTTP GET of 'http://localhost:8181/cxf/crm/customerservice/customers/{id}'. |
Order |
getOrder(java.lang.String orderId)
This method is mapped to an HTTP GET of 'http://localhost:8181/cxf/crm/customerservice/orders/{id}'. |
javax.ws.rs.core.Response |
updateCustomer(Customer customer)
Using HTTP PUT, we can can upload the XML representation of a customer object. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CustomerService
public CustomerService()
getCustomer
public Customer getCustomer(java.lang.String id)
- This method is mapped to an HTTP GET of 'http://localhost:8181/cxf/crm/customerservice/customers/{id}'. The value for
{id} will be passed to this message as a parameter, using the @PathParam annotation.
The method returns a Customer object - for creating the HTTP response, this object is marshaled into XML using JAXB.
For example: surfing to 'http://localhost:8181/cxf/crm/customerservice/customers/123' will show you the information of
customer 123 in XML format.
updateCustomer
public javax.ws.rs.core.Response updateCustomer(Customer customer)
- Using HTTP PUT, we can can upload the XML representation of a customer object. This operation will be mapped
to the method below and the XML representation will get unmarshaled into a real Customer object using JAXB.
The method itself just updates the customer object in our local data map and afterwards uses the Reponse class to
build the appropriate HTTP response: either OK if the update succeeded (translates to HTTP Status 200/OK) or not
modified if the method failed to update a customer object (translates to HTTP Status 304/Not Modified).
Note how this method is using the same @Path value as our next method - the HTTP method used will determine which
method is being invoked.
addCustomer
public javax.ws.rs.core.Response addCustomer(Customer customer)
- Using HTTP POST, we can add a new customer to the system by uploading the XML representation for the customer.
This operation will be mapped to the method below and the XML representation will get unmarshaled into a real
Customer object.
After the method has added the customer to the local data map, it will use the Response class to build the HTTP reponse,
sending back the inserted customer object together with a HTTP Status 200/OK. This allows us to send back the
new id for the customer object to the client application along with any other data that might have been updated in
the process.
Note how this method is using the same @Path value as our previous method - the HTTP method used will determine which
method is being invoked.
deleteCustomer
public javax.ws.rs.core.Response deleteCustomer(java.lang.String id)
- This method is mapped to an HTTP DELETE of 'http://localhost:8181/cxf/crm/customerservice/customers/{id}'. The value for
{id} will be passed to this message as a parameter, using the @PathParam annotation.
The method uses the Response class to create the HTTP response: either HTTP Status 200/OK if the customer object was
successfully removed from the local data map or a HTTP Status 304/Not Modified if it failed to remove the object.
getOrder
public Order getOrder(java.lang.String orderId)
- This method is mapped to an HTTP GET of 'http://localhost:8181/cxf/crm/customerservice/orders/{id}'. The value for
{id} will be passed to this message as a parameter, using the @PathParam annotation.
The method returns an Order object - the class for that object includes a few more JAX-RS annotations, allowing it to
display one of these two outputs, depending on the actual URI path being used:
- display the order information itself in XML format
- display details about a product in the order in XML format in a path relative to the URI defined here
Copyright © 2012 FuseSource. All Rights Reserved.