在Spring中在JmsListener中实例化IWebContext

在Spring中在JmsListener中实例化IWebContext,spring,thymeleaf,Spring,Thymeleaf,我有一个作为RESTAPI运行的Spring应用程序 让我们假设在某个时刻,生成了一条包含某些信息的消息,并将其存储在AWS SQS队列中 当调用JMSListener时,我试图用thymeleaf和openhtmltopdf生成一个pdf报告。我在实例化IWebContext时遇到问题,因为它需要HttpServletRequest、HttpServletResponse和Locale作为参数。区域设置不是一个问题,因为我可以将其作为SQS消息的一部分,但我一直使用REQ和RES 我正在使用的

我有一个作为RESTAPI运行的Spring应用程序

让我们假设在某个时刻,生成了一条包含某些信息的消息,并将其存储在AWS SQS队列中

当调用JMSListener时,我试图用thymeleaf和openhtmltopdf生成一个pdf报告。我在实例化IWebContext时遇到问题,因为它需要HttpServletRequest、HttpServletResponse和Locale作为参数。区域设置不是一个问题,因为我可以将其作为SQS消息的一部分,但我一直使用REQ和RES

我正在使用的代码:

IWebContext ctx = new WebContext(¿REQUEST?, ¿RESPONSE?, servletContext, locale, mapParams);
String processedHtml = templateEngine.process(template, ctx);

try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
    PdfRendererBuilder builder = new PdfRendererBuilder();
    builder.useSVGDrawer(new BatikSVGDrawer());
    builder.useFastMode();
    builder.withHtmlContent(processedHtml, baseUrl);
    builder.toStream(bos);
    builder.run();
    return bos.toByteArray();
} catch (Exception e) {
    logger.error("xxx");
}
由于它是在@JmsListenerdestination=${aws.sqs.queue.name}注释方法内调用的,因此我不能使用以下任何选项:

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
因为:

RequestContextHolder.getRequestAttributes()
始终为空


感谢和问候。

我认为您不应该为此使用IWebContext。相反,只需使用org.thymeleaf.context.context即可