Java EE 7 SDK

Samples Main Page

# The JAX-RS JSONP Sample Application

This sample demonstrates how to use the Java API for JSON Processing with JAX-RS.

## Description

This sample shows a JAX-RS application that produces and consumes JSON using the Java API for JSON Processing. The JAX-RS resources in this sample can use `JsonObject`, `JsonArray`, and `JsonStructure` objects as method parameters and return types.

## Key Features

This sample demonstrates the following key features:

- The JSON Processing Streaming API: Using the `JsonParser` and `JsonGenerator` interfaces.
- The JSON Processing Object Model API: Creating, obtaining, and using `JsonObject`, `JsonArray`, and `JsonStrucuture` objects.

## Building, Deploying, and Running the Application

Perform the following steps to build, deploy, and run the application:

1. Set up your build environment and configure the application server with which the build system has to work by following the common build instructions.
2. `app_dir` is the sample application base directory: `samples_install_dir/jsonp/jaxrs`.
3. Build, deploy, and run the sample application using the `run` outcome.

   `mvn clean verify cargo:run`

4. The resources of the sample application are located at the following URLs: (The port number might vary.)
   - Parser resource: `http://localhost:8080/jsonp-jaxrs-resources/parser`
     The parser resource uses the `JsonParser` interface to parse Twitter search results. Since it needs to contact the Twitter search URL, you may need to specify the appropiate proxy server in the Glassfish Server Administration Console.
   - Generator resource: `http://localhost:8080/jsonp-jaxrs-resources/generator`
     The generator resource uses the `JsonGenerator` interface to generate sample JSON.
   - Object resource: `http://localhost:8080/jsonp-jaxrs-resources/object`
     The object resource uses `JsonObject` to produce and consume JSON.
   - Array resource: `http://localhost:8080/jsonp-jaxrs-resources/array`
     The array resource uses `JsonArray` to produce and consume JSON.
   - Structure resource: `http://localhost:8080/jsonp-jaxrs-resources/structure`
     The structure resource uses `JsonStructure` to produce and consume JSON.
5. Use the `clean` outcome to undeploy the sample application and to remove the temporary directories such as `build` and `dist`.

   `mvn clean`

## Troubleshooting

If you have problems when running the application, refer to the troubleshooting document.

Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved.