Restful Web サービスは初めてです。Jersey クライアント経由でサーバーにアクセスしたいと考えています。しかし、500エラーが発生しています。私がやろうとしているのは、クライアント エンドからテーブル名を送信し、テーブルの内容を JSON として取得することです。誰でもここでエラーを見つけることができますか?
これが私のクライアントエンドです
public JSONObject loadTable(String tablename) throws ClientProtocolException, IOException {
pathParams.add("tablename", tablename);
JSONObject jsontable = service.path("access").path("loadtable").queryParams(pathParams).get(JSONObject.class);
return jsontable;
}
これは私のサーバー側です
@Path("/loadtable")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
public JSONObject loadTable(@QueryParam("tablename") String tablename) throws Exception {
List<Pricing> pricing = new ArrayList<Pricing>();
try {
query = c.prepareStatement("select * from '" + tablename + "'");
ResultSet ets_rs = query.executeQuery();
while (ets_rs.next()) {
pricing.add(new Pricing(ets_rs.getString(1), ets_rs.getString(2), ets_rs.getString(3), ets_rs.getString(4), ets_rs.getString(5), ets_rs.getString(6)));
}
query.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (c != null) {
c.close();
}
}
JSONObject jsonTable = JsonConvert.getJsonFromPricing(pricing);
System.out.println(jsonTable);
return jsonTable;
}
サーバー側の Pricing クラスは、結果セットを JSON に変換します。
これはスタック トレースです。
Exception in thread "AWT-EventQueue-0" com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8080/ServerETS/resources/access/loadtable?tablename=prices returned a response status of 500
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:563)
at com.sun.jersey.api.client.WebResource.get(WebResource.java:179)
at Link.ClientLink.loadTable(ClientLink.java:60)
at Interfaces.Pricing.loadTable(Pricing.java:112)
at Interfaces.Pricing.<init>(Pricing.java:32)
at Interfaces.MainMenu.panelPricing(MainMenu.java:1026)
at Interfaces.AdminData.btnAdminDataOKActionPerformed(AdminData.java:150)
at Interfaces.AdminData.access$000(AdminData.java:26)
at Interfaces.AdminData$1.actionPerformed(AdminData.java:70)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6288)
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:4238)
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)
これはGlassFishサーバーログです
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class org.json.simple.JSONObject, and Java type class org.json.simple.JSONObject, and MIME media type application/json was not found
... 33 more