How do I activate a CORS Filter for Cross Domain POST Requests in Maven?

I made a React Application deployed to a separate Google App Engine, which sends a POST Request to fetch some data from a Webapp, and I’m trying to parse the data within my React Application. I was able to fetch the correct data from PostMan, but the same request kept giving me a “No ‘Access-Control-Allow-Origin’ Header is present on the requested resource” Error.
I’m currently receiving the PostRequest from the Bigger Webapp like this:

public String getOrCreateSeller(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {

    this.shopifyStoreName = body.get("id").toString();
    long hashedName = hashStoreName();
    SellerId sellerId = new SellerId(hashedName);
    try {
        Seller seller = sellerService.findSellerById(sellerId);
        String json = getResponseJson();
        return Response.ok(json, MediaType.APPLICATION_JSON).build();
    } catch (NotFoundException e) {
        Seller seller = new Seller(sellerId.toDatastoreId(), 
     this.shopifyStoreName, 3L);
        datastoreRepository.transact(() -> {
        String json = getResponseJson();
        Response.ResponseBuilder r = Response.ok(json, MediaType.APPLICATION_JSON);

It turns out that in the bigger webapp I’m fetching data from contains a “CORSFilter” Class that looks like this:

public class CORSFilter implements Filter {

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
        ServletException {
    HttpServletResponse httpResp = (HttpServletResponse) resp;
    HttpServletRequest httpReq = (HttpServletRequest) req;

    httpResp.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
    httpResp.setHeader("Access-Control-Allow-Origin", "*");
    if (httpReq.getMethod().equalsIgnoreCase("OPTIONS")) {
    chain.doFilter(req, resp);

public void init(FilterConfig arg0) throws ServletException {

public void destroy() {


Hence, I feel like I should use this class to enable CORs, but I am not sure how. Please help!

As your server-side code seems to be using JAX-RS, a way to add CORS Headers to a JAX-RS application (following the same rules of that CORSFilter of yours) is just to add this class to your app:

public class AccessControlResponseFilter implements ContainerResponseFilter {
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
        final MultivaluedMap<String,Object> headers = responseContext.getHeaders();

        headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
        headers.add("Access-Control-Allow-Origin", "*");
        if (requestContext.getMethod().equalsIgnoreCase("OPTIONS")) {
            headers.add("Access-Control-Allow-Headers", requestContext.getHeaderString("Access-Control-Request-Headers"));

Alternatively, if you have that CORSFilter class available to your project, you could add it as a servlet filter to your web.xml:


Pick one of the two solutions, not both.

You can use @CrossOrigin annotation in controller class. Can get more information here – crossorigin