reactjstomcatcorspentahopentaho-report-designer

Pentaho APIs on tomcat apache 8 server(port - 8080) giving CORs issues when called through different web app(react JS, port - 3000)


I am stuck as a point where I've to call pentaho API to authenticate user from a reactJS app. Both are on my local machine. Things I've tried so far:

a) Add a proxy in reactJS config file - package.json. issue - Code hits the localhost:3000 instead of localhost:8080

b) Launch Google chrome with out security and add header. link suggesting above 2 - How to allow CORS in react.js?

c) modify web.xml file on pentaho side and add cors jar file. issue - I downloaded cors jar file from Maven repository. Added the corresponding filter. Server is not launching after these changes. link - https://www.ease2code.com/embedding-pentaho-cde-dashboard-in-web-application/

Version - Pentaho 8.3 and tomcat 8

Error - Access to XMLHttpRequest at 'http://localhost:8080/pentaho/j_spring_security_check' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


Solution

  • This is working finally. We need to add 2 jar files:

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

    Then update webapps\pentaho\WEB-INF\web.xml file to read these jars.

            <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>
    

    Restart pentaho server. It will work