com.github.dockerjava.api.exception.NotModifiedException Java Examples

The following examples show how to use com.github.dockerjava.api.exception.NotModifiedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerTestUtils.java    From module-ballerina-docker with Apache License 2.0 6 votes vote down vote up
/**
 * Stop and remove a running container.
 *
 * @param containerID The container ID.
 */
public static void stopContainer(String containerID) {
    try {
        InspectContainerResponse containerInfo = getDockerClient().inspectContainerCmd(containerID).exec();
        if ((null != containerInfo.getState().getRestarting() && containerInfo.getState().getRestarting()) ||
                (null != containerInfo.getState().getPaused() && containerInfo.getState().getPaused()) ||
                (null != containerInfo.getState().getRunning() && containerInfo.getState().getRunning())) {
            log.info("Stopping container: " + containerID);
            getDockerClient().stopContainerCmd(containerID).exec();
        }
        log.info("Removing container: " + containerID);
        getDockerClient().removeContainerCmd(containerID).exec();
    } catch (NotFoundException | NotModifiedException e) {
        // ignore
    }
}
 
Example #2
Source File: ResponseStatusExceptionFilter.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    int status = responseContext.getStatus();
    switch (status) {
        case 200:
        case 201:
        case 204:
            return;
        case 304:
            throw new NotModifiedException(getBodyAsMessage(responseContext));
        case 400:
            throw new BadRequestException(getBodyAsMessage(responseContext));
        case 401:
            throw new UnauthorizedException(getBodyAsMessage(responseContext));
        case 404:
            throw new NotFoundException(getBodyAsMessage(responseContext));
        case 406:
            throw new NotAcceptableException(getBodyAsMessage(responseContext));
        case 409:
            throw new ConflictException(getBodyAsMessage(responseContext));
        case 500:
            throw new InternalServerErrorException(getBodyAsMessage(responseContext));
        default:
            throw new DockerException(getBodyAsMessage(responseContext), status);
    }
}
 
Example #3
Source File: DefaultInvocationBuilder.java    From docker-java with Apache License 2.0 5 votes vote down vote up
protected DockerHttpClient.Response execute(DockerHttpClient.Request request) {
    try {
        DockerHttpClient.Response response = dockerHttpClient.execute(request);
        int statusCode = response.getStatusCode();
        if (statusCode < 200 || statusCode > 299) {
            try {
                String body = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8);
                switch (statusCode) {
                    case 304:
                        throw new NotModifiedException(body);
                    case 400:
                        throw new BadRequestException(body);
                    case 401:
                        throw new UnauthorizedException(body);
                    case 404:
                        throw new NotFoundException(body);
                    case 406:
                        throw new NotAcceptableException(body);
                    case 409:
                        throw new ConflictException(body);
                    case 500:
                        throw new InternalServerErrorException(body);
                    default:
                        throw new DockerException(body, statusCode);
                }
            } finally {
                response.close();
            }
        } else {
            return response;
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: HttpResponseHandler.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Override
protected void channelRead0(final ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    if (msg instanceof HttpResponse) {

        response = (HttpResponse) msg;

        resultCallback.onStart(() -> ctx.channel().close());

    } else if (msg instanceof HttpContent) {

        HttpContent content = (HttpContent) msg;

        ByteBuf byteBuf = content.content();

        switch (response.status().code()) {
            case 200:
            case 201:
            case 204:
                ctx.fireChannelRead(byteBuf);
                break;
            default:
                errorBody.writeBytes(byteBuf);
        }

        if (content instanceof LastHttpContent) {
            try {

                switch (response.status().code()) {
                    case 101:
                    case 200:
                    case 201:
                    case 204:
                        break;
                    case 301:
                    case 302:
                        if (response.headers().contains(HttpHeaderNames.LOCATION)) {
                            String location = response.headers().get(HttpHeaderNames.LOCATION);
                            HttpRequest redirected = requestProvider.getHttpRequest(location);

                            ctx.channel().writeAndFlush(redirected);
                        }
                        break;
                    case 304:
                        throw new NotModifiedException(getBodyAsMessage(errorBody));
                    case 400:
                        throw new BadRequestException(getBodyAsMessage(errorBody));
                    case 401:
                        throw new UnauthorizedException(getBodyAsMessage(errorBody));
                    case 404:
                        throw new NotFoundException(getBodyAsMessage(errorBody));
                    case 406:
                        throw new NotAcceptableException(getBodyAsMessage(errorBody));
                    case 409:
                        throw new ConflictException(getBodyAsMessage(errorBody));
                    case 500:
                        throw new InternalServerErrorException(getBodyAsMessage(errorBody));
                    default:
                        throw new DockerException(getBodyAsMessage(errorBody), response.status().code());
                }
            } catch (Throwable e) {
                resultCallback.onError(e);
            } finally {
                resultCallback.onComplete();
            }
        }
    }
}
 
Example #5
Source File: StartContainerCmd.java    From docker-java with Apache License 2.0 2 votes vote down vote up
/**
 * @throws NotFoundException
 *             No such container
 * @throws NotModifiedException
 *             Container already started
 */
@Override
Void exec() throws NotFoundException, NotModifiedException;
 
Example #6
Source File: StopContainerCmd.java    From docker-java with Apache License 2.0 2 votes vote down vote up
/**
 * @throws NotFoundException
 *             No such container
 * @throws NotModifiedException
 *             Container already stopped
 */
@Override
Void exec() throws NotFoundException, NotModifiedException;
 
Example #7
Source File: StartContainerCmdImpl.java    From docker-java with Apache License 2.0 2 votes vote down vote up
/**
 * @throws NotFoundException
 *             No such container
 * @throws NotModifiedException
 *             Container already started
 */
@Override
public Void exec() throws NotFoundException, NotModifiedException {
    return super.exec();
}
 
Example #8
Source File: StopContainerCmdImpl.java    From docker-java with Apache License 2.0 2 votes vote down vote up
/**
 * @throws NotFoundException
 *             No such container
 * @throws NotModifiedException
 *             Container already stopped
 */
@Override
public Void exec() throws NotFoundException, NotModifiedException {
    return super.exec();
}