type=page
status=published
title=The jsonpstreaming Example Application
next=jsonp008.html
prev=jsonp006.html
~~~~~~
=The jsonpstreaming Example Application


[[BABBJDAC]]

[[the-jsonpstreaming-example-application]]
The jsonpstreaming Example Application
--------------------------------------

This section describes how to build and run the `jsonpstreaming` example
application. This example is a web application that demonstrates how to
create JSON data from form data, how to parse JSON data, and how to
write JSON output using the streaming API.

The `jsonpstreaming` example application is in the
tut-install`/examples/web/jsonp/jsonpstreaming` directory.

The following topics are addressed here:

* link:#CEGDBIID[Components of the jsonpstreaming Example Application]
* link:#CEGGHFIG[Running the jsonpstreaming Example Application]

[[CEGDBIID]]

[[components-of-the-jsonpstreaming-example-application]]
Components of the jsonpstreaming Example Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `jsonpstreaming` example application contains the following files.

* Three JavaServer Faces pages.

** The `index.xhtml` page contains a form to collect information.

** The `filewritten.xhtml` page contains a text area that displays JSON
data.

** The `parsed.xhtml` page contains a table that lists the events from
the parser.
* The `StreamingBean.java` managed bean, a session-scoped managed bean
that stores the data from the form and directs the navigation between
the Facelets pages. This file also contains code that uses the JSON
streaming API.

The code used in `StreamingBean.java` to write JSON data to a file is
similar to the example in link:jsonp004.html#BABGJEEF[Writing JSON Data
Using a Generator]. The code to parse JSON data from a file is similar
to the example in link:jsonp004.html#BABGCHIG[Reading JSON Data Using a
Parser].

[[CEGGHFIG]]

[[running-the-jsonpstreaming-example-application]]
Running the jsonpstreaming Example Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This section describes how to run the `jsonpstreaming` example
application using NetBeans IDE and from the command line.

The following topics are addressed here:

* link:#CEGJCBCG[To Run the jsonpstreaming Example Application Using
NetBeans IDE]
* link:#CEGCGDDJ[To Run the jsonpstreaming Example Application Using
Maven]

[[CEGJCBCG]]

[[to-run-the-jsonpstreaming-example-application-using-netbeans-ide]]
To Run the jsonpstreaming Example Application Using NetBeans IDE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1.  Make sure that GlassFish Server has been started (see
link:usingexamples002.html#BNADI[Starting and Stopping GlassFish
Server]).
2.  From the File menu, choose Open Project.
3.  In the Open Project dialog box, navigate to:
+
[source,oac_no_warn]
----
tut-install/examples/web/jsonp
----
4.  Select the `jsonpstreaming` folder.
5.  Click Open Project.
6.  In the Projects tab, right-click the `jsonpstreaming` project and
select Run.
+
This command builds and packages the application into a WAR file
(`jsonpstreaming.war`) located in the `target` directory, deploys it to
the server, and opens a web browser window with the following URL:
+
[source,oac_no_warn]
----
http://localhost:8080/jsonpstreaming/
----
7.  Edit the data on the page and click Write a JSON Object to a File to
submit the form and write a JSON object to a text file. The following
page shows the contents of the text file.
8.  Click Parse JSON from File. The following page contains a table that
lists the parser events for the JSON data in the text file.

[[CEGCGDDJ]]

[[to-run-the-jsonpstreaming-example-application-using-maven]]
To Run the jsonpstreaming Example Application Using Maven
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1.  Make sure that GlassFish Server has been started (see
link:usingexamples002.html#BNADI[Starting and Stopping GlassFish
Server]).
2.  In a terminal window, go to:
+
[source,oac_no_warn]
----
tut-install/examples/web/jsonp/jsonpstreaming/
----
3.  Enter the following command to deploy the application:
+
[source,oac_no_warn]
----
mvn install
----
4.  Open a web browser window and enter the following URL:
+
[source,oac_no_warn]
----
http://localhost:8080/jsonpstreaming/
----
5.  Edit the data on the page and click Write a JSON Object to a File to
submit the form and write a JSON object to a text file. The following
page shows the contents of the text file.
6.  Click Parse JSON from File. The following page contains a table that
lists the parser events for the JSON data in the text file.


