Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Heroku上使用Proximo修复java.net.BindException?_Java_Heroku_Proximo - Fatal编程技术网

如何在Heroku上使用Proximo修复java.net.BindException?

如何在Heroku上使用Proximo修复java.net.BindException?,java,heroku,proximo,Java,Heroku,Proximo,我已经在Heroku上安装了Proximo插件,在将该命令添加到现有命令之前,我从Java获得了一个BindException。这就是我的前置命令的外观:web:bin/proximo sh target/bin/webapp,一旦我删除了proximo部分(bin/proximo),应用程序就会毫无错误地启动 这是完整的堆栈跟踪。我错过了什么 Exception in thread "main" java.net.BindException: Cannot assign requested a

我已经在Heroku上安装了Proximo插件,在将该命令添加到现有命令之前,我从Java获得了一个BindException。这就是我的前置命令的外观:
web:bin/proximo sh target/bin/webapp
,一旦我删除了proximo部分(
bin/proximo
),应用程序就会毫无错误地启动

这是完整的堆栈跟踪。我错过了什么

Exception in thread "main" java.net.BindException: Cannot assign requested address
 at sun.nio.ch.Net.bind0(Native Method)
 at sun.nio.ch.Net.bind(Net.java:344)
 at sun.nio.ch.Net.bind(Net.java:336)
 at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199)
 at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
 at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:162)
 at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:297)
 at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:240)
 at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
 at org.eclipse.jetty.server.Server.doStart(Server.java:270)
 at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)

它与使用端口9999的另一个进程有关。在Windows上,运行以下命令:

netstat -a -n | find "LIST"
它应该列出任何占据港口的东西。当然,您必须在TaskManager中手动终止这些程序。如果仍然不起作用,请更换该线路:

serverSocket = new ServerSocket(9999);
与:


将127.0.0.1与您的实际IP地址一起使用。

请记住,您只能使用Heroku在$port var中提供的端口

因此:

web: bin/proximo [your existing command]
需要包括这一点,例如:

web: bin/proximo [your existing command] -p $PORT

或者您需要指定web进程运行的端口的任何内容。

proximo包装器不适用于Java。您将不得不向应用程序的初始化中添加一些自定义代码,而不是使用包装器

URL proximo = new URL(System.getenv("PROXIMO_URL"));
String userInfo = proximo.getUserInfo();
String user = userInfo.substring(0, userInfo.indexOf(':'));
String password = userInfo.substring(userInfo.indexOf(':') + 1);

System.setProperty("socksProxyHost", proximo.getHost());
Authenticator.setDefault(new ProxyAuthenticator(user, password));


解决方案在中有详细描述。

尽管我在这篇文章中得到了与Visher相同的例外情况,但这不是同一个问题。我正在Heroku上运行Java应用程序,并使用附加Proximo代理所有出站TCP流量。启动时,日志显示以下内容(通过Proximo主机XX.XX.XX.XXX:1080代理绑定为0.0.0.0/0的流量)。因此,Proximo附加组件似乎已正确安装和配置。但是,应用程序由于BindException而停止。我不启动自己的ServerSocket—它由Proximo外接程序处理。我只是做了一个netstat | grep“1080”(1080是Proximo试图绑定的端口),但没有显示任何内容(即端口未使用)。当尝试单独ping IP时,我得到“请求超时”,当尝试ping端口1080上的IP时,我得到“找不到主机”。我怀疑Proximo试图绑定到的IP(和端口)必须以某种方式被服务器识别(Heroku在Amazon服务器上运行)。有没有办法做到这一点?非常感谢您的帮助。
URL proximo = new URL(System.getenv("PROXIMO_URL"));
String userInfo = proximo.getUserInfo();
String user = userInfo.substring(0, userInfo.indexOf(':'));
String password = userInfo.substring(userInfo.indexOf(':') + 1);

System.setProperty("socksProxyHost", proximo.getHost());
Authenticator.setDefault(new ProxyAuthenticator(user, password));
private class ProxyAuthenticator extends Authenticator {
  private final PasswordAuthentication passwordAuthentication;

  private ProxyAuthenticator(String user, String password) {
    passwordAuthentication = new PasswordAuthentication(user, password.toCharArray());
  }

  @Override
  protected PasswordAuthentication getPasswordAuthentication() {
    return passwordAuthentication;
  }
}