Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Connectivity Service to manage connectivity
package my.services;
import java.net.Socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import my.infrastructure.ConnectivitySocks5ProxySocket;
import my.util.CFServiceFacade;
@Service
public class ConnectivityService {
private static final Logger logger = LoggerFactory.getLogger(ConnectivityService.class);
private final CFServiceFacade connectivityServiceBinding;
private final String tokenServiceUrlProperty;
@Autowired
public ConnectivityService(
@Value("${my.connectivity.instanceName}") String connectivityServiceInstanceName,
@Value("${my.connectivity.tokenServiceUrlProperty}") String tokenServiceUrlProperty) {
connectivityServiceBinding = new CFServiceFacade(connectivityServiceInstanceName);
this.tokenServiceUrlProperty = tokenServiceUrlProperty;
}
// default constructor; needed due to implicit call of ConnectivitySocketFactory
public ConnectivityService() {
connectivityServiceBinding = new CFServiceFacade("my-connectivity"); // can be externalized in spring configuration
this.tokenServiceUrlProperty = "token_service_url"; // can be externalized in spring configuration
}
public ConnectivitySocks5ProxySocket getProxy(String locationId) {
logger.info("Creating Proxy Socket for locationId " + locationId);
String connectivityJWT = connectivityServiceBinding.getServiceJWT(tokenServiceUrlProperty);
return new ConnectivitySocks5ProxySocket(connectivityJWT, locationId);
}
public Socket getSSLProxy(String locationId) {
return (Socket) getProxy(locationId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment