Unable to send CORS request

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

actual

How about OpenMRS core version 2.5.5?

I tried different versions and given below are the results

  • First I tried with OpenMRS core versions 2.5.6 and 2.4.6 and got a '500’ error status for actual requests with failed preflight requests.

  • Then I tried version 2.1.8 and got successful responses for both preflight and actual requests.

Note: I could not see any error message in server logs

Thanks in advance

Could you include the body of the response? This doesn’t seems to be a CORS-specific error…