com.fitbur.gesellix.socketfactory.unix.UnixSocketFactory Maven / Gradle / Ivy
package com.fitbur.gesellix.com.fitbur.unix;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import com.fitbur.apache.http.client.HttpClient;
import com.fitbur.apache.http.conn.ConnectTimeoutException;
import com.fitbur.apache.http.conn.scheme.Scheme;
import com.fitbur.apache.http.params.HttpConnectionParams;
import com.fitbur.apache.http.params.HttpParams;
import com.fitbur.newsclub.net.unix.AFUNIXSocket;
import com.fitbur.newsclub.net.unix.AFUNIXSocketAddress;
import com.fitbur.spi.SocketFactory;
public class UnixSocketFactory implements SocketFactory {
private File socketFile;
public UnixSocketFactory() {
}
@Override
public boolean supports(String scheme) {
return "unix" == scheme;
}
@Override
public String sanitize(String dockerHost) {
return dockerHost.replaceAll("^unix://", "unix://localhost");
}
@Override
public void configure(HttpClient httpClient, String dockerHost) {
this.socketFile = new File(dockerHost.replaceAll("unix://localhost", ""));
Scheme unixScheme = new Scheme("unix", 0xffff, this);
httpClient.getConnectionManager().getSchemeRegistry().register(unixScheme);
}
@Override
public Socket createSocket(HttpParams params) throws IOException {
AFUNIXSocket socket = AFUNIXSocket.newInstance();
return socket;
}
@Override
public Socket connectSocket(Socket socket, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
// int soTimeout = HttpConnectionParams.getSoTimeout(params)
try {
// socket.setSoTimeout(soTimeout)
socket.connect(new AFUNIXSocketAddress(socketFile), connTimeout);
// socket.connect(new AFUNIXSocketAddress(socketFile))
}
catch (SocketTimeoutException e) {
throw new ConnectTimeoutException("Connect to '" + socketFile + "' timed out");
}
return socket;
}
@Override
public boolean isSecure(Socket sock) throws IllegalArgumentException {
return false;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy