JasperReports 服务器 Bitnami Docker 映像在 Azure 应用服务自定义 Web.xml 中运行

问题描述 投票:0回答:1

我正在 Azure 应用服务中运行的 docker 容器中使用来自 https://hub.docker.com/r/bitnami/jasperreports 的 Bitnami JasperReports 映像 v8.2.0。

我的 Docker 配置文件是:

version: '3.8'

services:
  jasperreports:
    image: docker.io/bitnami/jasperreports:8.2.0
    ports:
      - "8080:8080"
    volumes:
      - 'jasperreports_data:/bitnami/jasperreports'
      - "${WEBAPP_STORAGE_HOME}/site/wwwroot/config:/bitnami/jasperreports-mounted-conf"
    environment:
      - JASPERREPORTS_USERNAME=***
      - JASPERREPORTS_PASSWORD=***
      - JASPERREPORTS_DATABASE_TYPE=postgresql
      - JASPERREPORTS_DATABASE_HOST=bon-prod.postgres.database.azure.com
      - JASPERREPORTS_DATABASE_PORT_NUMBER=5432
      - JASPERREPORTS_DATABASE_USER=***
      - JASPERREPORTS_DATABASE_PASSWORD=***
      - JASPERREPORTS_DATABASE_NAME=jasper
      - JASPERREPORTS_SMTP_HOST=smtp.sendgrid.net
      - JASPERREPORTS_SMTP_PORT_NUMBER=587
      - JASPERREPORTS_SMTP_PROTOCOL=smtps
      - JASPERREPORTS_SMTP_USER=***
      - JASPERREPORTS_SMTP_PASSWORD=***
      # Additional environment variables for verbose logging
      - BITNAMI_DEBUG=true
      - JASPERREPORTS_LOGGING_LEVEL=DEBUG
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"

volumes:
  jasperreports_data:

我已添加

WEBSITES_ENABLE_APP_SERVICE_STORAGE=true
作为应用程序设置,以在 Azure 应用服务中启用存储。

从前端域调用其余端点时出现 CORS 错误。大约 3 年前,我在类似的问题上苦苦挣扎了好几个星期,并遇到了一个类似的 Stack Overflow 问题。当时我在裸露的 Linux 服务器上进行安装,并使用下面的 web.xml 解决了问题,其中添加了 CORS 过滤器(当然,其中 sub.domain.com 是我真正的子域):

<filter>
        <filter-name>CorsFilter</filter-name>
        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
        <!--  Update allowed origins and remove localhost for non-dev environments -->
        <init-param>
            <param-name>cors.allowed.origins</param-name>
            <param-value>https://sub.domain.com</param-value>
        </init-param>
        <init-param>
            <param-name>cors.allowed.methods</param-name>
            <param-value>GET,POST,HEAD,PUT,OPTIONS,DELETE,PATCH</param-value>
        </init-param>
        <init-param>
            <param-name>cors.allowed.headers</param-name>
            <param-value>Cache-Control,X-Suppress-Basic,Origin,Accept,X-Requested-With,Content-Type,Pragma,accept-timezone,withCredentials,X-Remote-Domain,X-Is-Visualize,x-jrs-base-url,Content-Disposition,Content-Description,Content-Type,X-Requested-With,Accept,Accept-Encoding,Accept-Language,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Connection,Host,Authorization,Options</param-value>
        </init-param>
        <init-param>
            <param-name>cors.exposed.headers</param-name>
            <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials,Authorization</param-value>
        </init-param>
        <init-param>
            <param-name>cors.support.credentials</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>cors.preflight.maxage</param-name>
            <param-value>300</param-value>
        </init-param>
    </filter>

因此,我已将 web.xml 文件通过 SFTP 传输到 Azure 应用服务上的 /site/wwwroot/config 文件夹,以按照 Bitnami Docker Hub 上的文档替换 Bitnami 容器的内置 web.xml。

但是,这导致了错误:

https://bon-rpt.greydom.com/jasperserver/JavaScriptServlet 403 (Forbidden)
XMLHttpRequest.send @ JavaScriptServlet:52
ajax @ JavaScriptServlet:425
(anonymous) @ JavaScriptServlet:442
(anonymous) @ JavaScriptServlet:490Understand this errorAI
JavaScriptServlet:158 Failed to retrieve CSRF token
csrfTokenRetrieveFailed @ JavaScriptServlet:158
(anonymous) @ JavaScriptServlet:486
xhr.onreadystatechange @ JavaScriptServlet:421
XMLHttpRequest.send
XMLHttpRequest.send @ JavaScriptServlet:52
ajax @ JavaScriptServlet:425
(anonymous) @ JavaScriptServlet:442
(anonymous) @ JavaScriptServlet:490Understand this errorAI
content_script_bundle.js:1 Attempting initialization Mon Dec 02 2024 21:49:04 GMT+0100 (Central European Standard Time)
login.html:1 <meta name="apple-mobile-web-app-capable" content="yes"> is deprecated. Please include <meta name="mobile-web-app-capable" content="yes">Understand this warningAI
JavaScriptServlet:158 Failed to retrieve CSRF token

我假设这是因为我现有的 web.xml 无法在 Docker 容器中工作。

如何获取容器的 web.xml,并简单地添加 CORS 过滤器,同时记住我的 Docker 容器位于 Azure 应用服务中?

azure docker cors jasper-reports jasperserver
1个回答
0
投票

这里您需要从

Bitnami JasperReports 容器
检索现有的 web.xml 文件,对其进行编辑以添加 CORS 过滤器,并确保修改后的
web.xml
在运行时正确注入回容器中。

  • 导航到应用服务实例。选择开发工具 > SSH。打开 SSH 终端以访问容器的 shell。

找到

web.xml
文件 -
/opt/bitnami/tomcat/conf/web.xml 

添加 CORS 过滤器配置:

<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>https://sub.domain.com</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.methods</param-name>
        <param-value>GET,POST,HEAD,PUT,OPTIONS,DELETE,PATCH</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.headers</param-name>
        <param-value>Cache-Control,Origin,Accept,X-Requested-With,Content-Type,Authorization</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>

将修改后的

web.xml
文件上传到应用服务上的
/site/wwwroot/config
目录。

© www.soinside.com 2019 - 2024. All rights reserved.