Test CXF Restful Services with Rest-Shell @Put @Get

This short post publishes a Restful Web Service and then tests @Put and @Post methods using rest-shell.

Create the Service

Follow the instructions from my previous post: Produce Json From Restful CXF Web Service.
Once you have done this, modify the CustomerService as follows:

package com.skills421.services;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.springframework.stereotype.Service;

import com.skills421.model.Customer;

public class CustomerService
private Map<Integer,Customer> customers = new HashMap<Integer, Customer>();

public Response addCustomer(@PathParam("id") int id,Customer customer)
return Response.status(Status.OK).build();

public Response find(@PathParam("id") int id)
Customer customer = customers.get(id);

return Response.status(Status.OK).entity(customer).type(MediaType.APPLICATION_JSON).build();

public Response getDefault()
Customer customer = new Customer(1,"Jon Doe",21);

return Response.status(Status.OK).entity(customer).type(MediaType.APPLICATION_JSON).build();

This provides methods to Put and Get data.

Test the Service using Rest-Shell

Open a terminal window and enter the following:

baseUri http://localhost:8080/SimpleCXFRest/rest/customer
get default

This will display the following:


Now enter the following:

put add/1 --data "{id:1,name:"Mark Doe",age:21}"

This will put Mark Doe to our service and display the following:


Finally, let’s check to see if our data was successfully uploaded by entering the following:

get find/1

and now we can see the following:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s