Jersey(1.19.1) - Client API, Ease of use and reusing JAX-RS artifacts
Since a resource is represented as a Java type it makes it easy to configure, pass around and inject in ways that is not so intuitive or possible with other client-side APIs.
The Jersey Client API reuses many aspects of the JAX-RS and the Jersey implementation such as:
- URI building using UriBuilder and UriTemplate to safely build URIs;
- Support for Java types of representations such as
byte[]
,String
,InputStream
,File
,DataSource
and JAXB beans in addition to Jersey specific features such as JSON support and MIME Multipart support. - Using the builder pattern to make it easier to construct requests.
Some APIs, like the Apache HTTP client or java.net.HttpURLConnection, can be rather hard to use and/or require too much code to do something relatively simple.
This is why the Jersey Client API provides support for wrapping HttpURLConnection and the Apache HTTP client. Thus it is possible to get the benefits of the established implementations and features while getting the ease of use benefit.
It is not intuitive to send a POST request with form parameters and receive a response as a JAXB object with such an API. For example with the Jersey API this is very easy:
Form f = new Form();
f.add("x", "foo");
f.add("y", "bar"); Client c = Client.create();
WebResource r = c.resource("http://localhost:8080/form"); JAXBBean bean = r.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
.accept(MediaType.APPLICATION_JSON_TYPE)
.post(JAXBBean.class, f);
In the above code a Form is created with two parameters, a new WebResource instance is created from a Client then the Form
instance is POST
ed to the resource, identified with the form media type, and the response is requested as an instance of a JAXB bean with an acceptable media type identifying the Java Script Object Notation (JSON) format. The Jersey client API manages the serialization of the Form
instance to produce the request and de-serialization of the response to consume as an instance of a JAXB bean.
If the code above was written using HttpURLConnection
then the developer would have to write code to serialize the form sent in the POST request and de-serialize the response to the JAXB bean. In addition further code would have to be written to make it easy to reuse the same resource “http://localhost:8080/form” that is encapsulated in the WebResource
type.
Jersey(1.19.1) - Client API, Ease of use and reusing JAX-RS artifacts的更多相关文章
- Jersey(1.19.1) - Client API, Uniform Interface Constraint
The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. I ...
- Jersey(1.19.1) - Client API, Overview of the API
To utilize the client API it is first necessary to create an instance of a Client, for example: Clie ...
- Jersey(1.19.1) - Client API, Using filters
Filtering requests and responses can provide useful functionality that is hidden from the applicatio ...
- Jersey(1.19.1) - Client API, Testing services
The Jersey client API was originally developed to aid the testing of the Jersey server-side, primari ...
- Jersey(1.19.1) - Client API, Security with Http(s)URLConnection
With Http(s)URLConnection The support for security, specifically HTTP authentication and/or cookie m ...
- Jersey(1.19.1) - Client API, Proxy Configuration
为 Jersey Client 设置代理,可以使用带有 ClientHandler 参数的构造方法创建 Client 实例. public static void main(String[] args ...
- docker报Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.19)
docker version Client: Version: 17.05.0-ce API version: 1.24 (downgraded from 1.29) Go version: go1. ...
- Jersey(1.19.1) - JSON Support
Jersey JSON support comes as a set of JAX-RS MessageBodyReader<T> and MessageBodyWriter<T&g ...
- Jersey(1.19.1) - Hello World, Get started with Jersey using the embedded Grizzly server
Maven Dependencies The following Maven dependencies need to be added to the pom: <dependency> ...
随机推荐
- CSS 背景图片的定位和缩放
在 CSS 中,利用 background-image 属性我们可以指定元素的背景图片,例如: .example { background-image: url(image/some.png); ba ...
- Enterprise Library 中加密数据库连接字符串
看了SHY520写的关于Data Access Application Block的文章,写得不错,忽略了一点就是如何去加密数据库连接字符串,这儿我简单的介绍一下.我们知道,在Enterprise L ...
- 转移部分博客到CSDN之中
之前的文章一直发布在个人博客ivyxjc.xyz中, 现在将一部分博客移到csdn博客中.
- Sonatype Nexus 搭建Maven 私服
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- PostgreSQL的 initdb 源代码分析之十二
继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...
- PostgreSQL的initdb 源代码分析之五
接前面,继续分析: putenv("TZ=GMT") 设置了时区信息. find_other_exec(argv[0], "postgres", PG_BACK ...
- PI-安装SoapUI on Windows
SoapUI是测试webservice连通性的工具,请见博文:http://www.dekevin.com/?p=1807 当你下载好了SOAPUI的安装程序之后,就可以进行程序的安装了,怎么来进行S ...
- exosip
exosip针对UA是对osip进行扩展,oSIP不提供不论什么高速产生请求消息和响应消息的方法,全部请求消息和响应消息的形成必须调用一组sip message api来手动组装完毕,所以作者在osi ...
- Android Studio升级后projectBuild failed.
近期在升级Android Studio后,发现原先能编译通过的project,突然就编译只是了,原因是生成的AndroidManifest.xml文件里有乱码. 升级后: android studio ...
- oracle internal :VIEW: X$KCBLDRHIST - Direct Read HISTory
WebIV:View NOTE:159900.1 Note (Sure) - Note Mods - Note Refs Error ORA 600 TAR TAR-Info Bug B ...