On the client side, I use Ajax.post (jquery 1.5) with json. On the server side, I use rest restaasy-jaxrs-2.0.1.GA. I found somewhere that I should add a couple of headers to the server response, and I did with the following filter:
public void doFilter( ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { MyServletRequestWrapper httpReq = new MyServletRequestWrapper((HttpServletRequest)req); HttpServletResponse httpRes = (HttpServletResponse)res; HttpSession session = httpReq.getSession(); httpRes.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); httpRes.addHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); if (((HttpServletRequest) req).getMethod().equals("OPTIONS")){ httpRes.addHeader(ACCESS_CONTROL_ALLOW_METHODS, "GET, POST, OPTIONS, PUT, DELETE"); httpRes.addHeader(ACCESS_CONTROL_ALLOW_HEADERS, "content-type, x-requested-with, x-requested-by"); } filterChain.doFilter(httpReq, httpRes); }
It works great because every GET response is added over the headers. The problem occurs when I want to use a POST request. When I use Ajax.post, the server first receives the OPTIONS request, and I have the following error:
Failed executing OPTIONS [REST_PATH] org.jboss.resteasy.spi.DefaultOptionsMethodException: No resource method found for options, return OK with Allow header
To solve the error described above, I tried to add the invoke method with the same path as POST ([REST_PATH]), but with the @OPTION annotation. In this case, javac told me that the character: OPTIONS of the class cannot be found, even there is OPTION.class in the attached jaxrs library.
Any ideas to fix this? I would really appreciate any tips.