0

Im having a issue while making a API Call with Request Method POST. The preflight OPTIONS method is failing. I'm running ATG on weblogic 12c. The following is my CORS Code

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import atg.servlet.*;
import atg.servlet.pipeline.*;

public class CORSHeaderServlet extends InsertableServletImpl{
  public CORSHeaderServlet () {}
  public void service (DynamoHttpServletRequest request,
                       DynamoHttpServletResponse response)
       throws IOException, ServletException
  {
     //add headers to response.
    response.addHeader("Access-Control-Allow-Origin" ,"*");
    response.addHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS");
    response.addHeader("Access-Control-Allow-Headers","Origin, Content-Type, X-Auth-Token, X-PINGOTHER");
    response.addHeader("Access-Control-Max-Age", "86000");
    passRequest (request, response);
  }
}

The Browser error is

 Access to XMLHttpRequest at 'http://localhost:7003/rest/model/atg/userprofiling/ProfileActor/login' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status

The Java Error is

 ]] Root cause of ServletException.
javax.servlet.ServletException: The request method type is not supported: OPTIONS
        at atg.rest.servlet.RestPipelineServlet.serviceRESTRequest(RestPipelineServlet.java:493)
        at atg.rest.servlet.RestPipelineServlet.service(RestPipelineServlet.java:274)
        at atg.servlet.pipeline.PipelineableServletImpl.passRequest(PipelineableServletImpl.java:157)
        at atg.servlet.pipeline.PipelineableServletImpl.service(PipelineableServletImpl.java:320)
        at atg.rest.servlet.RestPipelineServlet.service(RestPipelineServlet.java:278)
        Truncated. see log file for complete stacktrace

Any help on this would be greatly appreciated.

1 Answers1

0

The RestPipelineServlet is supposed to pass the request off to the correct RestProcessor. Looking at the RestProcessor interface it appears it only implements a subset of the METHODS you want to use (doc). So for your solution you'll probably have to implement a doRESTOptions method in the ActorProcessor and work from there.

It will not be trivial to get this injected into the application. There may also be available METHOD validation on the implemented methods in the RestPipelineServlet that you need to look into and override/extend.

radimpe
  • 3,197
  • 2
  • 27
  • 46