获取SEVERE:找不到媒体类型= application / json的MessageBodyWriter,type = class org.json.JSONObject

时间:2016-03-29 12:23:08

标签: java web-services rest restful-authentication

我只是编写一个客户端方法并调用POST方法。但我面临以下错误。

当我测试webservices url虽然postman工作。只在我的客户端代码中给出错误。

2016年3月29日下午5:39:27 org.glassfish.jersey.message.internal.WriterInterceptorExecutor $ TerminalWriterInterceptor aroundWriteTo 严重:找不到媒体类型= application / json,type = class org.json.JSONObject,genericType = class org.json.JSONObject的MessageBodyWriter。 线程" main"中的例外情况org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:找不到媒体类型= application / json的typeBodyWriter,type = class org.json.JSONObject,genericType = class org.json.JSONObject。     at org.glassfish.jersey.message.internal.WriterInterceptorExecutor $ TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:247)     在org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)     在org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)     在org.glassfish.jersey.client.ClientRequest.doWriteEntity(ClientRequest.java:517)     在org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:499)     在org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:388)     在org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)     在org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)     在org.glassfish.jersey.client.JerseyInvocation $ 2.call(JerseyInvocation.java:700)     在org.glassfish.jersey.internal.Errors.process(Errors.java:315)     在org.glassfish.jersey.internal.Errors.process(Errors.java:297)     在org.glassfish.jersey.internal.Errors.process(Errors.java:228)     在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)     在org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:696)     在org.glassfish.jersey.client.JerseyInvocation $ Builder.method(JerseyInvocation.java:448)     在org.glassfish.jersey.client.JerseyInvocation $ Builder.post(JerseyInvocation.java:349)     at test.restful.webservices.TESTClient.testUpdateUser(TESTClient.java:58)     在test.restful.webservices.TESTClient.main(TESTClient.java:89)

这是我的代码:

  private void testUpdateUser(){
      FormBean sample = new FormBean();  
      sample.setFORM_LONG_DESC("FrmIssCMNEW");       
      JSONObject jo = new JSONObject(sample);
      System.out.println("Json ===>>"+jo);
      String callResult = client
          .target(REST_SERVICE_URL)
          .path("/Add")
          .queryParam("formcode", "FrmIssCMNEW")
          .queryParam("dsnID","OFSBGRC")
          .queryParam("version","1")
          .queryParam("longdesc","testing by me")
         .request(MediaType.TEXT_PLAIN)
         .post(Entity.entity(jo,MediaType.APPLICATION_JSON),
            String.class);

  Post Method:
  @POST
  @Produces(MediaType.TEXT_PLAIN)   
  @Path("/Add")
  public String save
  (     @QueryParam("formcode") String formcode,
        @QueryParam("version") int version,
        @QueryParam("dsnID") String dsnID,
        @QueryParam("longdesc") String longdesc)
    {   
       /* my code */
           return "Display from POST method  <> "+"FormID :"+fb.getFORM_ID()+" -->> FormLong Description :"+fb.getFORM_LONG_DESC();

   }

提前致谢。

0 个答案:

没有答案
相关问题