Resteasy MessageBodyReader 错误消息
所以,我有一个 REST 应用程序,如下所示:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/getpartners")
public HashMap<Integer, PartnerEntityDTO> getPartners() throws NamingException {
//body
}
我使用 ResteasyClient 框架实现了我的 REST 客户端,看起来像下面根据 文档
@GET
@Path("/getpartners")
@Produces(MediaType.APPLICATION_JSON)
HashMap<Integer, PartnerEntityDTO> getPartners();
要点是,我想从 REST 服务在客户端获取 HashMap,并且无需任何操作即可获取它如果我使用浏览器,则会出现问题。但如果我使用 Swing 客户端,就会出现问题。我在我的 swing 客户端中使用此代码来处理调用和响应。
//Resteasy client
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
PartnerServiceClientInterface partnerServiceClientInterface = ProxyFactory.create(PartnerServiceClientInterface.class, "http://localhost:8080/dilib/partners");
**//Sources.java:66**
String restResponse = partnerServiceClientInterface.getPartners().toString();
JsonParser jsonParser = new JsonParser();
JsonArray partnerDataInJson = jsonParser.parse(restResponse).getAsJsonArray();
int size = partnerDataInJson.size();
Gson gson = new Gson();
HashMap<Integer, PartnerEntityDTO> partnerDataFromServer = new HashMap<Integer, PartnerEntityDTO>();
for(int i = 0; i < size; i++) {
PartnerEntityDTO deserializedPartnerEntityDTO = gson.fromJson(partnerDataInJson.get(i), PartnerEntityDTO.class);
partnerDataFromServer.put(i, deserializedPartnerEntityDTO);
}
错误消息是这样的:
Exception in thread "AWT-EventQueue-0" org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type application/json and type java.util.HashMap<java.lang.Integer, com.sayusiando.java.dilib.dilibcore.server.entities.core.dto.PartnerEntityDTO>
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:522)
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:513)
at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:414)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:376)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:349)
at org.jboss.resteasy.client.core.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:54)
at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:120)
at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:88)
at $Proxy16.getPartners(Unknown Source)
at com.sayusiando.java.dilib.client.swing.modules.core.fields.sources.Sources.processPartnerDataFromRESTServer(Sources.java:66)
at com.sayusiando.java.dilib.client.swing.modules.core.fields.sources.Sources.initComponents(Sources.java:45)
at com.sayusiando.java.dilib.client.swing.modules.core.fields.sources.Sources.<init>(Sources.java:26)
at com.sayusiando.java.dilib.client.swing.modules.core.DilibCoreSwingClient.valueChanged(DilibCoreSwingClient.java:155)
at javax.swing.JTree.fireValueChanged(JTree.java:2820)
at javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3191)
at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:629)
at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1078)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:287)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:170)
at javax.swing.JTree.setSelectionPath(JTree.java:1598)
at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2311)
at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3520)
at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3459)
at java.awt.Component.processMouseEvent(Component.java:6285)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6053)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4651)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:616)
at java.awt.EventQueue$2.run(EventQueue.java:614)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
我用谷歌搜索了这个错误消息,并且 Resteasy 的文档是 Interceptors 部分的 linket,但我不清楚问题是什么。
感谢您提前提供任何帮助!
So, I have a REST application and looks like this:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/getpartners")
public HashMap<Integer, PartnerEntityDTO> getPartners() throws NamingException {
//body
}
I implemented my REST client using ResteasyClient framework and looks like quoted below according to the documentation
@GET
@Path("/getpartners")
@Produces(MediaType.APPLICATION_JSON)
HashMap<Integer, PartnerEntityDTO> getPartners();
The point is that, I would like to get an HashMap on client side from REST service and I get it without any issue if I'm usin a browser. But If I'm using swing client than something is wrong. I use this code in my swing client to handle the call and response.
//Resteasy client
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
PartnerServiceClientInterface partnerServiceClientInterface = ProxyFactory.create(PartnerServiceClientInterface.class, "http://localhost:8080/dilib/partners");
**//Sources.java:66**
String restResponse = partnerServiceClientInterface.getPartners().toString();
JsonParser jsonParser = new JsonParser();
JsonArray partnerDataInJson = jsonParser.parse(restResponse).getAsJsonArray();
int size = partnerDataInJson.size();
Gson gson = new Gson();
HashMap<Integer, PartnerEntityDTO> partnerDataFromServer = new HashMap<Integer, PartnerEntityDTO>();
for(int i = 0; i < size; i++) {
PartnerEntityDTO deserializedPartnerEntityDTO = gson.fromJson(partnerDataInJson.get(i), PartnerEntityDTO.class);
partnerDataFromServer.put(i, deserializedPartnerEntityDTO);
}
The error message is this:
Exception in thread "AWT-EventQueue-0" org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type application/json and type java.util.HashMap<java.lang.Integer, com.sayusiando.java.dilib.dilibcore.server.entities.core.dto.PartnerEntityDTO>
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:522)
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:513)
at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:414)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:376)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:349)
at org.jboss.resteasy.client.core.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:54)
at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:120)
at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:88)
at $Proxy16.getPartners(Unknown Source)
at com.sayusiando.java.dilib.client.swing.modules.core.fields.sources.Sources.processPartnerDataFromRESTServer(Sources.java:66)
at com.sayusiando.java.dilib.client.swing.modules.core.fields.sources.Sources.initComponents(Sources.java:45)
at com.sayusiando.java.dilib.client.swing.modules.core.fields.sources.Sources.<init>(Sources.java:26)
at com.sayusiando.java.dilib.client.swing.modules.core.DilibCoreSwingClient.valueChanged(DilibCoreSwingClient.java:155)
at javax.swing.JTree.fireValueChanged(JTree.java:2820)
at javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3191)
at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:629)
at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1078)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:287)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:170)
at javax.swing.JTree.setSelectionPath(JTree.java:1598)
at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2311)
at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3520)
at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3459)
at java.awt.Component.processMouseEvent(Component.java:6285)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6053)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4651)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:616)
at java.awt.EventQueue$2.run(EventQueue.java:614)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
I googled for this error message and the documentation of the Resteasy is linket at the Interceptors part, but it is not clear for me what is the problem.
Thanks for any help in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抛弃提供者在你的类路径中吗?如果您使用的是 Maven,请添加此依赖项:将${resteasy.version}
替换为您正在使用的版本。编辑:
来自 RestEASY文档:
工作测试用例:
Is the jettison provider in your classpath? If you are using maven, add this dependency:Replace${resteasy.version}
with the version you are using.EDIT :
From the RestEASY documentation:
Working testcase: