<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) 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
only if the new code is made subject to such option by the copyright
holder.
-->
Reactive Clients Jersey Reactive Client Extensions Example
==========================================================
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 and Jersey's ListenableFuture (Guava) client extension.
The application consists of two parts:
- **"Remote"**, that can be considered to be deployed on a
remote machine. In fact each resource from
`org.glassfish.jersey.examples.rx.remote` package can be deployed on
a separate remote machine as every resource represents a service of
it's own.
- **Note:** `DestinationResource` returns response entities as `JSON`
while `CalculationResource` and `ForecastResource` as `XML`.
- **"Agent"**, 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.
Every "agent" resource (package `org.glassfish.jersey.examples.rx.agent`)
invokes the following requests to the "remote" resource:
- Obtain **visited** 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)
- Obtain **recommended** destinations for a user. Requests obtaining
**visited** and **recommended** destinations are independent and can
be run in parallel.
- Obtain weather **forecasts** for recommended destinations. New
client request is invoked for every recommended destination.
Obtaining weather **forecasts** depend on actual
**recommended** destinations.
- Obtain trip **calculations** (prices) for recommended destinations.
New client request is invoked for every recommended destination.
Obtaining trip **calculations** depend on actual
**recommended** destinations. **forecast** and **calculation**
requests are independent on each other and can be invoked
in parallel.
Contents
--------
The mapping of the URI path space is presented in the following table:
URI path | Resource class | HTTP methods | Allowed values
-------------------------------------------------- | ------------------------------- | -------------- | ------------------------------------------------------------------------------
**_/rx/agent/sync_** | SyncAgentResource | GET | returns JSON
**_/rx/agent/async_** | AsyncAgentResource | GET | returns JSON
**_/rx/agent/observable_** | ObservableAgentResource | GET | returns JSON
**_/rx/agent/listenable_** | ListenableFutureAgentResource | GET | returns JSON
**_/rx/remote/destination/visited_** | DestinationResource | GET | returns JSON
**_/rx/remote/destination/recommended_** | DestinationResource | GET | returns JSON
**_/rx/remote/forecast/{destination}_** | ForecastResource | GET | destination - name of a country; returns XML (random value)
**_/rx/remote/calculation/from/{from}/to/{to}_** | CalculationResource | GET | from - name of a country, to - name of a country; returns XML (random value)
Application is Servlet 3 based, web.xml-less. Everything needed (resources/providers) is registered in `RxApplication`.
Sample Response
---------------
Agent responses look similar to the following one:
```javascript
{
"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
}
```
As can be seen the response entity contains 3 main elements: **visited**
(list of visited destinations), **recommended** (list of recommended
destinations + weather forecast and price calculation) and
**processingTime** (describing how long it took to obtain previous two
elements).
Running the Example
-------------------
Run the example as follows:
> mvn clean package jetty:run
This deploys current example using Jetty. You can access the application at:
- <http://localhost:8080/rx/agent/sync>
- <http://localhost:8080/rx/agent/async>
- <http://localhost:8080/rx/agent/listenable>
- <http://localhost:8080/rx/agent/observable>
Resources
---------
This examples is using the following (3-rd party) libraries:
**RxJava** by Netflix
- [GitHub](https://github.com/ReactiveX/RxJava)
- [GitHub.Wiki](https://github.com/ReactiveX/RxJava/wiki)
- [JavaDoc](http://reactivex.io/RxJava/javadoc/)
**Guava** by Google
- [Homepage](https://code.google.com/p/guava-libraries/)
- [ListenableFuture Explained](https://code.google.com/p/guava-libraries/wiki/ListenableFutureExplained)
- [JavaDoc](http://docs.guava-libraries.googlecode.com/git/javadoc/ind
没有合适的资源?快使用搜索试试~ 我知道了~
jersey 官方例子
共668个文件
java:427个
xml:103个
md:61个
2星 需积分: 6 11 下载量 143 浏览量
2016-09-04
19:26:06
上传
评论
收藏 1.51MB ZIP 举报
温馨提示
jersey-examples-2.23.2-all 官方例子 jersey-examples-2.23.2-alljersey-examples-2.23.2-all
资源推荐
资源详情
资源评论
收起资源包目录
jersey 官方例子 (668个子文件)
server.cert 1KB
client.cert 1KB
client.cert 1KB
bootstrap.min.css 101KB
bootstrap-responsive.min.css 16KB
main.css 2KB
style.css 2KB
main.css 2KB
MainWindow.form 18KB
MainWindow.form 14KB
hello.ftl 2KB
FreemarkerResource.ftl 2KB
hello-default-model.ftl 2KB
GroovyResourceTest.groovy 3KB
NewGroovyScript.groovy 3KB
GroovyResource.groovy 2KB
index.html 7KB
contact.html 6KB
index.html 6KB
index.html 5KB
index.html 5KB
index.html 5KB
form.html 4KB
index.html 3KB
index.html 3KB
index.html 2KB
index.html 2KB
MainWindow.java 24KB
MainWindow.java 21KB
ExtendedWadlWebappOsgiTest.java 18KB
AbstractWebAppTest.java 18KB
AsyncResourceTest.java 16KB
ManagedAsyncResourceTest.java 15KB
ItemStoreResourceTest.java 14KB
ContactCardTest.java 12KB
AbstractHttpServiceTest.java 12KB
ListenableFutureAgentResource.java 11KB
HelloWorldTest.java 11KB
App.java 10KB
App.java 10KB
ItemStoreResource.java 10KB
AsyncAgentResource.java 10KB
App.java 9KB
ServerSentEventsTest.java 9KB
ExtendedWadlWebappTest.java 9KB
BookmarkEntity.java 9KB
BookmarkEntity.java 9KB
Helper.java 9KB
PersonResourceTest.java 9KB
MainTest.java 8KB
ObservableAgentResource.java 8KB
TwitterAggregator.java 8KB
ExceptionMappingTest.java 8KB
TaskResource.java 8KB
WebAppFelixTest.java 8KB
JsonJettisonTest.java 8KB
UserEntity.java 8KB
UserEntity.java 8KB
Main.java 8KB
JaxbTest.java 7KB
SparklinesResource.java 7KB
RestrictedResourceTest.java 7KB
MainTest.java 7KB
BookmarkTest.java 7KB
BookmarkTest.java 7KB
MultiPartWebAppTest.java 7KB
JsonProcessingResourceTest.java 7KB
ExceptionResource.java 7KB
JaxrsTypeInjectionTest.java 7KB
ItemsRepresentation.java 6KB
ManagedBeanWebAppTest.java 6KB
ItemResource.java 6KB
ClipboardDataProvider.java 6KB
Activator.java 6KB
DomainResource.java 6KB
RequestScopedResourceTest.java 6KB
ToneGenerator.java 6KB
PatchingInterceptor.java 6KB
JacksonTest.java 6KB
UserResource.java 6KB
EntityStore.java 6KB
TraceSupportTest.java 6KB
ResourcesTest.java 6KB
App.java 6KB
SecurityFilter.java 6KB
UserResource.java 6KB
ClipboardTest.java 6KB
StorageService.java 6KB
BlockingPostChatResource.java 6KB
HttpPatchTest.java 6KB
Jackson1Test.java 6KB
Server.java 6KB
FireAndForgetChatResource.java 6KB
FlightType.java 6KB
BookmarkEntityPK.java 6KB
BookmarkEntityPK.java 6KB
BookmarkResource.java 5KB
App.java 5KB
MyApplication.java 5KB
App.java 5KB
共 668 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
- qq_378825082017-07-07不知道怎么用
- mnlll2019-12-29还可以吧,能用上
zhousenshan
- 粉丝: 624
- 资源: 210
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功