首页 > 解决方案 > 使用 Jersey 发出 Post 请求时服务器端的 Classcast 异常

问题描述

我正在调用使用 Dropwizard 开发的 Rest 服务,并且能够成功调用 Get 请求,但是将请求发布到同一服务(另一个端点离场)不起作用。它给出了 500 服务器错误,并且在日志中我看到以下异常:

Classcast exception: io.dropwizard.jetty.BiDiGzipHandler$WrappedInputStream cannot be cast to org.eclipse.jetty.server.request

这是我如何拨打电话的片段:

RequestPojo pojo = new RequestPojo (123, "test");
ObjectMapper mapper = new ObjectMapper();
String json=null;
try{
  json = mapper.writeValueAsString(pojo);
}
catch(Exception e){
   //loggers
}
Response response = target.request().accept(MediaType.Application_JSON).post(Entity.json(jsonString);
String id = response.readEntity(new GenericType<Map>(){}.get("generatedID"));

我几乎看不到任何帖子上的这个例外。有人可以帮我解决这个例外。谢谢你的帮助。

标签: dropwizardembedded-jettyjersey-client

解决方案


推荐阅读