Search in sources :

Example 1 with ApiResponse

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;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(com.wordnik.swagger.annotations.ApiResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 2 with ApiResponse

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;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(com.wordnik.swagger.annotations.ApiResponse) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 ApiResponse (com.wordnik.swagger.annotations.ApiResponse)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 Path (javax.ws.rs.Path)2 Response (javax.ws.rs.core.Response)2 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 PUT (javax.ws.rs.PUT)1