eclipse-paho / eclipse-paho/paho.mqtt.java
Proxy Problem with WebSockets
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 919
- PR merge metrics
- No merged PRs in 30d
Description
- [x] Bug exists Release Version 1.2.0 ( Master Branch)
Hello everyone,
I want to use a proxy with websocket MQTT client but the programm does not take the http proxy into account and instead it tries to use a socks proxy. And even with a socks proxy i have the following error: java.net.SocketException: Malformed reply from SOCKS server : MqttException
Is this normal?
UPDATE:
We are able to use now an HTTP proxy by using a custom ConnectionFactory, but now we have an authentication problem even though i used an authenticator and the client is hanged!
This is the code:
```
class SocksSocketFactory extends SocketFactory {
public Socket createSocket() throws IOException{
final String username = "xxxxx";
final String password = "xxxxx";
Authenticator.setDefault(new Authenticator() {
protected java.net.PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
System.setProperty("http.proxyHost", "proxy.enterprise.com");
System.setProperty("http.proxyPort", "80");
System.setProperty("http.proxyUser", username);
System.setProperty("http.proxyPassword", password);
InetSocketAddress httpProxy = new InetSocketAddress("proxy.enterprise.com", 80);
Proxy proxy = new Proxy(Proxy.Type.HTTP, httpProxy);
Socket sock = new Socket(proxy);
return sock;
}
```
Here is the network flow:

Thank you in advance,
Amir
Contributor guide
Assessment
This issue has not been assessed yet.