How to fix java.net.BindException with Proximo on Heroku?

帅比萌擦擦* 提交于 2019-12-23 10:52:08

问题


I have installed the Proximo add-on on Heroku and when prepending the command to my existing command, I get a BindException from Java. This is how my prepended command looks: web: bin/proximo sh target/bin/webapp and as soon as I remove the Proximo part (bin/proximo), the application starts up with no errors.

This is the full stacktrace. What am I missing?

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)

回答1:


Remember you can only use the port that Heroku provides in the $PORT var.

Therefore:

web: bin/proximo [your existing command]

needs to include this, e.g:

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

or whatever you need to dictate the port your web process runs on.




回答2:


It is something related to another process using port 9999. On Windows, run the command:

netstat -a -n | find "LIST"

And it should list anything there that's hogging the port. Of course you'll then have to go and manually kill those programs in Task Manager. If this still doesn't work, replace the line:

serverSocket = new ServerSocket(9999);

With:

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

Use 127.0.0.1 with your actual IP address.




回答3:


The proximo wrapper does not work with Java. Instead of using the wrapper, you will have to add some custom code to your app's initialization.

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

And

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

The solution is described fully in this article.



来源:https://stackoverflow.com/questions/13910888/how-to-fix-java-net-bindexception-with-proximo-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!