0

JBoss 7 環境で REST サービスを実行しました。ガイドが示唆するように javax.ws.rs.core.Application を使用し、 @ApplicationPath を使用します。

したがって、次の REST サービスのコードは正しく、パスも正しいはずです。

@Path(value="/service") 
@ApplicationPath("/app")  

public class MioRESTserv extends Application {  


      @GET
       @Path(value="/echo/{message}")
       public String answer(@PathParam(value="message") String message) {
          return "Answer " + message;
       }

       @POST
       @Path(value="/ordering")
       @Consumes(value="application/json")
       @Produces(value="application/xml")
       public Output ordering(Input input) {
          Arrays.sort(input.getVector());
          return new Output(input.getVector());
       }
    }

最初のRestサービスの「回答」は正常に機能しています。しかし、次の html ページ (コンシューマーのように使用) で JQuery を使用して POST REST サービスの「順序付け」をテストしようとすると、rensponse が間違っています (以下を参照)。

$(document).ready(function() {
        $( "input[type=submit]" ).click(function(event) {   //$('#submit').click(function() {
            var string = $('#numbers').val();
            if (string.indexOf(',') != -1) {  alert("in " + string);

            $.post({  
                    url: "http://localhost:8090/PAX_IN_REST/app/service/sorting",
                    contentType: "application/json",
                    data: '{"vector" : [' + string + ']}',                  
                    success: function(data, textStatus, jqXHR) {

                    },
                    error: function(jqXHR, textStatus, errorThrown){
                        alert("errorThrown=" + errorThrown);
                    }
                }); 
            } else {
                alert('Bad format! Must be x,y,z');
            }
        });
});

パスは正しいです。「悪いフォーマット」をテストすると、うまく機能しています。正しい入力 (たとえば、1、3、6、7、2 の数字) を使用すると、「順序付け」 RESTService がtype=POST またはmethod=POSTで、アラートによる応答は次のようになり404 The requested resource (/REST_IN_PAX/[object%20Object]) is not availableます。

誰でも私を助けることができますか?ありがとう

4

1 に答える 1

0

@ApplicationPath注釈用に別のファイルが本当に必要です。

/**
 * Let the container know that we have a JAX-RS application.
 */
@ApplicationPath("/app")
public class AppResources extends Application {

}

次に、リソース用の別のファイル:

@Path("/service") 
public class MioRESTserv {  

   @GET
   @Path(value="/echo/{message}")
   public String answer(@PathParam(value="message") String message) {
      return "Answer " + message;
   }

   @POST
   @Path(value="/ordering")
   @Consumes(value="application/json")
   @Produces(value="application/xml")
   public Output ordering(Input input) {
      Arrays.sort(input.getVector());
      return new Output(input.getVector());
   }
}

始めるのに役立つこのリンクをチェックしてみてください: http://www.mastertheboss.com/resteasy/resteasy-tutorial

于 2013-08-01T17:00:09.360 に答える