本文介绍了如何将Proximo用作Java中的SOCKS代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Heroku上运行的Java应用程序,需要访问Salesforce,它只允许来自您白名单的IP的API访问。 是一款Heroku插件,可让您代理应用程序通过一个应用程序完成的所有请求带有静态IP的服务器。不幸的是,这样做的标准方式 - - 为我的应用程序的网络服务器创建一个监听套接字, 。

如何在我的Java应用程序中使用Proximo作为SOCKS代理?

解决方案 div>

我查看了,它们以前面提到的包装的形式发布,并看到它将作为SOCKS代理连接到Proximo服务器。这在Java中很容易实现,所以我将它添加到我的应用程序的启动中(Groovy语法):

  URL proximo = new URL(System.getenv('PROXIMO_URL')
字符串userInfo = proximo.getUserInfo()
字符串user = userInfo.substring(0,userInfo.indexOf(':'))
字符串密码= userInfo.substring(userInfo.indexOf(':')+ 1)
System.setProperty('socksProxyHost',proximo.getHost())
System.setProperty('socksProxyPort','1080')
Authenticator.setDefault(新的ProxyAuth(用户,密码))

其他地方的内部类:

 私有类ProxyAuth扩展了Authenticator {
private PasswordAuthentication passwordAuthentication;

私人ProxyAuth(字符串用户,字符串密码){
passwordAuthentication = new PasswordAuthentication(user,password.toCharArray())
}
$ b $ @覆盖
protected PasswordAuthenticatio getPasswordAuthentication(){
返回passwordAuthentication;
}
}


I've got a Java app that runs on Heroku that needs to access Salesforce, which only allows API access from IPs that you whitelist. Proximo is a Heroku add-on that allows you to proxy all of the requests your app makes through a single server with a static IP. Unfortunately, the standard way of doing this—running your app within Proximo's wrapper—mucks up the creating of a listening socket for my app's webserver, as it seems to for a number of folks.

How can I use Proximo as a SOCKS proxy in my Java application?

解决方案

I looked that stacklet that they distribute as the aforementioned wrapper and saw that it connects to the Proximo server as a SOCKS proxy. That's easy to do in Java, so I added this to the startup of my app (Groovy syntax):

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())
System.setProperty('socksProxyPort', '1080')
Authenticator.setDefault(new ProxyAuth(user, password))

With that ProxyAuth being an inner class elsewhere:

private class ProxyAuth extends Authenticator {
    private PasswordAuthentication passwordAuthentication;

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

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

这篇关于如何将Proximo用作Java中的SOCKS代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 10:50