我的 Play 中有一个 URL!根据 URL 中传递的扩展名路由到 HTML 或 XLSX 的应用程序,路由行如下:-
# Calls
GET /calls.{format} Call.index
因此 calls.html 呈现页面,calls.xlsx 下载 Excel 文件(使用 Play Excel 模块)。在浏览器、cURL 请求等方面一切正常。
我现在希望能够创建一封电子邮件并将 Excel 附加到其中,但我无法提取附件。这是我首先尝试的基本版本:-
public static void sendReport(List<Object[]> invoicelines, String emailaddress) throws MalformedURLException, URISyntaxException
{
setFrom("Telco Analysis <test@test.com>");
addRecipient(emailaddress);
setSubject("Telco Analysis report");
EmailAttachment emailAttachment = new EmailAttachment();
URL url = new URL("http://localhost:9001/calls.xlsx");
emailAttachment.setURL(url);
emailAttachment.setName(url.getFile());
emailAttachment.setDescription("Test file");
addAttachment(emailAttachment);
send(invoicelines);
}
但它只是不提取 URL 内容,它只是坐在那里,没有任何错误消息,Chrome 的页面微调器开始运行并绑定(bind)网络服务器(以至于来自另一个浏览器/机器的请求似乎没有出现)得到服务)。如果我发送不带附件的电子邮件,一切都很好,所以问题似乎只是文件的提取。
到目前为止,我已经尝试过上述方法,我已经尝试过 Play 的 WS 网络服务库,我已经尝试过手动制作的 HttpRequests 等。如果我指定另一个 URL(例如 http://www.google.com)它工作得很好。
有人能提供帮助吗?
最佳答案
我假设您在开发模式下运行。
在开发模式下,您可能只有一个请求执行池,但在您发送电子邮件的 Controller 中,您发送了第二个请求,该请求将阻塞直到您之前的请求完成(它不会因为它正在等待第二个请求响应)......所以......僵局! 外部请求正常工作的原因是因为您没有导致 Play 请求池出现死锁。
您的问题的简单答案是增加 application.conf 中 play.pool
的值。确保它是未注释的,并选择一个大于 1 的值!
# Execution pool
# ~~~~~
# Default to 1 thread in DEV mode or (nb processors + 1) threads in PROD mode.
# Try to keep a low as possible. 1 thread will serialize all requests (very useful for debugging purpose)
play.pool=3
关于java - 为什么这个 URL 没有从 Play 打开!框架 1.2.4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11898579/