Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide

Similar documents
Red Hat JBoss Developer Studio 7.0 JBoss SOAP Web Services User Guide

JBoss SOAP Web Services User Guide. Version: M5

JBoss Developer Studio 6.0

JBoss Developer Studio 3.0

Red Hat JBoss Core Services Apache HTTP Server 2.4 Apache HTTP Server Installation Guide

Red Hat JBoss Developer Studio 4.1 Smooks Developer Tools Reference Guide

Red Hat Enterprise Linux OpenStack Platform 7 OpenStack Data Processing

JBoss Developer Studio 4.1

Red Hat Subscription Management All Subscription Docs Quick Registration for RHEL

Building and Using Web Services With JDeveloper 11g

Red Hat JBoss Developer Studio 7.0 User Guide

Business Process Management IBM Business Process Manager V7.5

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

NetBeans IDE Field Guide

Red Hat Customer Portal 1 Managing User Access to the Red Hat Customer Portal and the Red Hat Network Application

JBoss Developer Studio 3.0

Crystal Reports Installation Guide

Red Hat Directory Server 8.2 Using the Directory Server Console

TIBCO ActiveMatrix Service Bus Getting Started. Software Release 2.3 February 2010

Outlook Profile Setup Guide Exchange 2010 Quick Start and Detailed Instructions

Red Hat CloudForms 3.2 NetApp Storage Integration Guide

JBoss Developer Studio 3.0

Producing Standards Based Content with ToolBook

Oracle Service Bus Examples and Tutorials

Using EMC Documentum with Adobe LiveCycle ES

JBoss Enterprise SOA Platform 5 ESB Tools Reference Guide. This guide is for developers Edition 5.3.1

User Guide. Version 3.2. Copyright Snow Software AB. All rights reserved.

Orchestrating Document and Media Management using CMIS

Oracle WebLogic Portal

SDK Code Examples Version 2.4.2

Job Streaming User Guide

Creating Web Services Applications with IntelliJ IDEA

8x8 Virtual Office Telephony Interface for Salesforce

Enabling Kerberos SSO in IBM Cognos Express on Windows Server 2008

T320 E-business technologies: foundations and practice

Practice Fusion API Client Installation Guide for Windows

Red Hat Enterprise Virtualization 3.0 User Portal Guide. Accessing and Using Virtual Machines from the User Portal Edition 1

Red Hat Enterprise Linux OpenStack Platform 7 Back Up and Restore Red Hat Enterprise Linux OpenStack Platform

HDAccess Administrators User Manual. Help Desk Authority 9.0

Getting Started with Amazon EC2 Management in Eclipse

JBoss AS Administration Console User Guide. by Shelly McGowan and Ian Springer

NovaBACKUP xsp Version 12.2 Upgrade Guide

Community Edition. Master Data Management 3.X. Administrator Guide

Getting Started using the SQuirreL SQL Client

HANDS-ON PRACTICE: DEPLOY AN APPLICATION

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

Working with WebSphere 4.0

Glassfish, JAVA EE, Servlets, JSP, EJB

Creating a Web Service using IBM Rational HATS. For IBM System i (5250) Creating a Web Service using HATS 1

Publishing, Consuming, Deploying and Testing Web Services

Novell Access Manager

WA2087 Programming Java SOAP and REST Web Services - WebSphere 8.0 / RAD 8.0. Student Labs. Web Age Solutions Inc.

Exchange Outlook Profile/POP/IMAP/SMTP Setup Guide

To begin, visit this URL:

Using Microsoft Visual Studio API Reference

Red Hat Customer Portal Current Customer Portal Subscription Management

Red Hat Cloud Infrastructure 5 Release Notes

FileNet Business Activity Monitor (BAM) Release Notes

CA Nimsoft Service Desk

Application Servers - BEA WebLogic. Installing the Application Server

2) Sharing Projects Made easy by IntelliGantt s Share Wizard, there are three share options to fit the needs of your project.

Cloud Tools Reference Guide. Version: GA

Counter-Strike Game Server Management Module

SQL Server 2005: Report Builder

TIBCO Hawk SNMP Adapter Installation

Topics Included in This Current Release Information: Section

Fedora 19. Fedora Documentation Project

RoomWizard Synchronization Software Manual Installation Instructions

SC-T35/SC-T45/SC-T46/SC-T47 ViewSonic Device Manager User Guide

L01: Using the WebSphere Application Server Liberty Profile for lightweight, rapid development. Lab Exercise

TIBCO ActiveMatrix Service Grid WebApp Component Development. Software Release August 2012

APIS CARM NG Quick Start Guide for MS Windows

Sophos Mobile Control Installation guide. Product version: 3

EMC Documentum Composer

SOA Software: Troubleshooting Guide for Agents

Fuse ESB Enterprise 7.0 Installation Guide

Archive Attender Version 3.5

Policy Guide Access Manager 3.1 SP5 January 2013

McAfee Endpoint Encryption Reporting Tool

Red Hat Enterprise Linux 7 High Availability Add-On Administration. Configuring and Managing the High Availability Add-On

Training Manual. Version 6

XStream Remote Control: Configuring DCOM Connectivity

PLESK 7 NEW FEATURES HOW-TO RESOURCES

InfoView User s Guide. BusinessObjects Enterprise XI Release 2

BIGPOND ONLINE STORAGE USER GUIDE Issue August 2005

Install guide for Websphere 7.0

Installing and Configuring DB2 10, WebSphere Application Server v8 & Maximo Asset Management

1. Open Thunderbird. If the Import Wizard window opens, select Don t import anything and click Next and go to step 3.

TIBCO ActiveMatrix Management Agent for WCF Samples. Software Release July 2009

Avalanche Site Edition

StreamServe Persuasion SP5 Control Center

Setting up VMware ESXi for 2X VirtualDesktopServer Manual

UF Health SharePoint 2010 Introduction to Content Administration

Bitrix Site Manager 4.0. Quick Start Guide to Newsletters and Subscriptions

PTC Integrity Eclipse and IBM Rational Development Platform Guide

TIBCO ActiveMatrix BPM Web Application Component Development. Software Release 2.0 November 2012

Security Assertion Markup Language (SAML) Site Manager Setup

The cloud server setup program installs the cloud server application, Apache Tomcat, Java Runtime Environment, and PostgreSQL.

Installing a Browser Security Certificate for PowerChute Business Edition Agent

Transcription:

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Provides information relating to RESTful Web Services for JBoss. Denny Xu Grid Qian Brian Fitzpatrick Ben Clare

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Provides information relating to RESTful Web Services for JBoss. Denny Xu Grid Qian Brian Fitzpatrick Ben Clare Edited by Isaac Rooskov

Legal Notice Copyright 2011 Red Hat. T his document is licensed by Red Hat under the Creative Commons Attribution-ShareAlike 3.0 Unported License. If you distribute this document, or a modified version of it, you must provide attribution to Red Hat, Inc. and provide a link to the original. If the document is modified, all Red Hat trademarks must be removed. Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries. Linux is the registered trademark of Linus Torvalds in the United States and other countries. Java is a registered trademark of Oracle and/or its affiliates. XFS is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries. MySQL is a registered trademark of MySQL AB in the United States, the European Union and other countries. Node.js is an official trademark of Joyent. Red Hat Software Collections is not formally related to or endorsed by the official Joyent Node.js open source or commercial project. T he OpenStack Word Mark and OpenStack Logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community. All other trademarks are the property of their respective owners. Abstract The JBoss RESTful Web Services User Guide explains how to use RESTful Web Services to implement web services in Java.

Table of Contents Table of Contents. Preface........................................................................................... 3.. Chapter......... 1... JBoss....... REST...... ful... Web..... Services......... Runtime......... and..... T. ools..... support........ Overview...................... 4. 1.1. Key Features of JBoss RESTful Web Services 4. Chapter......... 2... Adding........ JAX-RS........ support........ to... a.. project................................................... 5. 2.1. Adding support to a new project 5 2.2. Adding support to an existing project 5. Chapter......... 3... Creating......... a.. Simple........ Web..... Service........................................................ 6. 3.1. Generation 6. Chapter......... 4.. Sample........ Web..... Service......... wizards......................................................... 11.. 4.1. Sample REST ful Web Service 16. Chapter......... 5... Working......... with..... REST..... ful.... web.... services.................................................... 21.. 5.1. Running REST methods on the server 22. Chapter......... 6... Web..... Service........ Test...... View........................................................... 24... 6.1. Preliminaries 26 6.2. Testing a RESTful Web Service 26 6.2.1. RestfulSample project 26 6.2.2. REST Easy sample project 27. Chapter......... 7... JAX-RS........ Validation....................................................................... 33... Getting........ Help..... and..... Giving....... Feedback................................................................. 34.. A.1. Do You Need Help? 34 A.2. Give us Feedback 34. Revision......... History................................................................................. 35.. 1

2 Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide

Preface Preface T his manual uses several conventions to highlight certain words and phrases and draw attention to specific pieces of information. T o get more information on these conventions please refer to the Docum ent Conventions manual, which can be found on the Red Hat Documentation website under the JBoss Developer Studio section. 3

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Chapter 1. JBoss RESTful Web Services Runtime and Tools support Overview JBoss RESTful Web Services is a framework developed as a part of the JBoss Application Server. It implements the JAX-RS specifications. JAX-RS (Java API for REST ful Web Services) is a Java API that supports the creation of Representational State T ransfer (REST) web services, using annotations. JBoss REST ful Web Services integrates with most current JBoss Application Server releases as well as earlier ones, that did implement the J2EE 1.4 specifications. REST ful Web Services tooling works with JBossWS Runtime and allows you to create, deploy and run REST ful Web Services Also JBossWS Tool gives a way to test a web service running on a server. 1.1. Key Features of JBoss RESTful Web Services T able 1.1. Key Functionality Feature JAX-RS support EJB 2.1, EJB3 and JSE endpoints JBoss AS Benefit JBossWS implements the JAX-RS specification. JBossWS supports EJB 2.1, EJB3 and JSE as Web Service Endpoints. JBoss Application Server 5 (JavaEE 5 compliant) web service stack. 4

Chapter 2. Adding JAX-RS support to a project Chapter 2. Adding JAX-RS support to a project 2.1. Adding support to a new project When creating a new Dynam ic Web Project, JAX-RS support can be enabled through the JAX-RS facet. T o enable the JAX-RS facet during project creation, click the Modify button in the Configuration section. Figure 2.1. Enabling JAX-RS configuration Navigate to Project Facets and click the checkbox next to the JAX-RS (REST Web Services) item. Click the OK button to save the settings and return to the Dynam ic Web Project creation wizard. Figure 2.2. Enabling JAX-RS configuration 2.2. Adding support to an existing project JAX-RS support can be added to any Java project. To add this support, right-click on a project in the Project Explorer to bring up the context menu and navigate to Configure Add JAX-RS 1.1 support. Figure 2.3. Adding JAX-RS support It is also possible to add RESTful web service support to a project by bringing up the context menu and navigating to Properties Project Facets. Here you can click the checkbox next to the JAX-RS (REST Web Services) item and click the OK button to save the settings, as you would when creating a new project. 5

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Chapter 3. Creating a Simple Web Service This chapter describes how to create a simple web service. You must have a previously created Dynam ic Web Project available in your workbench before create a simple web service. For information on how to create a Dynam ic Web Project see the Getting Started Guide for this release. 3.1. Generation A simple web service can be created by using the Simple Web Service wizard as described in Procedure 3.1, Generate a simple web service Procedure 3.1. Generate a simple web service 1. Access the New - Select a wizard dialog a. Right click on the project name in the Project Explorer view. b. Select New Other. c. Expand the Web Services folder and click on the Simple Web Service option. T he New - Select a wizard dialog displays with the selected wizard type highlighted. 6

Chapter 3. Creating a Simple Web Service Figure 3.1. The New - Other (Wizard selection) dialog 2. Access the Simple Web Service dialog Click the Next button to proceed. T he Sim ple Web Service - Project and Web Service Details dialog displays. 7

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Figure 3.2. Simple Web Service - Project and Web Service Details 3. Define the service attributes Define the project, web service, package and class names according to the options displayed in T able 3.1, Project and Web Service Details 8

Chapter 3. Creating a Simple Web Service T able 3.1. Project and Web Service Details Dialog group Field Mand atory Instruction T echnology yes Select the technology the Web Service will be based on. Dynamic web project Service details Service implementation Servic e name Updat e web.x ml Add REST Easy Jars from root runtim e directo ry Packa ge Description A simple web service can be based on either the Web Service Definition Language (WSDL) or RESTful (REST) API. Click the radio button beside the technology your web service should use. yes Select the project name. T he project name will default to the highlighted project in the Project Explorer. A different project can be selected from the drop-down list. yes no no yes Enter the name for the web service. Checkbox is checked by default, but is not mandatory. Check this box to add RESTEasy JARs to the project. Enter the package for the web service servlet. Class yes Enter the name of the web service servlet. Applic ation class only when the JAX- RS techno logy option Enter the name of the JAX-RS application class to use. The web service name will be the URL for the service as mapped in the deployment descriptor (web.xml). Leaving this checked will add your new service to the web.xm l in your project. This option allows you to add RESTEasy JARs to the project if they appear in the root runtime directory but are not installed in the runtime. While this is not required, it will assist when working with JBoss Application Server 5 and JBoss Enterprse Application Platform 5 web service projects. The default package is org.jboss.sam ples.websev ices. Select your own package using the... button. The default class name will correspond to the default web service name resulting in an equivalent URL to servlet name mapping in the deployment descriptor (web.xm l). The default application class is MyREST Application.Select your own application class using the... button. 9

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide is select ed 4. Generate the web service Click the Finish button to complete the web service setup. The web service classes will be generated and the web.xml file updated with the deployment details if the Update web.xm l option was selected. Figure 3.3. Created Simple Web Service 10

Chapter 4. Sample Web Service wizards Chapter 4. Sample Web Service wizards JBoss T ools includes wizards for the creation of sample web services. T hese include: Create a Sam ple REST ful Web Service for a JAX-RS web service. These wizards are used within a Dynamic Web project. A dynamic web project can be created by following the steps in Procedure 4.1, Creating a dynamic web project. Procedure 4.1. Creating a dynamic web project 1. Access the New Project Dialog Select File New Project T he New Project screen displays. 2. Define the Project T ype a. Click the Dynam ic Web Project label by expanding the Web folder. b. Click the Next button to proceed. T he New Dynam ic Web Project screen displays. 11

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Figure 4.1. Dynamic Web Project Attributes 3. Define the Project Attributes Define the Dynamic Web Project attributes according to the options displayed in T able 4.1, New Dynamic Web Project 12

Chapter 4. Sample Web Service wizards Table 4.1. New Dynamic Web Project Field Project name Project location Target runtime Dynamic web module version Configura tion EAR members hip Working sets Mandato ry Instruction Description yes Enter the project name. The project name can be any name defined by the user. yes no yes yes no no Click the Use default location checkbox to define the project location as the Eclipse workspace or define a custom path in the Location field. Select a pre-configured runtime from the available options or configure a new runtime environment. Select the required web module version. Select the project configuration from the available options. Add the project to an existing EAR project. Add the project to an existing working set. T he default location corresponds to the Eclipse workspace. T he target runtime defines the server to which the application will be deployed. This option adds support for the Java Servlet API with module versions corresponding to J2EE levels as listed in Table 4.2, New Dynamic Project - Dynamic web module version. The project can be based on either a custom or a set of predefined configurations as described in Table 4.3, New Dynamic Project - Configuration. The project can be added to an existing EAR project by selecting the checkbox. Once checked, a new EAR project can be defined by clicking the New Project button. A working set provides the ability to group projects or project attributes in a customized way to improve access. A new working set can be defined once the Select button has been clicked. Table 4.2. New Dynamic Project - Dynamic web module version Option Description 2.2 T his web module version corresponds to the J2EE 1.2 implementation. 2.3 T his web module version corresponds to the J2EE 1.3 implementation. 2.4 T his web module version corresponds to the J2EE 1.4 implementation. 2.5 T his web module version corresponds to the JEE 5 implementation. 13

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Table 4.3. New Dynamic Project - Configuration Option <custom> BIRT Charting Web Project BIRT Charting Web Project CXF Web Services Project v2.5 Default Configuration for JBoss 5.0 Runtime Dynamic Web Project with Seam 1.2 Dynamic Web Project with Seam 2.0 Dynamic Web Project with Seam 2.1 Dynamic Web Project with Seam 2.2 JBoss WS Web Service Project v3.0 JavaServer Faces v1.2 Project Minimal Configuration Description Choosing from one of the pre-defined configurations will minimise the effort required to set up the project. A project with the BIRT Charting Runtime Component. A project with the BIRT Reporting Runtime Component. Configures a project with CXF using Web Module v2.5 and Java v5.0. T his option is a suitable starting point. Additional facets can be installed later to add new functionality. Configures a project to use Seam v1.2. Configures a project to use Seam v2.0. Configures a project to use Seam v2.1. Configures a project to use Seam v2.2. Configures a project with JBossWS using Web Module v2.5 and Java v5.0. Configures a project to use JSF v1.2. T he minimum required facets are installed. Additional facets can be chosen later to add functionality to the project. 4. Access the Java sub-dialog Click Next to proceed. T he New Dynam ic Web Project - Java dialog displays. 5. Define the source and output folders Define the Dynamic Web Project source and output folders by adding or editing folders as required. 6. Access the Web Module sub-dialog Click Next to proceed. T he New Dynam ic Web Project - Web Module dialog displays. 14

Chapter 4. Sample Web Service wizards Figure 4.2. New Dynamic Web Project - Web Module 7. Enter the web module settings Define the settings as listed in Table 4.4, New Dynamic Web Project - Web Module including the root folder for path names in the web project context and the name of the web content directory. Table 4.4. New Dynamic Web Project - Web Module Field Mandato ry Instruction Description Context root Content directory Generate web.xml deployme nt descriptor yes yes no Enter the context root for the project. Enter the directory name for the web content. Check this box to generate a deployment descriptor for the project. The context root identifies a web application to the server and which URLs to delegate to the application. Web resources such as html, jsp files and graphic files will be written to the specified content directory. URL to servlet mappings and servlet authentication details are written to the deployment descriptor enabling the web server to serve requests. 8. Open the Java EE perspective. a. Click the Finish button to complete the project setup. If not already set, a dialog will appear prompting the user to open the relevant perspective. b. Click the Yes button to display the Java EE perspective. T he project is configured and the Java EE perspective is displayed. 15

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide 4.1. Sample RESTful Web Service A sample RESTful web service can be generated by following the steps outlined in Procedure 4.2, Generate a sample REST ful web service. Procedure 4.2. Generate a sample RESTful web service Target runtime must have RESTEasy installed The sample RESTful web service will not work unless it is deployed to a server with RESTEasy installed, such as JBoss SOA-P. 1. Access the New - Select a wizard dialog a. Right click on the project name in the Project Explorer view. b. Select New Other. c. Click the Create a Sam ple REST ful Web Service label by expanding the Web Services folder. T he New - Select a wizard dialog displays with the selected wizard type highlighted. 2. Access the Generate a Sample REST ful Web Service dialog Click the Next button to proceed. T he Generate a Sam ple REST ful Web Service - Project and Web Service Nam e dialog displays. 16

Chapter 4. Sample Web Service wizards Figure 4.3. Generate a Sample RESTful Web Service - Project and Web Service Name Due to the nature in which JBoss Application Server 7 and JBoss Enterprise Application Server 5 handle JAX-RS support, the wizard can now be completed without the need for RESTEasy JARs in the project classpath or associated project runtime. T he JARs are necessary for JBoss SOA-P servers. 3. Define the service attributes Define the project, web service, package and class names according to the options displayed in Table 4.5, Project and Web Service Name 17

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Table 4.5. Project and Web Service Name Dialog group Field Mand atory Dynamic Web Project Instruction Description yes Enter the project name. T he project name will default to the highlighted project in the Project Explorer. A different project can be selected from the list or entered directly in the editable drop-down list. Web Service Name yes Enter the name for the web service. Sample Web Service Class Updat e web.x ml Add REST Easy Jars from root runtim e directo ry Packa ge no no yes Check this box to add the service to the deployment descriptor. Check this box to add RESTEasy JARs to the project. Enter the package for the web service class. Class yes Enter the name of the web service class containing the JAX-RS annotated path. Applic ation Class Name 4. Generate the web service yes Enter the name of the Application Class Name. The web service name will be the url for the service as mapped in the deployment descriptor (web.xml). This option is checked by default and may be unchecked when deploying to JBoss AS 6.0 or REST Easy 2.0 servers. Service information is not required in the deployment descriptor for these servers. This option allows you to add RESTEasy JARs to the project if they appear in the root runtime directory but are not installed in the runtime. While this is not required, it will assist when working with JBoss Application Server 5 and JBoss Enterprse Application Platform 5 web service projects. The default package for the sample web service will be displayed. This class defines the path to the web service and is referenced in the Application Class Name. T he Application Class Name is declared in the deployment descriptor providing indirect access to the annotated path. T he Application Class Name constructor instantiates objects of the web service class containing the JAX-RS annotated path, GET and POST methods. It serves as a single point of access to the application for the web server. 18

Chapter 4. Sample Web Service wizards Click the Finish button to complete the web service setup. T he web service classes will be generated and the web.xml file updated with the deployment details. 5. Browse the MyREST Application.java class Double click the MyREST Application.java class and note the constructor instantiating objects of type HelloWorldResource. T he relevance of this will be discussed shortly. Figure 4.4. Application Class - MyREST Application.java 6. Browse the HelloWorldResource.java class Double click the HelloWorldResource.java class and note the JAX-RS annotated path and the annotated GET method. Figure 4.5. HelloWorldResource.java 19

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide 7. Browse the web.xml deployment descriptor Double click the web.xm l file and note the jax.ws.rs.application parameter mapped to the Application class. Note also that: the main servlet for the application is org.jboss.resteasy.plugins.server.servlet.httpservletdispatcher which is given the custom name Resteasy; and the main servlet is not mapped to a particular url as indicated by /*. The url for sending GET requests can be resolved as follows: a. Identify the Application Class as defined in the deployment descriptor. b. Note the object type instantiated in the Application class and added to the singleton set: HelloWorldResource. c. Note the JAX-RS annotated path declared in the corresponding HelloWorldResource class: @Path("/MyRESTApplication") [1]. Figure 4.6. web.xml T he url for sending GET requests is therefore http://localhost:8080/projectname/[1] or, http://localhost:8080/restfulsample/myrest Application. 20

Chapter 5. Working with RESTful web services Chapter 5. Working with RESTful web services After JAX-RS support has been enabled, a REST ful Web Services node will appear within the project file list, in the Project Explorer. T his node outlines the various REST ful services that your project contains. Figure 5.1. Working with REST ful web services Each element in the navigator displays the resolved HTTP method (for example: GET and POST) followed by the Uniform Resource Identifier (URI) path template (for example: /customers/{id}). @Path annotations are available for resources and subresources, at the method level. Optional @ApplicationPath annotation is available on any subclass of javax.ws.rs.core.application. Under each element are the resolved, consumed and produced media types (based on the annotations you have supplied for the method or type) and the associated Java method. To navigate to the related source code for a JAX-RS resource, double click the elements of the resource explorer and the related source code will be opened and highlighted. You can also copy the URI path template for later use. The tooling can include the @ApplicationPath annotation value in the endpoints URI Path Template for javax.ws.rs.core.application subclases. T o achieve this the JAX-RS application class must be provided. An example of this is: @ ApplicationPath("/mypath") public class MyApplication extends Application {... } You could also define the root path to the applications JAX-RS endpoint in the web.xml file. An example of this is: <servlet-mapping> <servlet-name>javax.ws.rs.core.application</servlet-name> <url-pattern>/hello/* </url-pattern> </servlet-mapping> 21

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Note The web.xml approach takes precedence over the annotation approach due to the JAX-RS 1.1 specification. 5.1. Running REST methods on the server You can run a particular method of your REST ful project by right-clicking on the JAX-RS REST Web Services method that exists for your project, viewable in the Project Explorer and selecting Run As Run on Server. Figure 5.2. Running a REST method on the server If the server is not in a started state when this action is executed, or the application the method belongs to is not deployed to the server, these actions will be performed as a result of choosing to running the method on the server. Once the method has successfully run on the server, the Web Service T ester will open within the current workbench perspective and the URL for the REST ful operation will have automatically been set. Figure 5.3. Web Service T ester 22

Chapter 5. Working with RESTful web services 23

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Chapter 6. Web Service Test View JBoss T ools provides a view to test web services. T he Web Services T est View can be displayed by following the steps in Procedure 6.1, Web Services T est View. Procedure 6.1. Web Services T est View Access the Show View dialog 1. Select Window Show View Other T he Show View dialog displays. 2. Click on the Web Services T ester label by expanding the JBoss T ools Web Services node and click OK. T he Web Services test view displays. Figure 6.1. Web Service Test View The main components of the Web Service Tester View are: WSDL path/button bar (T able 6.1, WSDL path/button bar ) Request details panel (T able 6.2, Request details panel ) Response details panel (T able 6.3, Response details panel ) 24

Chapter 6. Web Service Test View T able 6.1. WSDL path/button bar Component Editable dropdown list Combo box Toolbar button - Get From WSDL Toolbar button - Invoke Description Enter the location of the WSDL file or HTTP address of the service to be tested. The combo box requires the path to the WSDL in a URI format. Select the type of service to test. The options are JAX-WS or any other option to test a JAX-RS service using HTTP request methods (PUT, GET, POST, DELETE or OPTIONS). Click this button to display the Select WSDL dialog. Enter the URL, File system location or Eclipse Workspace location of the WSDL file. Given a valid file, the dialog will allow selection of the Port and Operation to test. Once selected, the request details will be displayed in the Request Details panel. Once the WSDL file has been selected, the service can be invoked by clicking this button. Response details will be displayed in the Response Details panel. T able 6.2. Request details panel Component Prompt for Basic Authentication Headers Parameters Body Description Select this check box to send a username and password with the request. Entering the user details for each subsequent request is not necessary as the details are stored in memory. Enter (Add) one or more name=value pairs. These headers will be passed with the invocation request at the HTTP level where possible. As for header information, enter one or more nam e=value pairs by clicking the Add button. Enter the JAX-WS SOAP request messages or input for JAX-RS service invocations in this text box. T able 6.3. Response details panel Component Response headers Response body Parameters Body Description T he headers returned by the service invocation will be displayed in this panel. T he JAX-WS and JAX-RS response bodies will be displayed in this box. T he raw text returned from the web service invocation can be displayed by clicking the Show Raw button. The output will be embedded in a html browser by clicking the Show in Browser button. T he output can alternatively be displayed in the Eclipse editor as xml or raw text (depending on the response content type) by clicking the Show in Editor button. As for header information, enter one or more nam e=value pairs by clicking the Add button. Enter JAX-WS SOAP request messages and input for JAX-RS service invocations in this text box. T he following sections describe testing JAX-RS web services, including the necessary preliminary steps. 25

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide 6.1. Preliminaries T he following procedure describes the steps to perform before testing a web service. Procedure 6.2. T esting a web service Preliminary steps Prior to testing a web service: 1. T he Web Service T est View should be opened as described in Procedure 6.1, Web Services T est View ; T he Web Service T est View displays. Figure 6.2. Web Service Test View 2. A web service has been deployed to the deploy directory of the chosen server profile. 3. T he server has been started with run.sh -c <profile> 6.2. Testing a RESTful Web Service Testing a RESTful ( JAX-RS ) web service is achieved by following a similar procedure to testing a JAX- WS web service. Instead of selecting the JAX-WS option in the combobox, the JAX-RS service is invoked by sending HTTP method requests of the form OPTIONS, GET, POST, PUT and DELETE. As there is no WSDL file associated with a JAX-RS service, the available options can be determined by selecting OPT IONS in the combobox. A JAX-RS web service can be tested by using the Web Service T ester View displayed in Figure 6.1, Web Service Test View. The JAX-RS test is specified by: 1. Selecting the OPT IONS combobox option. 2. Entering the url of the JAX-RS web service. T he test procedure is discussed in the following sections for both the RestfulSample and the REST Easy sample projects developed earlier. 6.2.1. RestfulSample project 26

Chapter 6. Web Service Test View Procedure 6.3. RestfulSample test 1. a. Query the available options Select OPT IONS from the available combobox options. b. Enter the url of the web service in the editable drop-down list: http://localhost:8080/restfulsample/myrest Application. c. Click the Invoke button The Response Headers text area indicates that the allowed options are [GET, OPT IONS, HEAD] as shown in Figure 6.3, JAX-RS Response Header T ext. Figure 6.3. JAX-RS Response Header T ext 2. Test the GET request a. Having established that the GET request is valid, select GET from the available combobox options. b. Click the Invoke button. T he Response Body text area displays the expected Hello World text as shown in Figure 6.4, JAX-RS Response Body T ext. Figure 6.4. JAX-RS Response Body Text 6.2.2. RESTEasy sample project Procedure 6.4. Testing a JAX-RS web service- POST and GET requests 1. a. Query the available options Following the preliminary steps described in Procedure 6.2, T esting a web service, select 27

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide the OPT IONS method from the operations text area. b. Enter the url of the web service in the editable drop-down list http://localhost:8080/simple/rest-services/customers. c. Click the Invoke button The Response Headers text area indicates that the allowed options are [POST, OPTIONS] as shown in Figure 6.5, JAX-RS RESTEasy project Body Text. Figure 6.5. JAX-RS RESTEasy project Body Text 2. Test the POST option a. Select POST method in the the operations drop-down list. b. We will post xml data to this particular web service. Complete the header details by entering content-type=application/xml in the text area and click Add to add it to the Headers list. T he content-type is added to the Headers list as shown in Figure 6.6, content-type header. Figure 6.6. content-type header c. Enter customer details Enter the customer details in the Body T ext area as displayed in Figure 6.7, Customer 28

Chapter 6. Web Service Test View data. Figure 6.7. Customer data d. Click the Invoke button. T he Response Headers area indicated that a record was created and lists the location as http://localhost:8080/simple/rest-services/customers/1 as shown in Figure 6.8, Customer added. Figure 6.8. Customer added The console also indicates the successful creation of the customer: 10:44:33,846 INFO [ST DOUT] Created custom er 1 3. Test the GET option a. Select the GET method in the the operations drop-down list. b. We will retrieve the record created in the previous step. Enter the url for the record returned in the previous step http://localhost:8080/simple/rest-services/customers/1 c. Click the Invoke button. T he Response Headers area indicates a [HT T P/1.1 200 OK] response and the customer data is retrieved and displayed in the Response Body area as shown in Figure 6.9, GET response. 29

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Figure 6.9. GET response 4. Test the PUT option a. Editing a record is achieved by using the PUT method. Select the PUT method in the operations drop-down list. b. Enter the url of the record to be edited http://localhost:8080/simple/restservices/customers/1 c. Enter the data in the Body Text area. Replace the first-name with a different entry as in Figure 6.10, Updated customer data Figure 6.10. Updated customer data d. Ensure that the content-type=application/xm l header is in the Headers list. e. Click the Invoke button. The Response Headers area indicates a No Response ([HTTP/1.1 204 No Content]) Figure 6.11, Response header following PUT. 30

Chapter 6. Web Service Test View Figure 6.11. Response header following PUT In this instance, the console does not indicate an update was performed, however, the console may provide useful information following an operation. 5. Check the updated data with a GET Perform a GET operation by following the steps in Step 3. T he Response Body area displays the updated data. Figure 6.12. Customer data updated 6. Test the DELETE option a. Deleting a record is a similar process to posting. Select the DELETE method in the operations drop-down list. b. Enter the url of the record to be deleted http://localhost:8080/simple/restservices/customers/1 c. Click the Invoke button. The Response Headers area indicates a No Response ([HTTP/1.1 204 No Content]) as was the case for the PUT operation in Figure 6.11, Response header following PUT. Once again, the console does not indicate an update was performed, however, the console may provide useful information following an operation. 31

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide 7. Check the DELETE operation with a GET Perform a GET operation by following the steps in Step 3. The Response Body area returns an error report indicating that The requested resource () is not available and the Response Headers area returns a [HTTP/1.1 404 Not Found]. Figure 6.13. Customer data deleted T he response header and body messages indicate that the data was successfully deleted. 32

Chapter 7. JAX-RS Validation Chapter 7. JAX-RS Validation JAX-RS validation is enabled by default. Validation allows your project to be checked for errors. If an error is discovered a Problem s tab will appear in the bottom section of your workbench, outlining the errors found. If you wish to turn off JAX-RS Validation, you can do so by first navigating to Window Preferences Validation. In the Validator section of the dialog, deselect the checkboxes for JAX-RS Metam odel Validator and click the Apply button, followed by OK. Figure 7.1. Validator preferences 33

Red Hat JBoss Developer Studio 7.0 JBoss RESTful Web Services User Guide Getting Help and Giving Feedback A.1. Do You Need Help? If you experience difficulty with a procedure described in this documentation, visit the Red Hat Customer Portal at http://access.redhat.com. T hrough the customer portal, you can: search or browse through a knowledgebase of technical support articles about Red Hat products. submit a support case to Red Hat Global Support Services (GSS). access other product documentation. Red Hat also hosts a large number of electronic mailing lists for discussion of Red Hat software and technology. You can find a list of publicly available mailing lists at https://www.redhat.com/mailman/listinfo. Click on the name of any mailing list to subscribe to that list or to access the list archives. A.2. Give us Feedback If you find a typographical error, or know how this guide can be improved, we would love to hear from you. Submit a report in Bugzilla against the product JBoss Developer Studio and the component REST ful Web Services User Guide. T he following link will take you to a pre-filled bug report for this product: http://bugzilla.redhat.com/. Fill out the following template in Bugzilla's Description field. Be as specific as possible when describing the issue; this will help ensure that we can fix it quickly. Document URL: Section Number and Name: Describe the issue: Suggestions for improvement: Additional information: Be sure to give us your name so that you can receive full credit for reporting the issue. 34

Revision History Revision History Revision 7.0.0-1.4 00 2013-10-31 Rüdiger Landmann Rebuild with publican 4.0.0 Revision 7.0.0-1 Fri Sep 13 2013 Michelle Murray Released for 7.0.0 35