Example usage for org.apache.http.util Asserts check

List of usage examples for org.apache.http.util Asserts check

Introduction

In this page you can find the example usage for org.apache.http.util Asserts check.

Prototype

public static void check(boolean z, String str) 

Source Link

Usage

From source file:org.apache.http.impl.nio.client.PipeliningClientExchangeHandlerImpl.java

@Override
public void produceContent(final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + getId() + "] produce content");
    }/*from w w w. j  a  v  a 2s.  c  o  m*/
    final HttpAsyncRequestProducer requestProducer = this.requestProducerRef.get();
    Asserts.check(requestProducer != null, "Inconsistent state: request producer is null");
    requestProducer.produceContent(encoder, ioctrl);
    if (encoder.isCompleted()) {
        requestProducer.resetRequest();
    }
}

From source file:org.apache.http.impl.nio.client.PipeliningClientExchangeHandlerImpl.java

@Override
public void requestCompleted() {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + getId() + "] Request completed");
    }//www  .j  a v a2s. com
    final HttpAsyncRequestProducer requestProducer = this.requestProducerRef.getAndSet(null);
    Asserts.check(requestProducer != null, "Inconsistent state: request producer is null");
    requestProducer.requestCompleted(this.localContext);
    try {
        requestProducer.close();
    } catch (final IOException ioex) {
        this.log.debug(ioex.getMessage(), ioex);
    }
}

From source file:org.apache.http.impl.nio.client.PipeliningClientExchangeHandlerImpl.java

@Override
public void responseReceived(final HttpResponse response) throws IOException, HttpException {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + getId() + "] Response received " + response.getStatusLine());
    }/*from   w ww  . jav a 2 s  .c o m*/

    Asserts.check(this.responseConsumerRef.get() == null, "Inconsistent state: response consumer is not null");

    final HttpAsyncResponseConsumer<T> responseConsumer = this.responseConsumerQueue.poll();
    Asserts.check(responseConsumer != null, "Inconsistent state: response consumer queue is empty");
    this.responseConsumerRef.set(responseConsumer);

    final HttpRequest request = this.requestQueue.poll();
    Asserts.check(request != null, "Inconsistent state: request queue is empty");

    this.localContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
    this.localContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
    this.httpProcessor.process(response, this.localContext);

    responseConsumer.responseReceived(response);

    setCurrentResponse(response);
}

From source file:org.apache.http.impl.nio.client.PipeliningClientExchangeHandlerImpl.java

@Override
public void consumeContent(final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + getId() + "] Consume content");
    }/*from ww w .j a v  a  2s .com*/
    final HttpAsyncResponseConsumer<T> responseConsumer = this.responseConsumerRef.get();
    Asserts.check(responseConsumer != null, "Inconsistent state: response consumer is null");
    responseConsumer.consumeContent(decoder, ioctrl);
}

From source file:org.apache.http.impl.nio.client.PipeliningClientExchangeHandlerImpl.java

@Override
public void responseCompleted() throws IOException, HttpException {
    if (this.log.isDebugEnabled()) {
        this.log.debug("[exchange: " + getId() + "] Response processed");
    }/*  w  ww  . j ava  2  s . co m*/

    final boolean keepAlive = manageConnectionPersistence();

    final HttpAsyncResponseConsumer<T> responseConsumer = this.responseConsumerRef.getAndSet(null);
    Asserts.check(responseConsumer != null, "Inconsistent state: response consumer is null");
    try {
        responseConsumer.responseCompleted(this.localContext);
        final T result = responseConsumer.getResult();
        final Exception ex = responseConsumer.getException();
        try {
            responseConsumer.close();
        } catch (final IOException ioex) {
            this.log.debug(ioex.getMessage(), ioex);
        }
        if (result != null) {
            this.resultQueue.add(result);
        } else {
            failed(ex);
        }
        if (!this.resultFuture.isDone() && this.responseConsumerQueue.isEmpty()) {
            this.resultFuture.completed(new ArrayList<T>(this.resultQueue));
            this.resultQueue.clear();
        }

        if (this.resultFuture.isDone()) {
            close();
        } else {
            if (!keepAlive) {
                failed(new ConnectionClosedException("Connection closed"));
            } else {
                final NHttpClientConnection localConn = getConnection();
                if (localConn != null) {
                    localConn.requestOutput();
                } else {
                    requestConnection();
                }
            }
        }
    } catch (final RuntimeException ex) {
        failed(ex);
        throw ex;
    }
}

From source file:org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl.java

@Override
public void bind(final IOSession iosession) {
    Args.notNull(iosession, "I/O session");
    Asserts.check(!iosession.isClosed(), "I/O session is closed");
    this.status = ACTIVE;
    this.original = iosession;
    if (this.log.isDebugEnabled() || this.wirelog.isDebugEnabled()) {
        this.log.debug(this.id + " Upgrade session " + iosession);
        super.bind(new LoggingIOSession(iosession, this.id, this.log, this.wirelog));
    } else {//from  w  ww. jav  a 2  s. c om
        super.bind(iosession);
    }
}

From source file:org.apache.http.nio.testserver.HttpServerNio.java

public void start() throws IOException {
    Asserts.check(this.server == null, "Server already running");
    this.server = ServerBootstrap.bootstrap()
            .setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(this.timeout).build())
            .setServerInfo("TEST-SERVER/1.1").setConnectionFactory(connectionFactory)
            .setExceptionLogger(new SimpleExceptionLogger()).setExpectationVerifier(this.expectationVerifier)
            .setHttpProcessor(this.httpProcessor).setHandlerMapper(this.reqistry).create();
    this.server.start();
}

From source file:org.apache.http.testserver.HttpServer.java

public void start() throws IOException {
    Asserts.check(this.server == null, "Server already running");
    this.server = ServerBootstrap.bootstrap()
            .setSocketConfig(SocketConfig.custom().setSoTimeout(this.timeout).build())
            .setServerInfo("TEST-SERVER/1.1").setConnectionFactory(new LoggingConnFactory())
            .setExceptionLogger(new SimpleExceptionLogger()).setExpectationVerifier(this.expectationVerifier)
            .setHandlerMapper(this.reqistry).create();
    this.server.start();
}