Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.github.dockerjava.api.command.*;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.core.command.*;
import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl;
import com.google.common.base.Preconditions;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.BadRequestException;
import com.github.dockerjava.api.ConflictException;
import com.github.dockerjava.api.DockerException;
import com.github.dockerjava.api.InternalServerErrorException;
import com.github.dockerjava.api.NotAcceptableException;
import com.github.dockerjava.api.NotFoundException;
import com.github.dockerjava.api.NotModifiedException;
import com.github.dockerjava.api.command.DockerCmd;
import com.github.dockerjava.api.command.DockerCmdExec;

import com.google.common.base.Preconditions;

import javax.ws.rs.ClientErrorException;

public abstract class AbstrDockerCmd<CMD_T extends DockerCmd<RES_T>, RES_T> implements DockerCmd<RES_T> {

private final static Logger LOGGER = LoggerFactory.getLogger(AbstrDockerCmd.class);
Expand All @@ -28,14 +19,10 @@ public AbstrDockerCmd(DockerCmdExec<CMD_T, RES_T> execution) {
this.execution = execution;
}

@Override
@Override
@SuppressWarnings("unchecked")
public RES_T exec() throws DockerException {
LOGGER.debug("Cmd: {}", this);
return execution.exec((CMD_T)this);
}

protected DockerException toDockerException(ClientErrorException exception) {
LOGGER.info("toDockerException");
return new DockerException(exception.getMessage(), exception.getResponse().getStatus(), exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public InspectContainerCmdExec(WebTarget baseResource) {

@Override
protected InspectContainerResponse execute(InspectContainerCmd command) {
WebTarget webResource = getBaseResource().path(String.format("/containers/%s/json", command.getContainerId()));
WebTarget webResource = getBaseResource().path("/containers/{id}/json").resolveTemplate("id", command.getContainerId());

LOGGER.debug("GET: {}", webResource);
return webResource.request().accept(MediaType.APPLICATION_JSON).get(InspectContainerResponse.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.github.dockerjava.jaxrs.util;

import java.io.EOFException;
import java.io.IOException;
import java.nio.charset.Charset;

import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.core.MediaType;

import org.apache.commons.io.IOUtils;

Expand Down Expand Up @@ -46,20 +49,45 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re
throw new NotAcceptableException(getBodyAsMessage(responseContext));
case 409:
throw new ConflictException(getBodyAsMessage(responseContext));
case 500: {

case 500:
throw new InternalServerErrorException(getBodyAsMessage(responseContext));
}
default:
throw new DockerException(getBodyAsMessage(responseContext), status);
}
}

public String getBodyAsMessage(ClientResponseContext responseContext)
throws IOException {
byte[] buffer = new byte[1000];
IOUtils.read(responseContext.getEntityStream(), buffer);
String message = new String(buffer);
return message;
if (responseContext.hasEntity()) {
int contentLength = responseContext.getLength();
if (contentLength != -1) {
byte[] buffer = new byte[contentLength];
try {
IOUtils.readFully(responseContext.getEntityStream(), buffer);
}
catch (EOFException e) {
return null;
}
Charset charset = null;
MediaType mediaType = responseContext.getMediaType();
if (mediaType != null) {
String charsetName = mediaType.getParameters().get("charset");
if (charsetName != null) {
try {
charset = Charset.forName(charsetName);
}
catch (Exception e) {
//Do noting...
}
}
}
if (charset == null) {
charset = Charset.defaultCharset();
}
String message = new String(buffer, charset);
return message;
}
}
return null;
}
}