|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <!-- |
| 5 | +
|
| 6 | + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 7 | +
|
| 8 | + Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. |
| 9 | +
|
| 10 | + The contents of this file are subject to the terms of either the GNU |
| 11 | + General Public License Version 2 only ("GPL") or the Common Development |
| 12 | + and Distribution License("CDDL") (collectively, the "License"). You |
| 13 | + may not use this file except in compliance with the License. You can |
| 14 | + obtain a copy of the License at |
| 15 | + https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html |
| 16 | + or packager/legal/LICENSE.txt. See the License for the specific |
| 17 | + language governing permissions and limitations under the License. |
| 18 | +
|
| 19 | + When distributing the software, include this License Header Notice in each |
| 20 | + file and include the License file at packager/legal/LICENSE.txt. |
| 21 | +
|
| 22 | + GPL Classpath Exception: |
| 23 | + Oracle designates this particular file as subject to the "Classpath" |
| 24 | + exception as provided by Oracle in the GPL Version 2 section of the License |
| 25 | + file that accompanied this code. |
| 26 | +
|
| 27 | + Modifications: |
| 28 | + If applicable, add the following below the License Header, with the fields |
| 29 | + enclosed by brackets [] replaced by your own identifying information: |
| 30 | + "Portions Copyright [year] [name of copyright owner]" |
| 31 | +
|
| 32 | + Contributor(s): |
| 33 | + If you wish your version of this file to be governed by only the CDDL or |
| 34 | + only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 35 | + elects to include this software in this distribution under the [CDDL or GPL |
| 36 | + Version 2] license." If you don't indicate a single choice of license, a |
| 37 | + recipient has the option to distribute your version of this file under |
| 38 | + either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 39 | + its licensees as provided above. However, if you add GPL Version 2 code |
| 40 | + and therefore, elected the GPL Version 2 license, then the option applies |
| 41 | + only if the new code is made subject to such option by the copyright |
| 42 | + holder. |
| 43 | +
|
| 44 | + --> |
| 45 | + |
| 46 | + <title>The Asynchronous Chat JAX-RS Sample Application</title> |
| 47 | + <style type="text/css"> |
| 48 | + body,th,td,p,div,span,a,ul,ul li, ol, ol li, ol li b, dl,h1,h2,h3,h4,h5,h6,li |
| 49 | + {font-family:geneva,helvetica,arial,"lucida sans",sans-serif; font-size:10pt} |
| 50 | + h1 {font-size:18pt} |
| 51 | + h2 {font-size:14pt} |
| 52 | + h3 {font-size:12pt} |
| 53 | + code,kbd,tt,pre {font-family:monaco,courier,"courier new";font-size:10pt;color:#666} |
| 54 | + li {padding-bottom: 8px} |
| 55 | + p.copy, p.copy a {font-family:geneva,helvetica,arial,"lucida sans",sans-serif; font-size:8pt} |
| 56 | + p.copy {text-align: center} |
| 57 | + </style> |
| 58 | + </head> |
| 59 | + <body style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" |
| 60 | + alink="#333366" |
| 61 | + link="#594fbf" |
| 62 | + marginwidth="10" |
| 63 | + vlink="#1005fb"> |
| 64 | + <table border="0" |
| 65 | + cellpadding="2" |
| 66 | + cellspacing="4" |
| 67 | + width="100%"> |
| 68 | + <tbody> |
| 69 | + <tr> |
| 70 | + <td align="right" bgcolor="#587993" valign="top"><font color="#ffffff" size="-1"><b>Java EE 7 SDK</b></font> </td> |
| 71 | + </tr> |
| 72 | + </tbody> |
| 73 | + </table> |
| 74 | + <!-- Don't modify anything above this line, except for the title tag --> |
| 75 | + <p><a href="../../../docs/list.html">Samples Main Page</a></p> |
| 76 | + <h1>The Asynchronous Chat JAX-RS Sample Application</h1> |
| 77 | + <p>This sample application uses JAX-RS asynchronous features to implement a simple |
| 78 | + producer/consumer chat.</p> |
| 79 | + |
| 80 | + <h2>Description</h2> |
| 81 | + <p>This sample demonstrates how to use <code>javax.ws.rs.container.AsyncResponse</code>. |
| 82 | + The deployed resource (<code>ChatResource</code>) contains two asynchronous methods. |
| 83 | + These methods have a response annotated with <code>@AsyncResponse</code> and run |
| 84 | + in the suspended mode. In this mode, the response is not returned from the resource method |
| 85 | + as a return value but must be resumed by calling the <code>AsyncResponse.resume()</code> method. |
| 86 | + Before the response is resumed, the execution thread is returned back to container. |
| 87 | + </p> |
| 88 | + <p> |
| 89 | + The resource method that receives messages (<code>ChatResource.getMesssage()</code>) stores |
| 90 | + the asynchronous response in a blocking queue. After the message is sent to server |
| 91 | + (<code>ChatResource.posMesssage()</code>), the asynchronous response of the request that is waiting |
| 92 | + for message is taken from the queue and resumed with the message. Instead of keeping messages in |
| 93 | + the queue, the queue stores the responses waiting for these messages, and the messages are directly |
| 94 | + delivered to these response when they are available. |
| 95 | + </p> |
| 96 | + <p>The front page shows the text input field for a message. Enter a message and click on |
| 97 | + <code>POST MESSAGE</code>. The POST request is sent to the server where it is blocked in the |
| 98 | + queue until a message is requested.</p> |
| 99 | + <p>After sending a message, click on <code>GET MESSAGE</code>, which sends a |
| 100 | + background asynchronous GET request to the server. This request will be suspended and |
| 101 | + resumed later with the message from the POST request that is stored in the blocking queue. |
| 102 | + The message is sent back to the browser and displayed in the box below the |
| 103 | + <code>GET MESSAGE</code> button.</p> |
| 104 | + <p>If you click the buttons in the opposite order, |
| 105 | + the GET request is suspended waiting to be resumed by an incoming POST request. |
| 106 | + </p> |
| 107 | + <p>The page also contains the field with the status of an asynchronous queue |
| 108 | + that is stored in <code>ChatResource</code>. This |
| 109 | + field is automatically refreshed in short intervals by calling the GET method on |
| 110 | + <code>/chat/queue</code> from <code>ChatResource</code>. |
| 111 | + </p> |
| 112 | + <p> |
| 113 | + You can only send one GET and one POST request to the server from the page |
| 114 | + (the buttons are then disabled). To submit more |
| 115 | + GET and POST requests, open new browser windows. The screen also contains a |
| 116 | + log of the asynchronous requests submitted by the browser.</p> |
| 117 | + |
| 118 | + |
| 119 | + <h2>Key Features</h2> |
| 120 | + <p>This sample application demonstrates the following key features:</p> |
| 121 | + <ul> |
| 122 | + <li><code>@AsyncResponse</code></li> |
| 123 | + <li><code>@Path</code></li> |
| 124 | + <li><code>@Singleton</code></li> |
| 125 | + </ul> |
| 126 | + |
| 127 | + <h2>Building, Deploying, and Running the Application</h2> |
| 128 | + <!-- Modify this section as needed --> |
| 129 | + <p>Perform the following steps to build, deploy, and run the application:</p> |
| 130 | + <ol> |
| 131 | + <li> Set up your build environment and configure the application server with which the build system has to work by following the <a href="../../../docs/UserREADME.html">common build instructions.</a></li> |
| 132 | + <li><code><i>samples_install_dir</i></code> is the sample application base directory. Go to: <code><i>samples_install_dir</i>/javaee7/rest/async-chat</code>.</li> |
| 133 | + <li>Build, deploy, and run the sample application using the <code>run</code> outcome. |
| 134 | + <p><code>mvn clean verify cargo:run</code></p> |
| 135 | + </li> |
| 136 | + <li>The front page of this sample is at |
| 137 | + <code>http://localhost:8080/async-chat</code>.<br/> |
| 138 | + (The port number might vary.)</li> |
| 139 | + <li>Use the <code>clean</code> outcome to undeploy the sample application and to remove the temporary directories such as <code>build</code> and <code>dist</code>. |
| 140 | + <p><code>mvn clean</code></p> |
| 141 | + </li> |
| 142 | + </ol> |
| 143 | + |
| 144 | + <h2>Troubleshooting</h2> |
| 145 | + <p>If you have problems when running the application, refer to the <a href="../../../docs/UserTroubleShooting.html">troubleshooting document</a>.</p> |
| 146 | + <br> |
| 147 | + <!--- Do not modify the rest of the document --> |
| 148 | + <hr noshade="noshade" size="1"> |
| 149 | + <!-- start copyright --> |
| 150 | + <p class="copy">Copyright © 1997-2013 Oracle and/or its affiliates. All rights reserved. </p> |
| 151 | + <!-- end copyright --> |
| 152 | + </body> |
| 153 | +</html> |
0 commit comments