Example usage for org.apache.http.nio.protocol HttpAsyncExchange getResponse

List of usage examples for org.apache.http.nio.protocol HttpAsyncExchange getResponse

Introduction

In this page you can find the example usage for org.apache.http.nio.protocol HttpAsyncExchange getResponse.

Prototype

HttpResponse getResponse();

Source Link

Document

Returns the default HTTP response message.

Usage

From source file:com.mycompany.allasync.NHttpRequestHandler.java

public void handle(final HttpRequest request, final HttpAsyncExchange httpexchange, final HttpContext context)
        throws HttpException, IOException {
    HttpResponse response = httpexchange.getResponse();
    handleInternal(request, response, context);
    httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
}

From source file:talkeeg.server.BarcodeProvider.java

@Override
public void handle(HttpRequest data, HttpAsyncExchange httpExchange, HttpContext context)
        throws HttpException, IOException {
    final BinaryData barcodeData = this.helloProvider.get().helloAsBinaryData();
    final BitMatrix matrix = this.barcodeServiceProvider.get().encode(barcodeData);
    final BufferedImage image = BarcodeUtilsSE.toBufferedImage(matrix);
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
    ImageIO.write(image, "png", tmp);
    final HttpResponse response = httpExchange.getResponse();
    response.setHeader("Content-Type", "image/png");
    response.setEntity(new ByteArrayEntity(tmp.toByteArray()));
    response.setStatusCode(HttpStatus.SC_OK);
    httpExchange.submitResponse(new BasicAsyncResponseProducer(response));
}