您可使用服务器过滤器并获取HTTPRequest物体数据。
这方面有两个简单步骤。
1st- define your filter servlet
public class YourRequestFilter implements ContainerRequestFilter {
@Override
public ContainerRequest filter(ContainerRequest request) {
if( request.getRequestHeader("userName") != null ) {
String username = request.getRequestHeader("username").get(0);
}
}
}
http://www.xml。
<servlet>
<servlet-name>name</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.odata4j.jersey.producer.resources.ODataApplication</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.wipro.eim.middleware.framework.oauth.filter.OAuthContainerRequestFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.wipro.eim.middleware.framework.oauth.filter.YourRequestFilter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>