use of com.wordnik.swagger.annotations.ApiResponse in project fabric8 by jboss-fuse.
the class CustomerService method updateCustomer.
/**
* 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.
* <p/>
* 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).
* <p/>
* 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.
*/
@PUT
@Path("/customers/")
@Consumes({ "application/xml", "application/json" })
@ApiOperation(value = "Update an existing Customer")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Invalid ID supplied"), @ApiResponse(code = 204, message = "Customer not found") })
public Response updateCustomer(@ApiParam(value = "Customer object that needs to be updated", required = true) Customer customer) {
LOG.info("Invoking updateCustomer, Customer name is: {}", customer.getName());
Customer c = customers.get(customer.getId());
Response r;
if (c != null) {
customers.put(customer.getId(), customer);
r = Response.ok().build();
} else {
r = Response.notModified().build();
}
return r;
}
use of com.wordnik.swagger.annotations.ApiResponse in project fabric8 by jboss-fuse.
the class CustomerService method deleteCustomer.
/**
* 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.
* <p/>
* 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.
*/
@DELETE
@Path("/customers/{id}/")
@ApiOperation(value = "Delete Customer")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Invalid ID supplied"), @ApiResponse(code = 204, message = "Customer not found") })
public Response deleteCustomer(@ApiParam(value = "ID of Customer to delete", required = true) @PathParam("id") String id) {
LOG.info("Invoking deleteCustomer, Customer id is: {}", id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
Response r;
if (c != null) {
r = Response.ok().build();
customers.remove(idNumber);
} else {
r = Response.notModified().build();
}
return r;
}
Aggregations