Actually gwt RPC uses requestbuilder as its low-level transport, so cors
works with rpc without any problem.

Here you have an example of cors with gwt rpc.

- In the client side you have to change the RPC service url
 GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
 ((ServiceDefTarget)greetingService).setServiceEntryPoint("
http://localhost:8888/mymodule/greet";);

- In the server side configure a filter in your web.xml
   <filter>
      <filter-name>corsFilter</filter-name>
      <filter-class>com.example.server.CORSFilter</filter-class>
   </filter>
   <filter-mapping>
      <filter-name>corsFilter</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>
- And this is an example of filter, maybe you should set any kind of
security based on the Origin header

package com.example.server;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CORSFilter implements Filter {

  public void doFilter(ServletRequest servletRequest,
      ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest) servletRequest;
    HttpServletResponse resp = (HttpServletResponse) servletResponse;

    String o = req.getHeader("Origin");
    if ("options".equalsIgnoreCase(req.getMethod())) {
      resp.setHeader("Allow", "GET, HEAD, POST, PUT, DELETE, TRACE,
OPTIONS");
      if (o != null) {
        resp.addHeader("Access-Control-Allow-Origin", o);
        resp.addHeader("Access-Control-Allow-Methods",
            "POST, GET, OPTIONS");
        resp.addHeader("Access-Control-Allow-Headers",
            "content-type,pageurl,x-gwt-permutation,x-gwt-module-base");
        resp.setContentType("text/plain");
      }
      resp.getWriter().flush();
      return;
    }

    if (o != null) {
      resp.addHeader("Access-Control-Allow-Origin", o);
    }

    if (filterChain != null) {
      filterChain.doFilter(req, resp);
    }
  }

  @Override
  public void destroy() {
  }

  @Override
  public void init(FilterConfig arg0) throws ServletException {
  }

}

The server part works with RPC, RF, RequestBuilder, gwtquery-ajax and any
other js approach.

- Manolo


On Tue, Oct 16, 2012 at 9:01 AM, Thomas Broyer <t.bro...@gmail.com> wrote:
>
>
> On Tuesday, October 16, 2012 8:58:49 AM UTC+2, Manikanda raj S wrote:
>>
>> CORS don't work with GWT Servlets, only with RequestBuilder.
>>>
>>>
>
> There's no reason it wouldn't work. What did you try?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/6FgCPqIoH6QJ.
>
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to