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



我已经在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)

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

因此:

web: bin/proximo [your existing command]

需要包括这一点,例如:

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

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

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

netstat -a -n | find "LIST"

它应该列出任何占用港口的东西。当然,您必须在任务管理器中手动杀死这些程序。如果这仍然不起作用,请替换以下行:

serverSocket = new ServerSocket(9999);

跟:

InetAddress locIP = InetAddress.getByName("192.168.1.20");
serverSocket = new ServerSocket(9999, 0, locIP);

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

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));

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;
  }
}

本文将全面介绍该解决方案。

最新更新