Jersey Client Post Bean参数
代码:
public static void main(String[] args) {
Student st = new Student("Adriana", "Barrer", 12, 9);
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(
JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
WebResource webResource = client
.resource("http://localhost:8080/JerseyJSONExample/rest/jsonServices/send");
ClientResponse response = webResource.accept("application/json")
.type("application/json").post(ClientResponse.class, st);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Server response .... \n");
System.out.println(output);
}
资源中代码:
@POST
@Path("/send")
@Consumes(MediaType.APPLICATION_JSON)
public Response consumeJSON( Student student ) {
System.out.println("student :"+student);
System.out.println("student content:"+student.getFirstName());
String output = student.toString(); return Response.status(200).entity(output).build();
}
实体bean中必须要有默认的空构造器。
Jersey Client Post Bean参数的更多相关文章
- Jersey Client传递中文参数
客户端需要客户端的包: <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jerse ...
- jersey client上传下载文件
jersey client上传文件demo File file = new File("/tmp/test.jpg"); System.out.println(file.exist ...
- RESTful Java client with Apache HttpClient / URL /Jersey client
JSON example with Jersey + Jackson Jersey client examples RESTful Java client with RESTEasy client f ...
- 由hbase.client.scanner.caching参数引发的血案(转)
转自:http://blog.csdn.net/rzhzhz/article/details/7536285 环境描述 Hadoop 0.20.203.0Hbase 0.90.3Hive 0.80.1 ...
- Spring <bean> 参数意义
1.id bean的唯一标识, 2.class 类的完全限定名, 3.parent 父类bean定义的名字. 如果没有任何声明,会使用父bean,但是也可以重写父类.重写父类时,子bean 必须与父b ...
- tomcat web容器中,调用jersey client端报错的处理
在web工程中,写main方法,运行ok. 发布到tomcat中后,报错. javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/r ...
- 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 ...
- Jersey(1.19.1) - Client API, Proxy Configuration
为 Jersey Client 设置代理,可以使用带有 ClientHandler 参数的构造方法创建 Client 实例. public static void main(String[] args ...
- 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 ...
随机推荐
- Windows下搭建appium(Android版)
1.安装node.js 说明:安装node.js是为了可以使用它的npm,可以用npm install很方便的安装它包含的包,appium server使用node.js编写的 下载地址:https: ...
- Connections in Galaxy War(逆向并查集)
Connections in Galaxy War http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3563 Time Limit ...
- 【校招面试 之 C/C++】第10题 C++不在构造函数和析构函数中调用虚函数
1.不要在构造函数中调用虚函数的原因 在概念上,构造函数的工作是为对象进行初始化.在构造函数完成之前,被构造的对象被认为“未完全生成”.当创建某个派生类的对象时,如果在它的基类的构造函数中调用虚函数, ...
- 13-前端不通路径同一个请求访问同一个页面时,有时样式没有加载出来(jss,image,css)
通过如下方式访问同一个网站时,下面一个可以加载样式,而下面一个加载的页面却没有样式,思考良久没有想通,当时也忘记了用浏览器看下 css,js,image的请求路径,其实在前端页面里面我直接: 这样引 ...
- VBA json parser[z]
http://www.ediy.co.nz/vbjson-json-parser-library-in-vb6-xidc55680.html VB-JSON: A Visual Basic 6 (VB ...
- jquery获取radio单选框的值
1.获取原有单选框的值 var value=$("input[name='is_setting']:checked").val(); 2.获取重选后的单选框的值 <tr> ...
- [SoapUI] 将科学计数法转化为普通数字,并且只保留小数点后几位
方案一: import java.text.NumberFormat class CompareHashMap { def regEx_Numeric = '-?[1-9]\\d*$|-?([1-9] ...
- Netty 零拷贝(三)Netty 对零拷贝的改进
Netty 零拷贝(三)Netty 对零拷贝的改进 Netty 系列目录 (https://www.cnblogs.com/binarylei/p/10117436.html) Netty 的&quo ...
- 使用JConsole监控HBase内存状态
使用JConsole或者VisualVM等工具监控HBase状态时,需要修改HBase的配置文件,以解决随机端口问题. 文件名:hbase-env.sh export HBASE_JMX_BASE=& ...
- jQuery Datepicker 插件遇到问题
Datepicker ver 1.7.3 浏览更多 常用设置 //禁用今天之前时间 $(".datePicker").datepicker('option', { minDate ...