Example usage for io.netty.handler.codec.http2 Http2Error INTERNAL_ERROR

List of usage examples for io.netty.handler.codec.http2 Http2Error INTERNAL_ERROR

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 Http2Error INTERNAL_ERROR.

Prototype

Http2Error INTERNAL_ERROR

To view the source code for io.netty.handler.codec.http2 Http2Error INTERNAL_ERROR.

Click Source Link

Usage

From source file:com.linecorp.armeria.client.http.HttpRequestSubscriber.java

License:Apache License

private void failAndRespond(Throwable cause) {
    fail(cause);// w w w.j  a  va2  s  .com

    final Channel ch = ctx.channel();
    final Http2Error error;
    if (response.isOpen()) {
        response.close(cause);
        error = Http2Error.INTERNAL_ERROR;
    } else if (cause instanceof WriteTimeoutException) {
        error = Http2Error.CANCEL;
    } else {
        Exceptions.logIfUnexpected(logger, ch, HttpSession.get(ch).protocol(),
                "a request publisher raised an exception", cause);
        error = Http2Error.INTERNAL_ERROR;
    }

    if (ch.isActive()) {
        encoder.writeReset(ctx, id, streamId(), error);
        ctx.flush();
    }
}

From source file:com.linecorp.armeria.client.HttpRequestSubscriber.java

License:Apache License

private void failAndRespond(Throwable cause) {
    fail(cause);//from  w  ww. j a  v a 2 s .co m

    final Channel ch = ctx.channel();
    final Http2Error error;
    if (response.isOpen()) {
        response.close(cause);
        error = Http2Error.INTERNAL_ERROR;
    } else if (cause instanceof WriteTimeoutException || cause instanceof AbortedStreamException) {
        error = Http2Error.CANCEL;
    } else {
        Exceptions.logIfUnexpected(logger, ch, HttpSession.get(ch).protocol(),
                "a request publisher raised an exception", cause);
        error = Http2Error.INTERNAL_ERROR;
    }

    if (ch.isActive()) {
        encoder.writeReset(ctx, id, streamId(), error);
        ctx.flush();
    }
}

From source file:com.linecorp.armeria.server.http.HttpResponseSubscriber.java

License:Apache License

@Override
public void onSubscribe(Subscription subscription) {
    assert this.subscription == null;
    this.subscription = subscription;

    if (timeoutMillis > 0) {
        timeoutFuture = ctx.channel().eventLoop().schedule(() -> {
            if (state != State.DONE) {
                failAndRespond(RequestTimeoutException.get(), HttpStatus.SERVICE_UNAVAILABLE,
                        Http2Error.INTERNAL_ERROR);
            }/*from w w w. j a  v  a 2 s  .c o m*/
        }, timeoutMillis, TimeUnit.MILLISECONDS);
    }

    subscription.request(1);
}

From source file:com.linecorp.armeria.server.http.HttpResponseSubscriber.java

License:Apache License

@Override
public void onError(Throwable cause) {
    if (cause instanceof ServiceUnavailableException) {
        failAndRespond(cause, HttpStatus.SERVICE_UNAVAILABLE, Http2Error.CANCEL);
    } else if (cause instanceof ResourceNotFoundException) {
        failAndRespond(cause, HttpStatus.NOT_FOUND, Http2Error.CANCEL);
    } else {//from w  ww  .  j  a v  a  2 s  .c o m
        logger.warn("{} Unexpected exception from a service or a response publisher: {}", ctx.channel(),
                service, cause);

        failAndRespond(cause, HttpStatus.INTERNAL_SERVER_ERROR, Http2Error.INTERNAL_ERROR);
    }
}

From source file:com.linecorp.armeria.server.http.HttpResponseSubscriber.java

License:Apache License

@Override
public void onComplete() {
    if (!cancelTimeout()) {
        return;/*from   w w w .jav  a  2s  . co  m*/
    }

    if (wroteNothing(state)) {
        logger.warn("{} Published nothing (or only informational responses): {}", ctx.channel(), service);
        responseEncoder.writeReset(ctx, req.id(), req.streamId(), Http2Error.INTERNAL_ERROR);
        return;
    }

    if (state != State.DONE) {
        write(HttpData.EMPTY_DATA, true, true);
    }
}

From source file:com.linecorp.armeria.server.http.HttpResponseSubscriber.java

License:Apache License

private IllegalStateException newIllegalStateException(String msg) {
    final IllegalStateException cause = new IllegalStateException(msg);
    failAndRespond(cause, HttpStatus.INTERNAL_SERVER_ERROR, Http2Error.INTERNAL_ERROR);
    return cause;
}

From source file:com.linecorp.armeria.server.HttpResponseSubscriber.java

License:Apache License

private void onTimeout() {
    if (state != State.DONE) {
        reqCtx.setTimedOut();/*  w  ww.  j  a va2  s  . c o  m*/
        final Runnable requestTimeoutHandler = reqCtx.requestTimeoutHandler();
        if (requestTimeoutHandler != null) {
            requestTimeoutHandler.run();
        } else {
            failAndRespond(RequestTimeoutException.get(), SERVICE_UNAVAILABLE_MESSAGE,
                    Http2Error.INTERNAL_ERROR);
        }
    }
}

From source file:com.linecorp.armeria.server.HttpResponseSubscriber.java

License:Apache License

@Override
public void onError(Throwable cause) {
    if (cause instanceof HttpResponseException) {
        // Timeout may occur when the aggregation of the error response takes long.
        // If timeout occurs, respond with 503 Service Unavailable.
        ((HttpResponseException) cause).httpResponse().aggregate(ctx.executor())
                .whenCompleteAsync((message, throwable) -> {
                    if (throwable != null) {
                        failAndRespond(throwable, INTERNAL_SERVER_ERROR_MESSAGE, Http2Error.CANCEL);
                    } else {
                        failAndRespond(cause, message, Http2Error.CANCEL);
                    }/*w  ww.  j  a va 2 s . co m*/
                }, ctx.executor());
    } else if (cause instanceof HttpStatusException) {
        failAndRespond(cause, AggregatedHttpMessage.of(((HttpStatusException) cause).httpStatus()),
                Http2Error.CANCEL);
    } else if (cause instanceof AbortedStreamException) {
        // One of the two cases:
        // - Client closed the connection too early.
        // - Response publisher aborted the stream.
        failAndReset((AbortedStreamException) cause);
    } else {
        logger.warn("{} Unexpected exception from a service or a response publisher: {}", ctx.channel(),
                service(), cause);

        failAndRespond(cause, INTERNAL_SERVER_ERROR_MESSAGE, Http2Error.INTERNAL_ERROR);
    }
}

From source file:com.linecorp.armeria.server.HttpResponseSubscriber.java

License:Apache License

@Override
public void onComplete() {
    if (!cancelTimeout() && reqCtx.requestTimeoutHandler() == null) {
        // We have already returned a failed response due to a timeout.
        return;/* w  w  w . j  av a  2 s . c o m*/
    }

    if (wroteNothing(state)) {
        logger.warn("{} Published nothing (or only informational responses): {}", ctx.channel(), service());
        responseEncoder.writeReset(ctx, req.id(), req.streamId(), Http2Error.INTERNAL_ERROR);
        return;
    }

    if (state != State.DONE) {
        write(HttpData.EMPTY_DATA, true);
    }
}

From source file:com.linecorp.armeria.server.HttpResponseSubscriber.java

License:Apache License

private IllegalStateException newIllegalStateException(String msg) {
    final IllegalStateException cause = new IllegalStateException(msg);
    failAndRespond(cause, INTERNAL_SERVER_ERROR_MESSAGE, Http2Error.INTERNAL_ERROR);
    return cause;
}