[英]mailto URI truncated between Java.Desktop and Windows/MS outlook
I'm trying to create an automated error reporting tool for our Java desktop app. 我正在尝试为我们的Java桌面应用程序创建一个自动错误报告工具。 the idea is to make it as easy as possible for customers to send us error reports whenever our application crashes.
这样做的目的是让客户在我们的应用程序崩溃时尽可能轻松地向我们发送错误报告。
Using the Desktop.mail API, I am able to craft messages that can be easily edited and sent from our users, but I'm running into system limitations on several platforms (notably Windows 7 and MS Outlook, which most customers are using) 使用Desktop.mail API,我能够编写易于编辑并从用户发送的消息,但是我遇到了多个平台(尤其是大多数客户使用的Windows 7和MS Outlook)上的系统限制
When I run the example code below, you'll notice that the email message that is displayed truncates the included stack trace. 当我运行下面的示例代码时,您会注意到显示的电子邮件会截断所包含的堆栈跟踪。 I believe this has something to do with a maximum length of either command lines or URIs in the underlying systems.
我相信这与底层系统中命令行或URI的最大长度有关。
Is there a better way to craft an email from an error report that is not subject to this limitation? 有没有更好的方法可以从不受此限制的错误报告中制作电子邮件?
import java.awt.Desktop;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.net.URLEncoder;
public class Scratchpad {
public static void main(String[] args) throws Exception {
try {
generateLongStackTrace();
} catch (Error e) {
URI uri = createMailURI(e);
// this will correctly pop up the system email client, but it will truncate the message
// after about 2K of data (this seems system dependent)
Desktop.getDesktop().mail(uri);
}
}
// Will eventually generate a really long stack overflow error
public static void generateLongStackTrace() throws Exception {
generateLongStackTrace();
}
public static URI createMailURI(Error e) throws Exception {
StringBuilder builder = new StringBuilder();
builder.append("mailto:foo@example.com?body=");
// encodes the stack trace in a mailto URI friendly form
String encodedStackTrace = URLEncoder.encode(dumpToString(e), "utf-8").replace("+", "%20");
builder.append(encodedStackTrace);
return new URI(builder.toString());
}
// Dumps the offending stack trace into a string object.
public static String dumpToString(Error e) {
StringWriter sWriter = new StringWriter();
PrintWriter writer = new PrintWriter(sWriter);
e.printStackTrace(writer);
writer.flush();
return sWriter.toString();
}
}
there are length limitations wrt admissible urls in ie and the length of a windows command line (see here , here , here and here ) - i seems you run into one of these (though i admit that i have not rigorously checked). 在ie以及Windows命令行的长度(请参见此处 , 此处 , 此处和此处 )的长度中都有可允许的url的长度限制-我似乎遇到了其中一种(尽管我承认我没有严格检查过)。
however i think it's a plausible assumption that even if you could worm your way around the said limits the length of a generic transmission buffer between desktop applications (unless you use a dedicated api for remote controlling the target app) will be restricted somehow without a loophole. 但是,我认为这是一个合理的假设,即使您可以绕过上述限制而在台式机应用程序之间通用传输缓冲区的长度(除非您使用专用的api来远程控制目标应用程序)的长度也会受到某种限制而不会出现漏洞。
therefore i'd suggest one of the following strategies: 因此,我建议采用以下策略之一:
distribution through a web server. 通过Web服务器分发。
send a mail using an attachment (for some details see here ): 使用附件发送邮件(有关详细信息, 请参见此处 ):
good luck ! 祝好运 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.