简体   繁体   English

如何在内置Grizzly的Jersey应用程序上获取HTTP请求方法?

[英]How to get the HTTP request method on a Grizzly-embedded Jersey application?

I am working on a JAX-RS application. 我正在研究JAX-RS应用程序。 Before, I had it as a WAR mounted on a Tomcat server and I was obtaining the HTTTP Request Method using: javax.servlet.http.HttpServletRequest.getMethod() . 以前,我将它作为WAR挂载在Tomcat服务器上,并使用以下方法获取HTTTP请求方法: javax.servlet.http.HttpServletRequest.getMethod()

However, now I'm working with an embedded Grizzly server on my application and have found the following error on startup: 但是,现在我在应用程序上使用嵌入式Grizzly服务器,并且在启动时发现以下错误:

Missing dependency for constructor public wci.api.resource.AudioSessionResource(javax.servlet.http.HttpServletRequest) at parameter index 0

All my resources extends a MyHappyCustomResource class that has a constructor which receives an HttpServletRequest , provided by the resource constructor via Injection. 我所有的资源都扩展了MyHappyCustomResource类,该类具有一个构造函数,该构造函数接收HttpServletRequest ,它由资源构造函数通过注入提供。

This is an example of a resource constructor, the super call is from MyHappyCustomResource : 这是资源构造函数的示例, super调用来自MyHappyCustomResource

import javax.servlet.http.HttpServletRequest;

public AudioSessionResource(@Context HttpServletRequest request) {
    super(request);
    this.dao = new AudioSessionDao(this.sessionManager.getCurrentSession());
}

Right now I need this just to get the HTTP-Method so, any other or more correct way to do it it's appreciated. 现在,我只需要这个就可以获取HTTP方法,因此,我们欢迎其他任何或更正确的方法来使用它。

The solution was to use Grizzly's Request class as told by this page on the Grizzly official site: 解决方案是使用Grizzly官方网站上此页面所述的Grizzly的Request类:

https://grizzly.java.net/httpserverframework.html https://grizzly.java.net/httpserverframework.html

Similar abstractions to those offered by the Servlet specification: HttpHandler (Servlet), Request (HttpServletRequest), Response (HttpServletResponse). 与Servlet规范提供的抽象类似:HttpHandler(Servlet),Request(HttpServletRequest),Response(HttpServletResponse)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM