Example usage for io.vertx.core.http HttpServerResponse end

List of usage examples for io.vertx.core.http HttpServerResponse end

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServerResponse end.

Prototype

@Override
void end(Buffer chunk, Handler<AsyncResult<Void>> handler);

Source Link

Document

Same as #end(Buffer) but with an handler called when the operation completes

Usage

From source file:net.akehurst.example.xtext.vertx.VertxXTextHandler.java

License:Apache License

@Override
public void handle(final RoutingContext context) {
    final IServiceContext xCtx = new VertxXTextServiceContext(context);
    final IServiceResult sr = this.xtext.getService(xCtx).getService().apply();
    final HttpServerResponse response = context.response();
    response.setStatusCode(200);//from   w w  w.  j  a v  a  2  s . c  o  m
    response.putHeader("Cache-Control", "no-cache");
    final String encoding = "UTF-8";
    if (sr instanceof IUnwrappableServiceResult && ((IUnwrappableServiceResult) sr).getContent() != null) {
        final IUnwrappableServiceResult unwrapResult = (IUnwrappableServiceResult) sr;
        String contentType = unwrapResult.getContentType();
        if (contentType == null) {
            contentType = "text/plain";
        }
        response.putHeader("Content-Type", contentType);
        final String s = unwrapResult.getContent();
        response.end(s, encoding);
    } else {
        response.putHeader("Content-Type", "text/x-json");
        final String s = this.gson.toJson(sr);
        response.end(s, encoding);
    }
}

From source file:org.jadala.pne.StatusPageHandler.java

@Override
public void handle(RoutingContext context) {
    HttpServerResponse response = context.response();
    response.headers().set("content-type", "text/html");
    response.end(page.replace("{{version}}", version), "UTF-8");
}

From source file:org.sfs.rx.KeptAliveTerminus.java

License:Apache License

@Override
public void onError(Throwable e) {
    JsonObject document = new JsonObject();
    HttpServerResponse response = httpServerRequest.response();
    if (e instanceof HttpRequestValidationException) {
        HttpRequestValidationException cause = (HttpRequestValidationException) e;
        JsonObject entity = cause.getEntity();
        int status = cause.getStatusCode();

        LOGGER.debug("Validate Error", e);
        document.put("status", status).put("message", entity.encode());

    } else if (e instanceof HttpStatusCodeException) {
        HttpStatusCodeException cause = (HttpStatusCodeException) e;

        LOGGER.debug("HttpStatusCode Error", e);
        document.put("status", cause.getStatusCode());

    } else {/* w w w. j a  va 2s .  c  o  m*/
        LOGGER.error("Unhandled Exception", e);
        document.put("status", HTTP_INTERNAL_ERROR);
    }
    response.end(document.encode(), UTF_8.toString());
}