2012-01-22 35 views
0

我使用Jetty Web服務器和Jersey進行REST處理。接受所有的HTTP請求到一定的方法

我希望每個HTTP請求(我的服務器接收的)以/ hqsim開頭(不管後來會發生什麼),例如POST http://localhost:8080/hqsim/將被引導到某個方法(在我的示例中爲POST)。我試過@Path(「/」),@Path(「* /」),甚至沒有聲明任何@Path,但它不起作用。

我希望每個請求都會被引導到方法sendMessage

@Path("/hqsim") 
@Component 
@Scope("request") 
public class HQSimResource { 
    // init class logger 
    private static Logger logger = Logger.getLogger("audit." 
      + HQSimResource.class.getName()); 

    @POST 
    @Path("/*") 
    @Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML }) 
    public Response sendMessage(@Context final UriInfo uriInfo) { 
     // logger.debug("/sendMessage"); 
     System.out.println("Received Post"); 
     return Response.status(Response.Status.OK).build(); 
    } 
} 

回答

1

在功能級別上不需要@Path(/ *)。類級別的@Path(/ hqsim)就足夠了。

猜測: 通常REST資源位於您的Web應用程序下,如:http://localhost:8080/myWebApplication/hqsim。也許這是問題所在。

第二種選擇是,您在向Jersey註冊資源時遇到問題。

謝謝, Shay

相關問題