JNLP +代理 +通过流下载文件问题

发布于 2024-11-25 13:28:49 字数 1380 浏览 4 评论 0原文

我正在编写用于从网络下载 CSV 文件并将数据插入数据库表中的应用程序。问题是我需要通过 System.setProperty("http.proxyHost", "http-proxy.domain.com"); 等设置代理。当我在本地系统上运行应用程序时,它工作正常,但问题是当我从 JNLP 启动它时。起初我在签署 JAR 时遇到了问题(我已经设法做到了),现在我面临着问题,即使应用程序正在运行,它也无法连接到网络 - 它会抛出异常消息“连接超时:连接”。

JNLP 文件如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp href="launch.jnlp" spec="1.0+">
    <information>
        <title>TestImporter</title>
        <vendor>hol</vendor>
        <homepage href=""/>
        <description>TestImporter</description>
        <description kind="short">TestImporter</description>    
    </information>
    <update check="always"/>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.6+"/>
        <jar href="TestImporter.jar" main="true"/>    
        <jar href="lib/ojdbc14.jar"/>
        <jar href="lib/mail.jar"/>
    </resources>
    <application-desc main-class="cz.test.Importer">
    </application-desc>
</jnlp>

我正在通过以下代码连接到文件:

URLConnection yc = cnb.openConnection();
BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    yc.getInputStream()));

提前感谢您的任何帮助!

I'm writing application for downloading CSV file from web and inserting data into table in database. The problem is that I need to setup proxy via System.setProperty("http.proxyHost", "http-proxy.domain.com"); and so on. Application works fine when I'm running it on local system, but the problem is when I launch it from JNLP. At first I have had problems with signing the JARs (I've managed it to do it, somehow) and now I'm facing the problem, that even the application is running, it does not connect to the web - it throws exception with message "connection timeout: connect".

JNLP file looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp href="launch.jnlp" spec="1.0+">
    <information>
        <title>TestImporter</title>
        <vendor>hol</vendor>
        <homepage href=""/>
        <description>TestImporter</description>
        <description kind="short">TestImporter</description>    
    </information>
    <update check="always"/>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.6+"/>
        <jar href="TestImporter.jar" main="true"/>    
        <jar href="lib/ojdbc14.jar"/>
        <jar href="lib/mail.jar"/>
    </resources>
    <application-desc main-class="cz.test.Importer">
    </application-desc>
</jnlp>

I'm connecting to file by this code:

URLConnection yc = cnb.openConnection();
BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    yc.getInputStream()));

Thanks in advance for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂牵梦绕锁你心扉 2024-12-02 13:28:49

您可以尝试将代码包装在 doPrivileged 块中。看看这个:

http://download. oracle.com/javase/1.4.2/docs/api/java/security/AccessController.html

如果实现后,您的代码仍然失败,也许从 java 控制台粘贴日志会有意义。

You can try to wrap your code in a doPrivileged block. Check this one out:

http://download.oracle.com/javase/1.4.2/docs/api/java/security/AccessController.html

If after implementing it, your code still fails, maybe it will make some sense to paste your logs from java console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文