jersey发布web service ,如何获取 发送的inputstream中的内容?
时间:2009-11-08
来源:互联网
我用jersey实现webservice,服务器端获取不到流里面的内容。高手求解
web service pojo :
@POST
@Path("reurl")
@Consumes("application/xml") //提交内容为xml流
public Response returnResponse(InputStream is)
try {
byte[] buf = new byte[is.available()]; // the inputstream 's length is 0! i can't get the data from inputstream.
System.out.println(buf.length);
is.read(buf,0,buf.length);
System.out.println(new String(buf));
return Response.created(new URI("http://g.cn")).build();
} catch (URISyntaxException e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (IOException e1) {
throw new WebApplicationException(e1, Response.Status.INTERNAL_SERVER_ERROR);
}
}
客户端连接测试:测试通过。就是发送的xml内容服务器端获取不到。
String uri = "http://houfeng:8080/jerseyWebServiceTest/services/my/reurl";
final String addCustomerXML =
"<customer>" +
"<firstname>Joe</firstname>" +
"<lastname>Schmo</lastname>" +
"<zipcode>98042</zipcode>" +
"</customer>";
InputStream bais = new ByteArrayInputStream(addCustomerXML.getBytes());
WebResource resource = client.resource(uri);
ClientResponse response = resource.type(MediaType.APPLICATION_XML).entity(addCustomerXML).post(ClientResponse.class);
System.out.println("response status:"+response.getStatus());
System.out.println("response "+response.getLocation().toString());
a thinks in advance!
web service pojo :
@POST
@Path("reurl")
@Consumes("application/xml") //提交内容为xml流
public Response returnResponse(InputStream is)
try {
byte[] buf = new byte[is.available()]; // the inputstream 's length is 0! i can't get the data from inputstream.
System.out.println(buf.length);
is.read(buf,0,buf.length);
System.out.println(new String(buf));
return Response.created(new URI("http://g.cn")).build();
} catch (URISyntaxException e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (IOException e1) {
throw new WebApplicationException(e1, Response.Status.INTERNAL_SERVER_ERROR);
}
}
客户端连接测试:测试通过。就是发送的xml内容服务器端获取不到。
String uri = "http://houfeng:8080/jerseyWebServiceTest/services/my/reurl";
final String addCustomerXML =
"<customer>" +
"<firstname>Joe</firstname>" +
"<lastname>Schmo</lastname>" +
"<zipcode>98042</zipcode>" +
"</customer>";
InputStream bais = new ByteArrayInputStream(addCustomerXML.getBytes());
WebResource resource = client.resource(uri);
ClientResponse response = resource.type(MediaType.APPLICATION_XML).entity(addCustomerXML).post(ClientResponse.class);
System.out.println("response status:"+response.getStatus());
System.out.println("response "+response.getLocation().toString());
a thinks in advance!
作者: heihei0923 发布时间: 2009-11-08
该回复于2010-08-06 10:59:09被版主删除
- 对我有用[0]
- 丢个板砖[0]
- 引用
- 举报
- 管理
- TOP
|
#2楼 得分:0回复于:2009-11-09 13:23:42
|
作者: happy664618843 发布时间: 2009-11-08
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
==========
楼主 修改一下 这个地方
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
xxx.type(MediaType.APPLICATION_FORM_URLENCODED).entity(...).post(String.class);
不过传输的数据有字符限制, 搞不懂为啥
作者: heihei0923 发布时间: 2009-11-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28