-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.html
299 lines (275 loc) · 15 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!doctype html>
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) 2014-2015 Oracle and/or its affiliates. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can
obtain a copy of the License at
http://glassfish.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt. See the License for the specific
language governing permissions and limitations under the License.
When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.
GPL Classpath Exception:
Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the GPL Version 2 section of the License
file that accompanied this code.
Modifications:
If applicable, add the following below the License Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyright [year] [name of copyright owner]"
Contributor(s):
If you wish your version of this file to be governed by only the CDDL or
only the GPL Version 2, indicate your decision by adding "[Contributor]
elects to include this software in this distribution under the [CDDL or GPL
Version 2] license." If you don't indicate a single choice of license, a
recipient has the option to distribute your version of this file under
either the CDDL, the GPL Version 2 or to extend the choice of license to
its licensees as provided above. However, if you add GPL Version 2 code
and therefore, elected the GPL Version 2 license, then the option applies
and therefore, elected the GPL Version 2 license, then the option applies
only if the new code is made subject to such option by the copyright
holder.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Reactive Client Extension WebApp Example</title>
<!-- Bootstrap -->
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-offset-1 col-lg-10">
<header class="page-header">
<h1>Reactive Clients <small>Jersey Reactive Client Extensions Example</small></h1>
</header>
<p>
This example demonstrates how data from multiple resources and in various formats (json, xml) can be
combined into a form suitable to ones requirements. The example show and compares usage of standard
JAX-RS sync client, JAX-RS async client, Jersey's Observable (RxJava) client extension,
Jersey's Observable (RxJava) client extension using Netflix Hystrix latency and fault tolerant library,
Jersey's CompletionStage (Java 8) client extension and Jersey's ListenableFuture (Guava) client extension.
</p>
<p>
The application consists of two parts:
<ul>
<li>
<strong>"Remote"</strong>, that can be considered to be deployed on a remote machine. In fact each
resource from <code>org.glassfish.jersey.examples.rx.remote</code> package can be deployed on a
separate remote machine as every resource represents a service of it's own. <br/>
<strong>Note:</strong> <code>DestinationResource</code> returns response entities as
<code>JSON</code> while <code>CalculationResource</code> and <code>ForecastResource</code> as
<code>XML</code>.<br/><br/>
</li>
<li>
<strong>"Agent"</strong>, which is a synchronization/orchestration layer. This layer, also deployed
as a server application, fetches data from all needed resources (using JAX-RS Client API) and
combine them together. The combined result is then sent to the client that invoked the original
request on the orchestration layer.
</li>
</ul>
</p>
<p>
Every "agent" resource (package <code>org.glassfish.jersey.examples.rx.agent</code>) invokes the
following requests to the "remote" resource:
<ul>
<li>
Obtain <strong>visited</strong> destinations for a user. (User identification is propagated via
request header and basically everything about a user maximally simplified since it's out of scope
of this example)
</li>
<li>
Obtain <strong>recommended</strong> destinations for a user. Requests obtaining
<strong>visited</strong> and <strong>recommended</strong> destinations are independent and can be
run in parallel.
</li>
<li>
Obtain weather <strong>forecasts</strong> for recommended destinations. New client request is
invoked for every recommended destination. Obtaining weather <strong>forecasts</strong> depend
on actual <strong>recommended</strong> destinations.
</li>
<li>
Obtain trip <strong>calculations</strong> (prices) for recommended destinations. New client
request is invoked for every recommended destination. Obtaining trip <strong>calculations</strong>
depend on actual <strong>recommended</strong> destinations. <strong>forecast</strong> and
<strong>calculation</strong> requests are independent on each other and can be invoked in
parallel.
</li>
</ul>
</p>
<h2>Contents</h2>
<p>
The mapping of the URI path space is presented in the following table:
</p>
<table class="table table-bordered">
<thead>
<tr>
<th>URI path</th>
<th>Resource class</th>
<th>HTTP methods</th>
<th>Allowed values</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>/rx/agent/sync</code></td>
<td>SyncAgentResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/agent/async</code></td>
<td>AsyncAgentResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/agent/observable</code></td>
<td>ObservableAgentResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/agent/hystrix</code></td>
<td>HystrixObservableAgentResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/agent/completion</code></td>
<td>CompletionStageAgentResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/agent/listenable</code></td>
<td>ListenableFutureAgentResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/remote/destination/visited</code></td>
<td>DestinationResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/remote/destination/recommended</code></td>
<td>DestinationResource</td>
<td>GET</td>
<td>returns JSON</td>
</tr>
<tr>
<td><code>/rx/remote/forecast/{destination}</code></td>
<td>ForecastResource</td>
<td>GET</td>
<td>destination - name of a country; returns XML (random value)</td>
</tr>
<tr>
<td><code>/rx/remote/calculation/from/{from}/to/{to}</code></td>
<td>CalculationResource</td>
<td>GET</td>
<td>from - name of a country, to - name of a country; returns XML (random value)</td>
</tr>
</tbody>
</table>
<p>
Application is Servlet 3 based, web.xml-less. Everything needed (resources/providers) is registered in
<code>RxApplication</code>.
</p>
<h2>Sample Response</h2>
<p>
Agent responses look similar to the following one:
<pre>{
"visited" : [ {
"destination" : "Antigua & Barbuda"
}, {
"destination" : "Guinea"
}, {
"destination" : "Malta"
}, {
"destination" : "Denmark"
}, {
"destination" : "Tajikistan"
} ],
"recommended" : [ {
"destination" : "Bolivia",
"forecast" : "Showers",
"price" : 1359
}, {
"destination" : "Yemen",
"forecast" : "Haze",
"price" : 8032
}, {
"destination" : "Dominican Republic",
"forecast" : "Cloudy",
"price" : 1141
}, {
"destination" : "Korea South",
"forecast" : "Mostly Sunny",
"price" : 9853
}, {
"destination" : "Saudi Arabia",
"forecast" : "Fog",
"price" : 9063
} ],
"processingTime" : 877
}</pre>
As can be seen the response entity contains 3 main elements: <strong>visited</strong> (list of visited
destinations), <strong>recommended</strong> (list of recommended destinations + weather forecast and price
calculation) and <strong>processingTime</strong> (describing how long it took to obtain previous two
elements).
</p>
<h2>Running the Example</h2>
<p>Run the example as follows:</p>
<blockquote>
<pre>mvn clean package jetty:run</pre>
</blockquote>
<p>
This deploys current example using Jetty. You can access the application at:
<ul>
<li><a href="http://localhost:8080/rx/agent/sync">http://localhost:8080/rx/agent/sync</a></li>
<li><a href="http://localhost:8080/rx/agent/async">http://localhost:8080/rx/agent/async</a></li>
<li><a href="http://localhost:8080/rx/agent/listenable">http://localhost:8080/rx/agent/listenable</a></li>
<li><a href="http://localhost:8080/rx/agent/observable">http://localhost:8080/rx/agent/observable</a></li>
<li><a href="http://localhost:8080/rx/agent/hystrix">http://localhost:8080/rx/agent/hystrix</a></li>
<li><a href="http://localhost:8080/rx/agent/completion">http://localhost:8080/rx/agent/completion</a></li>
</ul>
</p>
<h2>Resources</h2>
<p>This examples is using the following (3-rd party) libraries:</p>
<div>
<strong>RxJava</strong> by Netflix
<ul>
<li><a href="https://github.com/ReactiveX/RxJava">GitHub</a></li>
<li><a href="https://github.com/ReactiveX/RxJava/wiki">GitHub.Wiki</a></li>
<li><a href="http://reactivex.io/RxJava/javadoc/">JavaDoc</a></li>
</ul>
</div>
<div>
<strong>Hystrix</strong> by Netflix
<ul>
<li><a href="https://github.com/Netflix/Hystrix">GitHub</a></li>
<li><a href="https://github.com/Netflix/Hystrix/wiki">GitHub.Wiki</a></li>
<li><a href="http://netflix.github.io/Hystrix/javadoc/">JavaDoc</a></li>
</ul>
</div>
<div>
<strong>Guava</strong> by Google
<ul>
<li><a href="https://code.google.com/p/guava-libraries/">Homepage</a></li>
<li><a href="https://code.google.com/p/guava-libraries/wiki/ListenableFutureExplained">ListenableFuture Explained</a></li>
<li><a href="http://docs.guava-libraries.googlecode.com/git/javadoc/index.html?overview-summary.html">JavaDoc</a></li>
</ul>
</div>
</div>
</div>
</div>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</body>
</html>