Book Image

Java EE 7 with GlassFish 4 Application Server

By :
Book Image

Java EE 7 with GlassFish 4 Application Server

By:

Overview of this book

<p>GlassFish is a free, open source application server which supports all the major Java features such as Enterprise JavaBeans, JPA, JavaServer Faces, JMS, RMI, JavaServer Pages, and servlets. It is the first Java EE 7 compliant application server. All major Java EE technologies and API's are covered in this version of Java. GlassFish server allows the user to work with the extensile, adaptable, and lightweight Java EE 7 platform. <br /><br />This book explores the installation and configuration of GlassFish, and then moves on to Java EE 7 application development, covering all major Java EE 7 APIs. It focuses on going beyond the basics to develop Java applications deployed to the GlassFish 4 application server. The book covers all major Java EE 7 APIs including JSF 2.2, EJB 3.2, CDI 1.1, the Java API for WebSocket, JAX-WS, JAX-RS and more. <br /><br />The book also introduces JSON-P, the Java API for JSON (Javascript Object Notation) Processing. This advanced topic deals with how the two APIs are used to process JSON function, namely the Model API and the Streaming API. Apart from revisiting Java Server Faces (JSF), it explains why Facelets, the new features introduced in modern versions of JSF, are the preferred view technology over Java Server Pages (JSP)<br /><br />The later chapters explore competing implementations of the WebSocket standard in Java, describing the updates in JMS; which aims to provide a simpler API and reduction in boilerplate code among a host of other features. Readers will also learn how to secure Java EE applications by taking advantage of GlassFish's built-in security features. Finally, we learn more about the RESTful web service development using the JAX-RS specification.</p>
Table of Contents (18 chapters)
Java EE 7 with GlassFish 4 Application Server
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Securing Java EE Applications
Index

Working with query and path parameters


In our previous examples, we have been working with a RESTful web service to manage a single customer object. In real life, this would obviously not be very helpful. The common case is to develop a RESTful web service to handle a collection of objects (customers, in our example). To determine which specific object in the collection we are working with, we can pass parameters to our RESTful web services. There are two types of parameters we can use: query and path.

Query parameters

We can add parameters to methods that will handle HTTP requests in our web service. Parameters decorated with the @QueryParam annotation will be retrieved from the request URL.

The following example illustrates how to use query parameters in our JAX-RS RESTful web services:

package com.ensode.queryparams.service;

import com.ensode.queryparams.entity.Customer;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax...