休息容易JQUERY 404

时间:2013-06-26 10:39:02

标签: jquery rest jboss7.x resteasy

我在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服务“排序”时(像消费者一样使用)我有错误的重新响应(见下文):

$(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的数字),使用type=POSTmethod=POST的“订购”RESTService,以警告方式回答:404 The requested resource (/REST_IN_PAX/[object%20Object]) is not available

任何人都可以帮助我吗?感谢

1 个答案:

答案 0 :(得分: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