+ -
当前位置:首页 → 问答吧 → jersey发布web service ,如何获取 发送的inputstream中的内容?

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!

作者: heihei0923   发布时间: 2009-11-08

该回复于2010-08-06 10:59:09被版主删除

  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
#2楼 得分:0回复于:2009-11-09 13:23:42
我自己也顶。有没有用过 jersey的呀

作者: 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

热门下载

更多