English 中文(简体)
如何在数据服务提供者查阅HttpServletRequest
原标题:How to access HttpServletRequest in Odata service provider

I am using Odata4j for exposing my services and i need to access HttpServletRequest object from my service provider. Is there is a way yo do this. I tried using @Context annotation to inject the object but it is giving null

问题回答

您可使用服务器过滤器并获取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>  




相关问题
WCF Data Service - Proxy mid-tier service

The project we are working on is a classic 3 tiered architecture. tier 1 being the database server, tier 2 the application services and tier 3 the presentation tier (a web site). In the application ...

PHP Download script (Locally)

Im looking for a script that will take OData feed and download some .wmv files based on the filenames held within the OData? Can anyone help?

How would you implement API key in WCF Data Service?

Is there a way to require an API key in the URL / or some other way of passing the service a private key in order to grant access to the data? I have this right now... using System; using System....

How do I interact with OData from Java?

OData is Microsoft s repackaging of its Astoria (now WCF Data Services) RESTful query/update protocol. If I want to use Java to create an OData compatible data source, how do I do that? Similarly, if ...

How to use "SelectMany" with DataServiceQuery<>

I have the following DataServiceQuery running agaist an ADO Data Service (with the update installed to make it run like .net 4): DataServiceQuery<Account> q = (_gsc.Users .Where(c =...

热门标签