2017-08-18 5 views
-1

ちょっと残っているjsonオブジェクトを残りのWebサービスに送信してから、特定のキーの値を取得してから、別の場所で使用される新しいjsonオブジェクトを返します。とにかく、私はサービスと通信しようとするとHTTP 204を取得しています。JsonObjectは、jsonObjectを送信しようとしているときにPOSTメソッドでHTTP 204を返します。

私の残りのサービスは、この

@Path("/example") 
public class PdfMaker { 

@POST 
@Path("/post") 
@Consumes(MediaType.APPLICATION_JSON) 
@Produces(MediaType.APPLICATION_JSON) 
public Response PruebasMet(JSONObject json) throws IOException, JSONException{ 
     try{ 
      String xml = json.getString("xml"); 
      String plantilla = json.getString("plant"); 

     //method that uses "xml" and "plant" and returns "pdf" 

     JSONObject response = new JSONObject(); 
     response.put("pdf", pdf); 

    return Response.status(200).entity(pdfb64.toString()).build(); 
     }catch(Exception e){ 
      e.getStackTrace(); 
      return null; 
     } 

} 

のように見えると私は、この

public class Jersey { 

public static String baseuri = "http://localhost:8080/PdfMakerGF/rest/example/post"; 

public static void main(String[] args) { 

    try { 
     ClientConfig config = new DefaultClientConfig(); 
     Client client = Client.create(config); 
     WebResource webResource = client.resource(baseuri); 
     JSONObject objTest = new JSONobject(); 
     objTest.put("xml","Data1"); 
     objTest.put("plan", "Data2"); 


     ClientResponse res = webResource.header("Content-Type","application/json;charset=UTF-8") 
     .post(ClientResponse.class, objTest.toString()); 

     System.out.println("output..." + "\n"); 

     System.out.println("Answer "+res); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

と通信しようとしている。しかし、私が受け取ることに応答がこの1件の

回答POSTでありますhttp://localhost:8080/PdfMakerGF/rest/example/post は204の応答ステータスを返しました。

明らかに何か間違っていますが、それが何であるかはわかりません。 私はこれに固執しています。どんな種類の助けにも感謝します。 私はnetbeans 8.1、Glassfish 4.1、Jerseyを使用しています。 ありがとう

+0

Aを提供しているという情報を持っていますlsoサービスはxml形式で証明され、正常に動作します –

+1

サーバーログで例外をチェックしましたか? – sisyphus

+0

郵便配達員で同じリクエストを送信しようとしましたか? – ngc4151

答えて

0

オーケーはとてもfinalyそれは私が変更するために必要なものに動作し、このように取り組んで終わる、サービスは私の場合は内部クラスで、データをrecivingれた方法でした。..

Class Aux{ 
String xml; 
String plant; 
//generate gettes and setters :) 
} 
@Path("/example") 
public class PdfMaker { 
@POST 
@Path("/post") 
@Consumes(MediaType.APPLICATION_JSON) 
@Produces(MediaType.APPLICATION_JSON) 
public Response PruebasMet(Aux json) throws IOException, 
JSONException{ 
    try{ 
    String xml = json.getXml(); 
    String plant = json.getPlant(); 
    //method that uses "xml" and "plant" and returns "pdf" 

    JSONObject response = new JSONObject(); 
    response.put("pdf", pdf); 

return Response.status(200).entity(pdf)).build(); 
    }catch(Exception e){ 
     e.getStackTrace(); 
     return null; 
    } 

}

とクライアントが..です

Client client = new Client(); 
    WebResource wresource = client.resource("http://localhost:8080/PdfMakerGF/rest/example/post"); 
    JSONObject json = new JSONObject(); 
    json.put("xml", DATA); 
    json.put("plant", DATA); 

     ClientResponse response = 
     wresource.type("application/json").post(ClientResponse.class, 
     json.toString()); 

     out = response.getEntity(String.class); 
     System.out.println("RES = "+response); 
     System.out.println("OUT = "+out); 

アウトサービスが

+0

私はこれが誰かを助けることを望む –

0

サーバーで例外が発生し、catchブロックに行くと、HTTP 204(No Content)に対応するnullが返されます。シジパスがコメントしたように、サーバーの標準出力には例外があるはずです。

だから、あなたはおそらく行う必要があります。

  • リターン異なる応答コード(例えばINTERNAL_SERVER_ERRORまたは BAD_REQUEST)サーバー・コードは 例外に
0
を投げている理由catchブロック
  • チェックイン

    ほとんどの場合、例外が発生します。私はあなたが「植物」を1つの場所に、そして「計画」を別の場所に持っているからだと思います。

  • +0

    を取得した唯一の情報は、とにかくthaksあなたの馬のために –

    関連する問題