Hi , I am pretty new to the OpenMRS platform. When i try to send cross-origin requests, getting 403 response status. Please find below the steps I took to resolve the issue
- Initially I got the error response for both the Preflight and actual request. Then I added a custom filter with following code
HttpServletResponse httpresponse = (HttpServletResponse) response;
httpresponse.setHeader("Access-Control-Allow-Origin","*");
httpresponse.setHeader("access-control-expose-headers","*");
httpresponse.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS");
httpresponse.setHeader("Access-Control-Allow-Headers","*");
httpresponse.setHeader("Access-Control-Allow-Credentials", "true");
httpresponse.setHeader("Access-Control-Max-Age", "3600");
chain.doFilter(request, response);
- After this change, the response was still the same. Next I added a CORS filter library like below in web.xml
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- The preflight requests are successful after the previous change, but actual requests are still failing with 403 status.
Note:
- I am using the OpenMRS core version 2.6.0. When tried with the version 2.1.0, got proper response for both preflight and actual request.
- With POSTMAN client responses are successful. Please find the network response below
Thanks in advance