package tech.greenfield.vertx.irked;

import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.impl.RoutingContextDecorator;

/**
 * Request handling wrapper which adds some useful routines for
 * API writers.
 * 
 * Can serve as a basis for local context parsers that API writers
 * can use to expose path arguments from parent prefixes
 * 
 * @author odeda
 */
public class Request extends RoutingContextDecorator {

	private RoutingContext outerContext;

	public Request(RoutingContext outerContext) {
		super(outerContext.currentRoute(), outerContext);
		this.outerContext = outerContext;
	}

	@Override
	public void fail(int statusCode) { 
		// we're overriding the fail handlers, which for some reason the decorator 
		// feels should be moved to another thread. Instead, use the outer implementation
		// and let it do what's right
		this.outerContext.fail(statusCode);
	}

	@Override
	public void fail(Throwable throwable) {
		// we're overriding the fail handlers, which for some reason the decorator 
		// feels should be moved to another thread. Instead, use the outer implementation
		// and let it do what's right
		this.outerContext.fail(throwable);
	}

}

@@ -31,16 +31,54 @@
 irked;%0A%0A
+import io.vertx.core.json.JsonObject;%0A
 import i
@@ -109,16 +109,16 @@
 ontext;%0A
-
 import i
@@ -162,16 +162,62 @@
 corator;
+%0Aimport tech.greenfield.vertx.irked.status.OK;
 %0A%0A/**%0A *
@@ -1203,32 +1203,32 @@
 do what's right%0A
-
 %09%09this.outerCont
@@ -1250,12 +1250,1245 @@
 ble);%0A%09%7D
+%0A%09%0A%09/**%0A%09 * Helper method to terminate request processing with a success (200 OK) response containing a JSON body.%0A%09 * @param json %7B@link JsonObject%7D containing the output to encode%0A%09 */%0A%09public void sendJSON(JsonObject json) %7B%0A%09%09sendJSON(json, new OK());%0A%09%7D%0A%09%0A%09/**%0A%09 * Helper method to terminate request processing with a custom response containing a JSON body and the specified%0A%09 * status line.%0A%09 * @param json %7B@link JsonObject%7D containing the output to encode%0A%09 * @param status HTTP status to send%0A%09 */%0A%09public void sendJSON(JsonObject json, HttpError status) %7B%0A%09%09String content = json.encode();%0A%09%09response()%0A%09%09%09.putHeader(%22Content-Type%22, %22application/json%22)%0A%09%09%09.putHeader(%22Content-Length%22, String.valueOf(content.length()))%0A%09%09%09.end(content);%0A%09%7D%0A%09%0A%09/**%0A%09 * Helper method to terminate request processing with an HTTP error (non-200 OK) response.%0A%09 * The resulting HTTP response will have the correct status line and an application/json content%0A%09 * with a JSON encoded object containing the fields %22status%22 set to %22false%22 and %22message%22 set%0A%09 * to the %7B@link HttpError%7D's message.%0A%09 * @param err%0A%09 */%0A%09public void sendError(HttpError err) %7B%0A%09%09sendJSON(new JsonObject().put(%22status%22, false).put(%22message%22, err.getMessage()), err);%0A%09%7D
 %0A%0A%7D%0A

add request helper methods to send stuff