CORS filter tomcat 7 No header "Access-Control-Allow-Origin" is present on the requested resource

I am using the following configuration in my tomcat7 conf / web.xml

<filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> <init-param> <param-name>cors.allowed.origins</param-name> <param-value>*</param-value> </init-param> <init-param> <param-name>cors.allowed.methods</param-name> <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value> </init-param> <init-param> <param-name>cors.allowed.headers</param-name> <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Last-Modified</param-value> </init-param> <init-param> <param-name>cors.exposed.headers</param-name> <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value> </init-param> <init-param> <param-name>cors.support.credentials</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 

My apache web server sends a request to tomcat rest api. The APache web server runs on port 8005, and tomcat runs on 8080. Thus, the request is sent from mydomain.com:8085/index.php/kop to mydomain.com:8080/webiste-1.0/rest-api/product. I get

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxxx:8085' is therefore not allowed access. 

The following is the request header from chrome:

 Accept:application/json, text/javascript, */*; q=0.01 Cache-Control:no-cache Origin:http://xxxx:8085 Pragma:no-cache Referer:http://xxxx:8085/html/index.php/kop_och_salj User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 

Response headers: Content length: "0" Date: "Wed, 18 Jun 2014 12:02:11 GMT" Server: "Apache-Coyote / 1.1"

What am I doing wrong? Did I miss something?

+6
source share
1 answer

I found a solution myself. Apache Tomcat includes CORS support - starting with Tomcat version 7.0.41 - my problem was that I installed tomcat 7 with apt-get install tomcat7 in ubuntu 12.04 and installed an older version than 7.0.41. As soon as I installed tomcat manually 7.0.54, the cors filter is processed

+3
source

Source: https://habr.com/ru/post/971005/


All Articles