为什么未从Play打开此URL!框架1.2.4? [英] Why is this URL not opened from Play! Framework 1.2.4?

查看:95
本文介绍了为什么未从Play打开此URL!框架1.2.4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Play中有一个URL!应用程序,该应用程序根据URL中传递的扩展名路由到HTML或XLSX,并带有诸如:-

I have a URL in my Play! app that routes to either HTML or XLSX depending on the extension that is passed in the URL, with a routes line like :-

# Calls
GET     /calls.{format}                         Call.index

因此,calls.html呈现页面,calls.xlsx下载一个Excel文件(使用Play Excel模块).一切都可以通过浏览器,cURL请求等正常运行.

so calls.html renders the page, calls.xlsx downloads an Excel file (using Play Excel module). All works fine from the browser, a cURL request, etc.

我现在希望能够创建电子邮件并为其附加Excel,但是我无法提取附件.这是我首先尝试的基本版本:-

I now want to be able to create an email and have the Excel attached to it, but I cannot pull the attachment. Here's the basic version of what I tried first :-

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的页面微调器继续运行并束缚了网络服务器(以至于来自其他浏览器/计算机的请求似乎不会得到服务).如果我发送的电子邮件中没有附件,那一切都很好,因此,问题的出在仅仅是拉文件.

but it just doesn't pull the URL content, it just sits there without any error messages, with Chrome's page spinner going and ties up the web server (to the point that requests from another browser/machine don't appear to get serviced). If I send the email without the attachment, all is fine, so it's just the pulling of the file that appears to be the problem.

到目前为止,我已经尝试了上述方法,已经尝试了Play的WS网络服务库,已经尝试了手动创建的HttpRequests,等等.如果我指定了另一个URL(例如

So far I've tried the above method, I've tried Play's WS webservice library, I've tried manually-crafted HttpRequests, etc. If I specify another URL (such as http://www.google.com) it works just fine.

有人可以协助吗?

推荐答案

我假设您正在开发模式下运行.

I am making an assumption that you are running in Dev mode.

在开发模式下,您可能只有一个请求执行池,但是在发送电子邮件的控制器中,您正在发送第二个请求,该请求将一直阻塞到您之前的请求完成为止(这不会因为它正在等待第二个请求做出响应). 导致外部请求正常运行的原因是,您没有在Play请求池中造成僵局.

In Dev mode, you will likely have a single request execution pool, but in your controller that send an email, you are sending off a second request, which will block until your previous request has completed (which it won't because it is waiting for the second request to respond)...so....deadlock! The resaon why external requests work fine, is because you are not causing the deadlock on your Play request pool.

对您的问题的简单答案是增加application.conf中play.pool的值.确保它没有注释,并选择一个大于1的值!

Simple answer to your problem is to increase the value of the play.pool in the application.conf. Make sure that it is uncommented, and choose a value greater than 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

这篇关于为什么未从Play打开此URL!框架1.2.4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆