List of usage examples for io.vertx.core.http HttpHeaders CONTENT_TYPE
CharSequence CONTENT_TYPE
To view the source code for io.vertx.core.http HttpHeaders CONTENT_TYPE.
Click Source Link
From source file:com.baldmountain.depot.DepotTemplateHandler.java
License:Open Source License
public void renderSpecificPath(RoutingContext context, String path) { String file = templateDirectory + path; engine.render(context, file, res -> { if (res.succeeded()) { context.response().putHeader(HttpHeaders.CONTENT_TYPE, contentType).end(res.result()); } else {/*from www . ja va 2s. c om*/ context.fail(res.cause()); } }); }
From source file:com.cyngn.vertx.bosun.BosunReporter.java
License:Apache License
/** * Send data to the bosun instance//w w w . j a v a 2s.c om * * @param api the api on bosun to send to * @param data the json data to send * @param message the event bus message the request originated from */ private void sendData(String api, String data, Message message) { HttpClient client = getNextHost(); Buffer buffer = Buffer.buffer(data.getBytes()); client.post(api).exceptionHandler(error -> { sendError(message, "Got ex contacting bosun, " + error.getLocalizedMessage()); }).handler(response -> { int statusCode = response.statusCode(); // is it 2XX if (statusCode >= HttpResponseStatus.OK.code() && statusCode < HttpResponseStatus.MULTIPLE_CHOICES.code()) { message.reply(new JsonObject().put(RESULT_FIELD, BosunResponse.OK_MSG)); } else { response.bodyHandler(responseData -> { sendError(message, "got non 200 response from bosun, error: " + responseData, statusCode); }); } }).setTimeout(timeout).putHeader(HttpHeaders.CONTENT_LENGTH, buffer.length() + "") .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()).write(buffer).end(); }
From source file:com.deblox.server.Server.java
License:Apache License
@Override public void start(Future<Void> startFuture) { logger.info("starting with config: " + config().toString()); Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions().addInboundPermitted(new PermittedOptions()) .addOutboundPermitted(new PermittedOptions()); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // broadcast some arbitary message router.post("/api/event").handler(ctx -> { ctx.response().putHeader("content-type", "text/json"); // curl -H "Content-Type: application/json" -X POST -d '{"topic":"release-event", "data":"something"}' localhost:8080/api/event ctx.request().bodyHandler(req -> { try { JsonObject msg = new JsonObject(req.toString()); logger.info(msg);/*w ww . j a v a2 s .c o m*/ eb.send(msg.getString("topic", "unknown"), msg.getJsonObject("data"), resp -> { ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json") .end(resp.result().body().toString()); }); } catch (Exception ex) { logger.error(ex.getMessage()); ctx.fail(500); } }); }); // Serve the static pages router.route().handler(StaticHandler.create().setCachingEnabled(false) .setWebRoot(config().getString("webroot", "webroot")).setDirectoryListing(false)); // the server itself vertx.createHttpServer().requestHandler(router::accept).listen(config().getInteger("port", 8080)); // need a bus! eb = vertx.eventBus(); // send back deployment complete startFuture.complete(); }
From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java
License:Open Source License
public static void ask(HttpServerResponse httpServerResponse, String conversationToken, String initialPrompt, String[] noInputPrompts) { httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8"); httpServerResponse.putHeader("Google-Assistant-API-Version", "v1"); JsonObject responseJSON = new JsonObject(); if (conversationToken != null) { responseJSON.put("conversation_token", conversationToken); }/*from w w w.ja va2 s. co m*/ responseJSON.put("expect_user_response", true); responseJSON.put("expected_inputs", JsonUtil.getArray(_getExpectedInputJSON(initialPrompt, noInputPrompts))); httpServerResponse.end(responseJSON.encode()); }
From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java
License:Open Source License
public static void tell(HttpServerResponse httpServerResponse, String textToSpeech) { httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8"); httpServerResponse.putHeader("Google-Assistant-API-Version", "v1"); JsonObject responseJSON = new JsonObject(); JsonObject finalResponseJSON = new JsonObject(); finalResponseJSON.put("speech_response", _getPromptJSON(textToSpeech)); responseJSON.put("final_response", finalResponseJSON); httpServerResponse.end(responseJSON.encode()); }
From source file:com.github.mcollovati.vertx.vaadin.VertxVaadinRequest.java
License:Open Source License
@Override public String getContentType() { return Optional.ofNullable(request.getHeader(HttpHeaders.CONTENT_TYPE)).map(CONTENT_TYPE_PATTERN::matcher) .filter(Matcher::matches).map(m -> m.group(1)).orElse(null); }
From source file:com.github.mcollovati.vertx.vaadin.VertxVaadinRequest.java
License:Open Source License
@Override public String getCharacterEncoding() { return Optional.ofNullable(request.getHeader(HttpHeaders.CONTENT_TYPE)).map(CHARSET_PATTERN::matcher) .filter(Matcher::matches).map(m -> m.group(1)).orElse(null); }
From source file:com.github.mcollovati.vertx.vaadin.VertxVaadinResponse.java
License:Open Source License
@Override public void setContentType(String contentType) { response.putHeader(HttpHeaders.CONTENT_TYPE, contentType); }
From source file:com.hubrick.vertx.rest.converter.AbstractHttpMessageConverter.java
License:Apache License
@Override public void write(T object, MediaType contentType, HttpOutputMessage httpOutputMessage) throws HttpMessageConverterException { try {/* w ww. j av a 2s .c o m*/ final MultiMap headers = httpOutputMessage.getHeaders(); if (headers.get(HttpHeaders.CONTENT_TYPE) == null) { MediaType contentTypeToUse = contentType; if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) { contentTypeToUse = getDefaultContentType(object); } if (contentTypeToUse != null) { headers.set(HttpHeaders.CONTENT_TYPE, contentTypeToUse.toString()); } } writeInternal(object, httpOutputMessage); } catch (HttpMessageConverterException e) { throw e; } catch (Throwable t) { throw new HttpMessageConverterException("Error writing object", t); } }
From source file:com.hubrick.vertx.rest.converter.FormHttpMessageConverter.java
License:Apache License
@Override public Multimap<String, Object> read(Class<? extends Multimap<String, Object>> clazz, HttpInputMessage httpInputMessage) throws HttpMessageConverterException { final MediaType mediaType = MediaType .parseMediaType(httpInputMessage.getHeaders().get(HttpHeaders.CONTENT_TYPE)); Charset charset = (mediaType.getCharSet() != null ? mediaType.getCharSet() : this.charset); String body = new String(httpInputMessage.getBody(), charset); try {//from w w w . j av a 2s.c om String[] pairs = FluentIterable.from(Splitter.on("&").split(body)).toArray(String.class); Multimap<String, Object> result = HashMultimap.create(); for (String pair : pairs) { int idx = pair.indexOf('='); if (idx == -1) { result.put(URLDecoder.decode(pair, charset.name()), null); } else { String name = URLDecoder.decode(pair.substring(0, idx), charset.name()); String value = URLDecoder.decode(pair.substring(idx + 1), charset.name()); result.put(name, value); } } return result; } catch (UnsupportedEncodingException e) { throw new HttpMessageConverterException(e); } }