HTTP GET Method Demonstration

This section gives the demonstration of the GET Method used in Hello World.

Step 1: Create EJB method for getCountries.

This method is used to get all the countries present in the system.

Note: Refer to the Sorting, Paging, Filtering, and Field section for the usage and description of Apicontext parameter.

  @Cursor(entityClass = CountryEntity.CLASSNAME, queryName = CountryEntity.GET_ALL_COUNTRIES)
  public PagingResult getCountries(PagingContext ctx)
	throws Exception {
	 EntityManagerWrapper qm = new EntityManagerWrapper(manager);
	 List countryEntities = qm.executeNamedQuery(
		CountryEntity.GET_ALL_COUNTRIES, ctx);
	 if (countryEntities == null)
		return null;
	 PagingResult countries = new PagingResult();
	 for (CountryEntity countryEntity : countryEntities) {
	return countries;


Step 2: RESTify EJB method for getCountries.

This step generates a corresponding REST method to get all the countries from the EJB.

The below Fig shows getCountries(...) method is selected to RESTify. Click "Next" to configure the DTO. Note: If you want to use Filtering/Sorting, support must be provided at the EJB layer.

The following screen shows Rest Method details. The Method Signature preview can be seen here. Click "Next".

Select the fields for the DTO by checking "Property Name" and Click "Configure".

After configuring the property, click Finish. You will be asked to proceed through the rest of the wizard.

Click "Finish" complete the wizard.

Click Finish on the main wizard if you do not wish to RESTify other methods. If you want to RESTify other methods, use the preceding steps.

REST Interface for GET Method

 @RBAC(type = { CRUDEnum.READ }, capability = { "HelloWorldCap" })
  "application/;version=1" })
  public getCountries(
  @Context UriContext param0);

REST Implementation for GET Method

public getCountries(
 UriContext param0) {
   * TODO: Put getCountrieslogic using
   * bean instance
  */ countries = null; ctx = param0.getPagingCtxt();
	try {
	countries = new;
	java.util.Collection restCountries = new java.util.ArrayList(); ejbCountryList = getBean()
	if (ejbCountryList == null) {
	   throw new WebApplicationException(Response.Status.NOT_FOUND);
	for ( country : ejbCountryList) { restCountry = new;
	   PropertyUtils.copyProperties(restCountry, country);

	} catch (Exception e) {
	  throw new WebApplicationException(e);
	} finally {
	  // TODO: Auto generated code

	return countries;

Step 3: Invoke REST API using REST Client.

You need to use REST Client to invoke REST API created in Step 2. Assuming that the application is already built and deployed on the Junos Space. For building and deploying application, please refer to the Building and Deploying HelloWorld section.

HTTP GET Request

GET api/space/hello-world/countries
HTTP/1.1 Host: <host-name>:<port>
Accept: application/;version=1

HTTP GET Response

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<countries uri="/hello-world/countries/" size="3">

<country uri="/hello-world/countries/3"> 

<country uri="/hello-world/countries/4"> 

<country uri="/hello-world/countries/5">