/** * @param entity A result content! * @return A new json result. */ @Nonnull public static Result xml(final Object entity) { return with(entity, 200).type(MediaType.xml); }
/** * Sets a response header with the given name and value. If the header had already been set, * the new value overwrites the previous one. * * @param name Header's name. * @param values Header's values. * @return This content. */ @Nonnull public Result header(final String name, final Object... values) { requireNonNull(name, "Header's name is required."); requireNonNull(values, "Header's values are required."); return header(name, ImmutableList.copyOf(values)); }
Optional<MediaType> rtype = finalResult.type(); if (rtype.isPresent()) { type(rtype.get()); Optional<Status> finalStatus = finalResult.status(); if (finalStatus.isPresent()) { status(finalStatus.get()); Map<String, Object> headers = finalResult.headers(); if (headers.size() > 0) { headers.forEach(this::setHeader); Object value = finalResult.get(produces);
/** * Performs content-negotiation on the Accept HTTP header on the request object. It select a * handler for the request, based on the acceptable types ordered by their quality values. * If the header is not specified, the first callback is invoked. When no match is found, * the server responds with 406 "Not Acceptable", or invokes the default callback: {@code ** / *}. * * <pre> * get("/jsonOrHtml", () {@literal ->} * Results * .when("text/html", () {@literal ->} Results.html("view").put("model", model))) * .when("application/json", () {@literal ->} model) * .when("*", () {@literal ->} {throw new Err(Status.NOT_ACCEPTABLE);}) * ); * </pre> * * @param type A media type. * @param supplier A result supplier. * @return A new result. */ @Nonnull public static Result when(final String type, final Supplier<Object> supplier) { return new Result().when(type, supplier); }
return (T) result; return result.get();
/** * Get a result value. * * @return Value or <code>empty</code> */ @Nonnull public Optional<Object> ifGet() { return ifGet(MediaType.ALL); }
@Override protected Result clone() { Result result = new Result(); headers.forEach(result::header); result.status = status; result.type = type; result.value = value; return result; }
Optional<MediaType> rtype = finalResult.type(); if (rtype.isPresent()) { type(rtype.get()); Optional<Status> finalStatus = finalResult.status(); if (finalStatus.isPresent()) { status(finalStatus.get()); Map<String, Object> headers = finalResult.headers(); if (headers.size() > 0) { headers.forEach(this::setHeader); Object value = finalResult.get(produces);
/** * Performs content-negotiation on the Accept HTTP header on the request object. It select a * handler for the request, based on the acceptable types ordered by their quality values. * If the header is not specified, the first callback is invoked. When no match is found, * the server responds with 406 "Not Acceptable", or invokes the default callback: {@code ** / *}. * * <pre> * get("/jsonOrHtml", () {@literal ->} * Results * .when("text/html", () {@literal ->} Results.html("view").put("model", model))) * .when("application/json", () {@literal ->} model) * .when("*", () {@literal ->} {throw new Err(Status.NOT_ACCEPTABLE);}) * ); * </pre> * * @param type A media type. * @param supplier A result supplier. * @return A new result. */ @Nonnull public static Result when(final MediaType type, final Supplier<Object> supplier) { return new Result().when(type, supplier); }
ws.send(event("print", r.get())); ws.send(event("prompt", shell.getPrompt())); ws.send(event("end"));
/** * Get a result value. * * @return Value or <code>empty</code> */ @Nonnull public Optional<Object> ifGet() { return ifGet(MediaType.ALL); }
@Override protected Result clone() { Result result = new Result(); headers.forEach(result::header); result.status = status; result.type = type; result.value = value; return result; }
/** * Set the content type of this content. * * @param type A content type. * @return This content. */ @Nonnull public Result type(final String type) { return type(MediaType.valueOf(type)); }
/** * Produces a redirect (302) status code and set the <code>Location</code> header too. * * @param status A HTTP redirect status. * @param location A location. * @return A new result. */ private static Result redirect(final Status status, final String location) { requireNonNull(location, "A location is required."); return with(status).header("location", location); }