托管服务器,更改IP和JNLP

发布于 2024-09-27 11:37:33 字数 312 浏览 0 评论 0原文

我的客户有以下场景:

他有一个托管服务器 (1)(即 http://customer.net) 基本上重定向到以下格式的地址:http:///app (服务器 2)

IP 地址经常更改(他们甚至每两周告诉我一次)。服务器 2 中有一个带有 jnlp 链接的应用程序,它显然被配置为从服务器 2 IP 下载。当服务器2的IP改变时,jnlp就会被破坏。

对我来说,显而易见的选择是向提供商获取专用 IP 地址,但想知道是否还有其他选择。

提前致谢!

I have the following scenario for a customer of mine:

He has a hosted server (1) (i.e. http://customer.net) which basically redirects to an address in this format: http:///app (server 2)

The IP address changes frequently (they told me even each two weeks). There's an application in server 2 with a jnlp link which obviously is configured to download from server 2 IP. When the IP of server 2 changes the jnlp will be broken.

For me the obvious option is to obtain a dedicated IP address with the provider, but wanted to know if there are any other options.

Thanks in advance!

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

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

发布评论

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

评论(1

她比我温柔 2024-10-04 11:37:33

我能够弄清楚。基本上我有一个 servlet,从中触发 jnlp 链接。我从请求中收集正确的 URL,并在下载之前用它更新 jnlp 文件。我还添加了一些临时文件,以避免一直这样做,只有当 URL 发生变化时。

这是相关代码:

        File jnlp = null;
        File backup = null;
        String protocol = "http://";
        String url = request.getRequestURL().toString();
        url = url.substring(url.indexOf(protocol) + protocol.length(), url.indexOf("/xinco/menu.jsp"));
        File last = new File(getServletContext().getRealPath("/client/" + url + ".xinco"));
        if (!last.exists()) {
            File dir = new File(getServletContext().getRealPath("/client/"));
            String[] list = dir.list(new ExtensionFilter(".xinco"));

            if (list.length != 0) {
                for (int i = 0; i < list.length; i++) {
                    new File(dir.getAbsolutePath(), list[i]).delete();
                }
            }
            try {
                jnlp = new File(getServletContext().getRealPath("/client/XincoExplorer.jnlp"));
                backup = new File(getServletContext().getRealPath("/client/XincoExplorer.jnlp.bak"));
                backup.createNewFile();
                if (jnlp.exists()) {
                    FileChannel source = null;
                    FileChannel destination = null;
                    try {
                        source = new FileInputStream(jnlp).getChannel();
                        destination = new FileOutputStream(backup).getChannel();
                        destination.transferFrom(source, 0, source.size());
                    } finally {
                        if (source != null) {
                            source.close();
                        }
                        if (destination != null) {
                            destination.close();
                        }
                    }
                    try {
                        StringBuilder contents = new StringBuilder();
                        //use buffering, reading one line at a time
                        //FileReader always assumes default encoding is OK!
                        BufferedReader input = new BufferedReader(new FileReader(jnlp));
                        try {
                            String line = null; //not declared within while loop
                        /*
                             * readLine is a bit quirky :
                             * it returns the content of a line MINUS the newline.
                             * it returns null only for the END of the stream.
                             * it returns an empty String if two newlines appear in a row.
                             */
                            while ((line = input.readLine()) != null) {
                                if (line.contains("codebase") && !line.startsWith("<!")) {
                                    String start = line.substring(0,
                                            line.indexOf(protocol) + protocol.length());
                                    String end = null;
                                    end = line.substring(line.indexOf("/xinco"));
                                    line = start + url + end;
                                }
                                contents.append(line);
                                contents.append(System.getProperty("line.separator"));
                            }
                            //use buffering to update jnlp
                            Writer output = new BufferedWriter(new FileWriter(jnlp));
                            try {
                                //FileWriter always assumes default encoding is OK!
                                output.write(contents.toString());
                            } finally {
                                output.close();
                            }
                        } finally {
                            input.close();
                            backup.delete();
                            last.createNewFile();
                        }
                    } catch (IOException ex) {
                        try {
                            source = new FileInputStream(backup).getChannel();
                            destination = new FileOutputStream(jnlp).getChannel();
                            destination.transferFrom(source, 0, source.size());
                            backup.delete();
                        } finally {
                            if (source != null) {
                                source.close();
                            }
                            if (destination != null) {
                                destination.close();
                            }
                        }
                    }
                } else {
                    throw new XincoException("Missing XincoExplorer.jnlp!");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

I was able to figure it out. Basically I have a servlet from which the jnlp link is triggered. I gather the correct URL from the request and update the jnlp file with it before download. Also I added some temp files to avoid doing that all the time, only when the URL changes.

Here's the related code:

        File jnlp = null;
        File backup = null;
        String protocol = "http://";
        String url = request.getRequestURL().toString();
        url = url.substring(url.indexOf(protocol) + protocol.length(), url.indexOf("/xinco/menu.jsp"));
        File last = new File(getServletContext().getRealPath("/client/" + url + ".xinco"));
        if (!last.exists()) {
            File dir = new File(getServletContext().getRealPath("/client/"));
            String[] list = dir.list(new ExtensionFilter(".xinco"));

            if (list.length != 0) {
                for (int i = 0; i < list.length; i++) {
                    new File(dir.getAbsolutePath(), list[i]).delete();
                }
            }
            try {
                jnlp = new File(getServletContext().getRealPath("/client/XincoExplorer.jnlp"));
                backup = new File(getServletContext().getRealPath("/client/XincoExplorer.jnlp.bak"));
                backup.createNewFile();
                if (jnlp.exists()) {
                    FileChannel source = null;
                    FileChannel destination = null;
                    try {
                        source = new FileInputStream(jnlp).getChannel();
                        destination = new FileOutputStream(backup).getChannel();
                        destination.transferFrom(source, 0, source.size());
                    } finally {
                        if (source != null) {
                            source.close();
                        }
                        if (destination != null) {
                            destination.close();
                        }
                    }
                    try {
                        StringBuilder contents = new StringBuilder();
                        //use buffering, reading one line at a time
                        //FileReader always assumes default encoding is OK!
                        BufferedReader input = new BufferedReader(new FileReader(jnlp));
                        try {
                            String line = null; //not declared within while loop
                        /*
                             * readLine is a bit quirky :
                             * it returns the content of a line MINUS the newline.
                             * it returns null only for the END of the stream.
                             * it returns an empty String if two newlines appear in a row.
                             */
                            while ((line = input.readLine()) != null) {
                                if (line.contains("codebase") && !line.startsWith("<!")) {
                                    String start = line.substring(0,
                                            line.indexOf(protocol) + protocol.length());
                                    String end = null;
                                    end = line.substring(line.indexOf("/xinco"));
                                    line = start + url + end;
                                }
                                contents.append(line);
                                contents.append(System.getProperty("line.separator"));
                            }
                            //use buffering to update jnlp
                            Writer output = new BufferedWriter(new FileWriter(jnlp));
                            try {
                                //FileWriter always assumes default encoding is OK!
                                output.write(contents.toString());
                            } finally {
                                output.close();
                            }
                        } finally {
                            input.close();
                            backup.delete();
                            last.createNewFile();
                        }
                    } catch (IOException ex) {
                        try {
                            source = new FileInputStream(backup).getChannel();
                            destination = new FileOutputStream(jnlp).getChannel();
                            destination.transferFrom(source, 0, source.size());
                            backup.delete();
                        } finally {
                            if (source != null) {
                                source.close();
                            }
                            if (destination != null) {
                                destination.close();
                            }
                        }
                    }
                } else {
                    throw new XincoException("Missing XincoExplorer.jnlp!");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文