Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.jolokia.docker.maven.access.hc;
import java.io.*;
import java.net.URI;
import java.util.*;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.jolokia.docker.maven.access.*;
import org.jolokia.docker.maven.access.chunked.*;
import org.jolokia.docker.maven.access.hc.http.HttpClientBuilder;
import org.jolokia.docker.maven.access.hc.unix.UnixSocketClientBuilder;
import org.jolokia.docker.maven.access.log.*;
import org.jolokia.docker.maven.config.Arguments;
import org.jolokia.docker.maven.log.DefaultLogCallback;
import org.jolokia.docker.maven.log.LogOutputSpec;
import org.jolokia.docker.maven.model.*;
import org.jolokia.docker.maven.util.*;
import org.json.JSONArray;
import org.json.JSONObject;
import static java.net.HttpURLConnection.*;
import static org.jolokia.docker.maven.access.hc.ApacheHttpClientDelegate.*;
/**
* Implementation using Apache HttpComponents for accessing
* remotely the docker host.
*
* The design goal here is to provide only the functionality required for this plugin in order to
* make it as robust as possible agains docker API changes (which happen quite frequently). That's
* also the reason, why no framework like JAX-RS or docker-java is used so that the dependencies are
* kept low.
*
* Of course, it's a bit more manual work, but it's worth the effort (as long as the Docker API
* functionality required is not to much).
*
* @author roland
* @since 26.03.14
*/
public class DockerAccessWithHcClient implements DockerAccess {
// Base URL which is given through when using UnixSocket communication but is not really used
private static final String DUMMY_BASE_URL = "unix://127.0.0.1:1/";
// Logging
private final Logger log;
private final ApacheHttpClientDelegate delegate;
private final UrlBuilder urlBuilder;
/**
* Create a new access for the given URL
*
* @param baseUrl base URL for accessing the docker Daemon
* @param certPath used to build up a keystore with the given keys and certificates found in this
* directory
* @param maxConnections maximum parallel connections allowed to docker daemon (if a pool is used)
* @param log a log handler for printing out logging information
* @paran usePool whether to use a connection bool or not
*/
public DockerAccessWithHcClient(String apiVersion, String baseUrl, String certPath, int maxConnections, Logger log)
throws IOException {
this.log = log;
URI uri = URI.create(baseUrl);
if (uri.getScheme() == null) {
throw new IllegalArgumentException("The docker access url '" + baseUrl + "' must contain a schema tcp:// or unix://");
}
if (uri.getScheme().equalsIgnoreCase("unix")) {
this.delegate =
new ApacheHttpClientDelegate(new UnixSocketClientBuilder().build(uri.getPath(), maxConnections));
this.urlBuilder = new UrlBuilder(DUMMY_BASE_URL, apiVersion);
} else {
HttpClientBuilder builder = new HttpClientBuilder();
if (isSSL(baseUrl)) {
builder.certPath(certPath);
}
builder.maxConnections(maxConnections);
this.delegate = new ApacheHttpClientDelegate(builder.build());
this.urlBuilder = new UrlBuilder(baseUrl, apiVersion);
}
}
@Override
public void startExecContainer(String containerId, LogOutputSpec outputSpec) throws DockerAccessException {
try {
String url = urlBuilder.startExecContainer(containerId);
JSONObject request = new JSONObject();
request.put("Detach", false);
request.put("Tty", true);
delegate.post(url, request.toString(), createExecResponseHandler(outputSpec), HTTP_OK);
} catch (Exception e) {
log.error(e.getMessage());
throw new DockerAccessException("Unable to start container id [%s]", containerId);
}
}
private ResponseHandler