【发布时间】:2017-11-24 14:06:12
【问题描述】:
在使用 Tomcat 8 查询 Pentaho BI server 7 的 Web 应用程序时,我遇到了一些问题。
首先为了避免CORS(跨域资源共享)问题,我在tomcat的web.xml配置文件中添加了CORS过滤器:
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<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,Authorization</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
之后,一切都很好,直到需要通过 Pentaho CDA(Pentaho 社区数据访问)获取一些资源。我在插件设置文件(pentaho-solutions/system/cda/settings.xml)中添加了一个基本身份验证头和一行:
<allow-cross-domain-resources>true</allow-cross-domain-resources>
我的应用程序执行的每个请求都会收到相同的错误:
XMLHttpRequest 无法加载 http://localhost:8080/pentaho/plugin/cda/api/doQuery?path=/whatever/dashboard.cda&dataAccessId=mdxGetSmth。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://127.0.0.1:xxx' 不允许访问。响应的 HTTP 状态代码为 401。
有趣的是,相同的查询在 Postman 中运行(当然使用相同的 Basic auth 标头)只是因为 Postman 只是跳过了 OPTIONS(预检)请求。
【问题讨论】:
标签: rest tomcat cors pentaho basic-authentication