【问题标题】:Pentaho APIs on tomcat apache 8 server(port - 8080) giving CORs issues when called through different web app(react JS, port - 3000)Tomcat apache 8 服务器(端口 - 8080)上的 Pentaho API 在通过不同的 Web 应用程序调用时会出现 COR 问题(反应 JS,端口 - 3000)
【发布时间】:2021-03-05 13:06:46
【问题描述】:

我被困在一个点上,我必须调用 pentaho API 来验证来自 reactJS 应用程序的用户。两者都在我的本地机器上。到目前为止我尝试过的事情:

a) 在 reactJS 配置文件 - package.json 中添加代理。 问题 - 代码命中 localhost:3000 而不是 localhost:8080

b) 在没有安全性的情况下启动 Google chrome 并添加标题。 上面建议的链接 2 - How to allow CORS in react.js?

c) 修改 pentaho 端的 web.xml 文件并添加 cors jar 文件。 问题 - 我从 Maven 存储库下载了 cors jar 文件。添加了相应的过滤器。这些更改后服务器未启动。 链接-https://www.ease2code.com/embedding-pentaho-cde-dashboard-in-web-application/

版本 - Pentaho 8.3 和 tomcat 8

错误 - 从源“http://localhost:3000”访问“http://localhost:8080/pentaho/j_spring_security_check”的 XMLHttpRequest 已被 CORS 策略阻止:没有“Access-Control-Allow-Origin”标头出现在请求的资源。

【问题讨论】:

    标签: reactjs tomcat cors pentaho pentaho-report-designer


    【解决方案1】:

    这终于奏效了。我们需要添加2个jar文件:

    1. cors-filter-2.6
    2. java-property-utils-1.13

    然后更新 webapps\pentaho\WEB-INF\web.xml 文件以读取这些 jar。

            <filter-name>CORS</filter-name>
    
            <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    
        <init-param>
    
        <param-name>cors.allowOrigin</param-name>
    
       <!-- Update specific domains instead of giving to all -->
    
        <param-value>*</param-value>
    
        </init-param>
    
        <init-param>
    
        <param-name>cors.supportsCredentials</param-name>
    
        <param-value>false</param-value>
    
        </init-param>
    
        <init-param>
    
        <param-name>cors.supportedHeaders</param-name>
    
        <param-value>accept, authorization, origin</param-value>
    
            </init-param>
    
     <init-param>
    
        <param-name>cors.supportedMethods</param-name>
    
                <param-value>GET, POST, HEAD, OPTIONS</param-value>
    
     </init-param>
    
        </filter>
    
        <filter-mapping>
    
            <filter-name>CORS</filter-name>
    
            <url-pattern>/*</url-pattern>
    
        </filter-mapping>
    

    重启 pentaho 服务器。它会工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-29
      • 2015-02-14
      • 1970-01-01
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      相关资源
      最近更新 更多