I want to modify an object that has already been populated with JacksonMapper and add the IP and Referrer URL to it automatically, but the request is always null because it isn't found in the attributes array. Am I doing something wrong?
ApiController.java
@RequestMapping(value="/member/follow")
public @ResponseBody IHttpResponse follow(@RequestBody FollowRequest request) {
return request.getHttpResponse();
}
ApiRequestWrapper.js
public class ApiRequestWrapper extends HttpServletRequestWrapper
{
public ApiRequestWrapper(HttpServletRequest request) {
super(request);
if(this.getAttribute("request") instanceof IHttpRequest)
{
IHttpRequest httpRequest = (IHttpRequest) this.getAttribute("request");
if(httpRequest != null)
{
httpRequest.setIp(request.getRemoteAddr());
httpRequest.setReferrer(request.getLocalName());
}
}
}
}
Web.xml
<filter>
<filter-name>apiFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>apiFilter</filter-name>
<url-pattern>/api/*</url-pattern>
</filter-mapping>