Running the RESTful web service

In this section, we will run the root resource class. Invoke the URL http://localhost:8080/jboss-jaxrs/jaxrs/helloworld. The jboss-jaxrs is included in the URL as it is the context of the web application. The jaxrs is included to invoke the servlet com.sun.jersey.spi.container.servlet.ServletContainer. The /helloworld is the resource URI for the RESTful web service. We did not annotate any resource method or class method with @PATH; therefore, we won't invoke a specific method. The first resource method in the root resource class gets invoked. Make different resource methods as the first in the root resource class to test different MIME type outputs. If HTML output is required, make the getHTMLMessage method the first in the root resource class.

The HTML output in the browser is shown as follows:

Running the RESTful web service

If the getClichedMessage() resource method is made sequentially the first in the resource class, the text/plain representation gets displayed in the browser when the URL http://localhost:8080/jboss-jaxrs/jaxrs/helloworld is invoked as shown here:

Running the RESTful web service

If the getXMLMessage() resource method is made sequentially the first in the resource class, the XML representation gets displayed in the browser as shown here:

Running the RESTful web service

When a different method is invoked in the resource class after making a modification, the jboss-jaxrs application would need to be reinstalled. To reinstall, first the Maven project must be cleaned for which you need to right-click on pom.xml and select Run As | Maven clean. A BUILD SUCCESS message indicates that the files generated from the previous installation have been removed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset