Example usage for io.vertx.core.http HttpHeaders ACCEPT

List of usage examples for io.vertx.core.http HttpHeaders ACCEPT

Introduction

In this page you can find the example usage for io.vertx.core.http HttpHeaders ACCEPT.

Prototype

CharSequence ACCEPT

To view the source code for io.vertx.core.http HttpHeaders ACCEPT.

Click Source Link

Document

Accept header name

Usage

From source file:com.hubrick.vertx.rest.impl.DefaultRestClientRequest.java

License:Apache License

@Override
public void setAcceptHeader(List<MediaType> mediaTypes) {
    bufferedHttpOutputMessage.getHeaders().set(HttpHeaders.ACCEPT, formatForAcceptHeader(mediaTypes));
}

From source file:com.hubrick.vertx.rest.impl.DefaultRestClientRequest.java

License:Apache License

@Override
public List<MediaType> getAcceptHeader() {
    final String acceptHeader = bufferedHttpOutputMessage.getHeaders().get(HttpHeaders.ACCEPT);
    if (Strings.isNullOrEmpty(acceptHeader)) {
        return Collections.emptyList();
    } else {/*from  w  w  w .j a  va  2 s .  c om*/
        return FluentIterable.from(Splitter.on(",").split(acceptHeader)).toList().stream()
                .map(MediaType::parseMediaType).collect(Collectors.toList());
    }
}

From source file:com.hubrick.vertx.rest.impl.DefaultRestClientRequest.java

License:Apache License

private void populateAcceptHeaderIfNotPresent() {
    final String acceptHeader = httpClientRequest.headers().get(HttpHeaders.ACCEPT);
    if (Strings.isNullOrEmpty(acceptHeader)) {
        httpClientRequest.headers().set(HttpHeaders.ACCEPT, formatForAcceptHeader(httpMessageConverters.stream()
                .map(HttpMessageConverter::getSupportedMediaTypes).reduce(new LinkedList<>(), (a, b) -> {
                    a.addAll(b);//from  w  w  w .ja  va  2s.  com
                    return a;
                })));
    }
}

From source file:com.thesoftwarefactory.vertx.web.more.impl.WebContextImpl.java

License:Apache License

@Override
public DeviceInfo deviceInfo() {
    if (deviceInfo == null) {
        String userAgent = routingContext.request().getHeader(HttpHeaders.USER_AGENT.toString());
        String httpAccept = routingContext.request().getHeader(HttpHeaders.ACCEPT.toString());
        deviceInfo = new DeviceInfoMobileEsp(userAgent, httpAccept);
    }/*from w w w  . j a v  a2 s  .c om*/
    return deviceInfo;
}

From source file:de.elsibay.EbbTicketShowcase.java

License:Open Source License

@Override
public void start(Future<Void> startFuture) throws Exception {

    SessionStore sessionStore = LocalSessionStore.create(vertx);
    Router backendRouter = Router.router(vertx);
    backendRouter.route().handler(LoggerHandler.create(LoggerHandler.DEFAULT_FORMAT));
    CookieHandler cookieHandler = CookieHandler.create();
    SessionHandler sessionHandler = SessionHandler.create(sessionStore);
    // the CORS OPTION request must not set cookies
    backendRouter.get().handler(cookieHandler);
    backendRouter.get().handler(sessionHandler);
    backendRouter.post().handler(cookieHandler);
    backendRouter.post().handler(sessionHandler);

    // setup CORS
    CorsHandler corsHandler = CorsHandler.create("http(s)?://" + WEBSERVER_HOST + ":" + WEBSERVER_PORT)
            .allowCredentials(true).allowedHeader(HttpHeaders.ACCEPT.toString())
            .allowedHeader(HttpHeaders.ORIGIN.toString()).allowedHeader(HttpHeaders.AUTHORIZATION.toString())
            .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()).allowedHeader(HttpHeaders.COOKIE.toString())
            .exposedHeader(HttpHeaders.SET_COOKIE.toString()).allowedMethod(HttpMethod.POST)
            .allowedMethod(HttpMethod.PUT).allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.DELETE);

    // setup event bus bridge
    TicketEventbusBridge sebb = new TicketEventbusBridge(sessionStore);
    backendRouter.mountSubRouter("/eventbus", sebb.route(vertx));

    // dummy eventbus services
    vertx.eventBus().consumer("ping", (Message<JsonObject> msg) -> {
        msg.reply(new JsonObject().put("answer", "pong " + msg.body().getString("text", "")));
    });/*  ww  w.  j a v a  2 s .c  o  m*/

    vertx.setPeriodic(5000, id -> {
        vertx.eventBus().send("topic", new JsonObject().put("timestamp", new Date().getTime()));
    });

    // session manager for login
    backendRouter.route("/api/*").handler(corsHandler);
    backendRouter.route("/api/*").method(HttpMethod.POST).method(HttpMethod.PUT).handler(BodyHandler.create());

    backendRouter.route("/api/session").handler((RoutingContext rc) -> {
        JsonObject user = rc.getBodyAsJson();
        String sessionId = rc.session().id();
        rc.session().put("user", user);
        rc.response().end(user.copy().put("sessionId", sessionId).encodePrettily());
    });

    // dummy ping REST service
    backendRouter.route("/api/ping").handler((RoutingContext rc) -> {
        JsonObject replyMsg = new JsonObject();
        replyMsg.put("timestamp", new Date().getTime());
        Cookie sessionCookie = rc.getCookie(SessionHandler.DEFAULT_SESSION_COOKIE_NAME);
        if (sessionCookie != null) {
            replyMsg.put("sessionId", sessionCookie.getValue());
        }
        rc.response().end(replyMsg.encode());
    });

    // start backend on one port
    vertx.createHttpServer().requestHandler(backendRouter::accept).listen(BACKENDSERVER_PORT,
            BACKENDSERVER_HOST, (AsyncResult<HttpServer> async) -> {
                System.out
                        .println(async.succeeded() ? "Backend Server started" : "Backend Server start FAILED");
            });

    // static files on other port
    Router staticFilesRouter = Router.router(vertx);
    staticFilesRouter.route("/*").handler(StaticHandler.create("src/main/www").setCachingEnabled(false));
    vertx.createHttpServer().requestHandler(staticFilesRouter::accept).listen(WEBSERVER_PORT, WEBSERVER_HOST,
            (AsyncResult<HttpServer> async) -> {
                System.out.println(async.succeeded()
                        ? "Web Server started\ngoto http://" + WEBSERVER_HOST + ":" + WEBSERVER_PORT + "/"
                        : "Web Server start FAILED");
            });
}

From source file:org.etourdot.vertx.marklogic.http.impl.request.DefaultMarklogicRequest.java

License:Open Source License

@Override
public void execute() {
    final HttpClientRequest httpClientRequest = httpClient.request(method, uriEncoder.toString());
    httpClientRequest.handler(new AuthHttpHandler(this, responseHandler));
    httpClientRequest.putHeader(HttpHeaders.ACCEPT, Format.JSON.getDefaultMimetype());
    if (authorization == null && AuthScheme.Type.BASIC == realm.getSchemeType()) {
        authorize(uri, AuthSchemeFactory.newScheme(realm));
    }//from  www.j ava 2 s .c om
    if (authorization != null) {
        httpClientRequest.putHeader(HttpHeaders.AUTHORIZATION, authorization);
    }
    if (body != null) {
        httpClientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(contentLength))
                .putHeader(HttpHeaders.CONTENT_TYPE, contentType).write(body);
    }
    httpClientRequest.exceptionHandler(exception -> {
        responseHandler.handle(new ErrorResponse(exception));
    }).end();
}

From source file:org.etourdot.vertx.marklogic.http.impl.request.DefaultMultiPartRequest.java

License:Open Source License

@Override
public void execute() {
    final HttpClientRequest httpClientRequest = httpClient.request(method, uriEncoder.toString());
    httpClientRequest.handler(new AuthHttpHandler(this, responseHandler));
    if (HttpMethod.POST == method) {
        httpClientRequest.putHeader(HttpHeaders.ACCEPT, Format.JSON.getDefaultMimetype());
        httpClientRequest.putHeader(HttpHeaders.CONTENT_TYPE, "multipart/mixed; boundary=" + boundary);
    } else {/*from  w w  w. jav  a 2  s. co  m*/
        httpClientRequest.putHeader(HttpHeaders.ACCEPT, "multipart/mixed; boundary=" + boundary);
        httpClientRequest.putHeader(HttpHeaders.CONTENT_TYPE, Format.JSON.getDefaultMimetype());
    }
    if (authorization != null) {
        httpClientRequest.putHeader(HttpHeaders.AUTHORIZATION, authorization);
    }
    if (body != null) {
        httpClientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(contentLength)).write(body);
    } else if (!parts.isEmpty()) {
        long computeLength = 0;
        String boundaryString = "--" + boundary;
        Buffer buffer = Buffer.buffer();
        for (HttpPart part : parts) {
            Buffer partBuffer = part.toBuffer();
            buffer.appendString(boundaryString).appendString(System.lineSeparator()).appendBuffer(partBuffer)
                    .appendString(System.lineSeparator());
            computeLength += boundaryString.length() + partBuffer.length()
                    + 2 * System.lineSeparator().length();
        }
        buffer.appendString(boundaryString).appendString("--").appendString(System.lineSeparator());
        computeLength += boundaryString.length() + 2 + System.lineSeparator().length();
        httpClientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(computeLength)).write(buffer);
    }
    httpClientRequest.end();
}

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

@Override
public void start(Future<Void> startFuture) throws Exception {

    final String originPattern = this.config().getString("origin_pattern", ORIGIN_PATTERN);

    final int httpPort = this.config().getInteger("http_port", 8080);
    String cp = this.config().getString("context", "/");
    if (!cp.endsWith("/")) {
        cp = cp + "/";
    }/*from  www.j a v a  2  s.c o m*/
    if (!cp.startsWith("/")) {
        cp = "/" + cp;
    }
    final String contextPath = cp;

    Router router = Router.router(vertx);
    router.route().handler(LoggerHandler.create(LoggerHandler.DEFAULT_FORMAT));

    // setup CORS
    CorsHandler corsHandler = CorsHandler.create(originPattern).allowCredentials(true)
            .allowedHeader(HttpHeaders.ACCEPT.toString()).allowedHeader(HttpHeaders.ORIGIN.toString())
            .allowedHeader(HttpHeaders.AUTHORIZATION.toString())
            .allowedHeader(HttpHeaders.CONTENT_TYPE.toString()).allowedHeader(HttpHeaders.COOKIE.toString())
            .exposedHeader(HttpHeaders.SET_COOKIE.toString()).allowedMethod(HttpMethod.POST)
            .allowedMethod(HttpMethod.PUT).allowedMethod(HttpMethod.GET).allowedMethod(HttpMethod.DELETE);

    router.route(contextPath + "api/*").handler(corsHandler);
    router.route(contextPath + "api/*").method(HttpMethod.POST).method(HttpMethod.PUT)
            .handler(BodyHandler.create());

    // config jwt service
    JsonWebTokenHandler jwtService = new JsonWebTokenHandler(vertx, config().getJsonObject("keyStore"));
    router.post(contextPath + "api/jwt").handler(jwtService);

    // status page
    String version = config().getString("version", "unknown");
    router.get(contextPath).handler(new StatusPageHandler(version));

    router.post(contextPath + "api/node").handler(new NodeHandler(vertx));
    router.get(contextPath + "api/node").handler(new NodeHandler(vertx));
    //        router.post(contextPath + "api/organisation").handler(new PersonHandler(vertx));
    //        router.get(contextPath + "api/organisation").handler(new PersonHandler(vertx));
    vertx.deployVerticle(ElasticClient.class.getName(), deploymentHandler("ElasticClient"));

    vertx.createHttpServer().requestHandler(router::accept).listen(httpPort,
            (AsyncResult<HttpServer> asyncHttpServer) -> {
                if (asyncHttpServer.succeeded()) {
                    System.out
                            .println("npe server started. listen at http://0.0.0.0:" + httpPort + contextPath);
                    startFuture.complete();
                } else {
                    startFuture.fail(asyncHttpServer.cause());
                }
            });

}