Reputation: 318
I'm trying to use the WebSocketStompClient
from Spring. I need to set a proxy to reach the STOMP server. I tried with the usual socksProxySet, socksProxyHost, socksProxyPort
with no success.
Do you have any idea how to set the proxy for the WebSocket(Stomp)Client
?
Upvotes: 4
Views: 3237
Reputation: 740
I know this is a fairly old question. Nonetheless, I'd like give a new answer as it may be of help for anyone that happen to stumble upon the same issue.
You can provide your own RestTemplate with the proxy properly configured to your stomp client :
@Bean
public WebSocketStompClient client() {
StandardWebSocketClient client = new StandardWebSocketClient();
List<Transport> webSocketTransports = Arrays.asList(new WebSocketTransport(client), new RestTemplateXhrTransport(getRestTemplate()));
SockJsClient sockJsClient = new SockJsClient(webSocketTransports);
WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
stompClient.setAutoStartup(true);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
return stompClient;
}
// Rest template with proxy configuration
private RestTemplate getRestTemplate() {
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
if (environment.getProperty("http.proxySet", boolean.class, false)) {
String proxyHost = environment.getProperty("http.proxyHost");
String proxyUser = environment.getProperty("http.proxyUser");
String proxyPassword = environment.getProperty("http.proxyPassword");
Integer proxyPort = environment.getProperty("http.proxyPort", Integer.class);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
new AuthScope(proxyHost, proxyPort),
new UsernamePasswordCredentials(proxyUser, proxyPassword));
HttpHost myProxy = new HttpHost(proxyHost, proxyPort);
clientBuilder.setProxy(myProxy)
.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy())
.setDefaultCredentialsProvider(credentialsProvider);
}
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(clientBuilder.build());
return new RestTemplate(factory);
}
Upvotes: 1
Reputation: 1
If it is Stomp-over-Websocket and if you have a native Stomp broker like RabbitMQ with Extension Plugin(s), you can use:
Note: The defaults don't like messages > 8kB
Upvotes: 0