Skip to content

Commit

Permalink
Simplified the class hierarchy of the HTTP handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Feb 24, 2016
1 parent f007f3a commit 78d44aa
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 79 deletions.
Expand Up @@ -31,7 +31,7 @@

@Authors("Nikolche Mihajlovski")
@Since("5.0.11")
public class FastHttpErrorHandler extends FastParamsAwareHttpHandler {
public class FastHttpErrorHandler extends AbstractAsyncHttpHandler {

private final ErrorHandler handler;

Expand All @@ -41,8 +41,7 @@ public FastHttpErrorHandler(FastHttp http, ErrorHandler handler) {
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel ctx, boolean isKeepAlive, Req req, Object extra) throws Exception {
return handler.onError(req, req.response(), (Throwable) extra);
}

}

This file was deleted.

Expand Up @@ -31,7 +31,7 @@

@Authors("Nikolche Mihajlovski")
@Since("5.1.0")
public class FastParamsAwareReqHandler extends FastParamsAwareHttpHandler {
public class FastParamsAwareReqHandler extends AbstractAsyncHttpHandler {

private final ReqHandler handler;

Expand All @@ -41,7 +41,7 @@ public FastParamsAwareReqHandler(FastHttp http, MediaType contentType, HttpWrapp
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel ctx, boolean isKeepAlive, Req req, Object extra) throws Exception {
return handler.execute(req);
}

Expand Down
Expand Up @@ -40,7 +40,7 @@
@Since("5.1.0")
public class HttpHandlers {

public static FastParamsAwareHttpHandler from(FastHttp http, NParamLambda handler, MediaType contentType, HttpWrapper[] wrappers) {
public static FastHttpHandler from(FastHttp http, NParamLambda handler, MediaType contentType, HttpWrapper[] wrappers) {
if (handler instanceof ReqHandler) {
return new DelegatingFastParamsAwareReqHandler(http, contentType, wrappers, (ReqHandler) handler);

Expand Down Expand Up @@ -109,7 +109,7 @@ public static void register(FastHttp[] httpImpls, String verb, String path, Medi

public static void register(FastHttp[] httpImpls, String verb, String path, MediaType contentType, HttpWrapper[] wrappers, NParamLambda lambda) {
for (FastHttp http : httpImpls) {
FastParamsAwareHttpHandler handler = HttpHandlers.from(http, lambda, contentType, wrappers);
FastHttpHandler handler = HttpHandlers.from(http, lambda, contentType, wrappers);
http.on(verb, path, handler);
}
}
Expand Down
Expand Up @@ -44,7 +44,7 @@ public MethodReqHandler(FastHttp http, MediaType contentType, HttpWrapper[] wrap
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return AOP.invoke(null, method, instance, args(req));
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public FiveParamLambdaHandler(FastHttp http, MediaType contentType, HttpWrapper[
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return lambda.execute(arg(req, 0), arg(req, 1), arg(req, 2), arg(req, 3), arg(req, 4));
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public FourParamLambdaHandler(FastHttp http, MediaType contentType, HttpWrapper[
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return lambda.execute(arg(req, 0), arg(req, 1), arg(req, 2), arg(req, 3));
}

Expand Down
Expand Up @@ -25,14 +25,14 @@
import org.rapidoid.http.FastHttp;
import org.rapidoid.http.HttpWrapper;
import org.rapidoid.http.Req;
import org.rapidoid.http.handler.FastParamsAwareHttpHandler;
import org.rapidoid.http.handler.AbstractAsyncHttpHandler;
import org.rapidoid.http.handler.param.ParamRetriever;
import org.rapidoid.http.handler.param.ParamRetrievers;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public abstract class NParamMethodHandler extends FastParamsAwareHttpHandler {
public abstract class NParamMethodHandler extends AbstractAsyncHttpHandler {

private final ParamRetriever[] paramRetrievers;

Expand Down
Expand Up @@ -42,7 +42,7 @@ public OneParamLambdaHandler(FastHttp http, MediaType contentType, HttpWrapper[]
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return lambda.execute(arg(req, 0));
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public SevenParamLambdaHandler(FastHttp http, MediaType contentType, HttpWrapper
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return lambda.execute(arg(req, 0), arg(req, 1), arg(req, 2), arg(req, 3), arg(req, 4), arg(req, 5), arg(req, 6));
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public SixParamLambdaHandler(FastHttp http, MediaType contentType, HttpWrapper[]
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return lambda.execute(arg(req, 0), arg(req, 1), arg(req, 2), arg(req, 3), arg(req, 4), arg(req, 5));
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public ThreeParamLambdaHandler(FastHttp http, MediaType contentType, HttpWrapper
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return lambda.execute(arg(req, 0), arg(req, 1), arg(req, 2));
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public TwoParamLambdaHandler(FastHttp http, MediaType contentType, HttpWrapper[]
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return lambda.execute(arg(req, 0), arg(req, 1));
}

Expand Down
Expand Up @@ -26,14 +26,14 @@
import org.rapidoid.http.FastHttp;
import org.rapidoid.http.HttpWrapper;
import org.rapidoid.http.Req;
import org.rapidoid.http.handler.FastParamsAwareHttpHandler;
import org.rapidoid.http.handler.AbstractAsyncHttpHandler;
import org.rapidoid.lambda.OneParamLambda;
import org.rapidoid.net.abstracts.Channel;
import org.rapidoid.u.U;

@Authors("Nikolche Mihajlovski")
@Since("5.1.0")
public class DelegatingFastParamsAwareReqHandler extends FastParamsAwareHttpHandler {
public class DelegatingFastParamsAwareReqHandler extends AbstractAsyncHttpHandler {

private final OneParamLambda<Object, Req> handler;

Expand All @@ -44,7 +44,7 @@ public DelegatingFastParamsAwareReqHandler(FastHttp http, MediaType contentType,
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return handler.execute(req);
}

Expand Down
Expand Up @@ -27,14 +27,14 @@
import org.rapidoid.http.HttpWrapper;
import org.rapidoid.http.Req;
import org.rapidoid.http.Resp;
import org.rapidoid.http.handler.FastParamsAwareHttpHandler;
import org.rapidoid.http.handler.AbstractAsyncHttpHandler;
import org.rapidoid.lambda.TwoParamLambda;
import org.rapidoid.net.abstracts.Channel;
import org.rapidoid.u.U;

@Authors("Nikolche Mihajlovski")
@Since("5.1.0")
public class DelegatingFastParamsAwareReqRespHandler extends FastParamsAwareHttpHandler {
public class DelegatingFastParamsAwareReqRespHandler extends AbstractAsyncHttpHandler {

private final TwoParamLambda<Object, Req, Resp> handler;

Expand All @@ -45,7 +45,7 @@ public DelegatingFastParamsAwareReqRespHandler(FastHttp http, MediaType contentT
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return handler.execute(req, req.response());
}

Expand Down
Expand Up @@ -27,14 +27,14 @@
import org.rapidoid.http.HttpWrapper;
import org.rapidoid.http.Req;
import org.rapidoid.http.Resp;
import org.rapidoid.http.handler.FastParamsAwareHttpHandler;
import org.rapidoid.http.handler.AbstractAsyncHttpHandler;
import org.rapidoid.lambda.OneParamLambda;
import org.rapidoid.net.abstracts.Channel;
import org.rapidoid.u.U;

@Authors("Nikolche Mihajlovski")
@Since("5.1.0")
public class DelegatingFastParamsAwareRespHandler extends FastParamsAwareHttpHandler {
public class DelegatingFastParamsAwareRespHandler extends AbstractAsyncHttpHandler {

private final OneParamLambda<Object, Resp> handler;

Expand All @@ -45,7 +45,7 @@ public DelegatingFastParamsAwareRespHandler(FastHttp http, MediaType contentType
}

@Override
protected Object doHandle(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
protected Object handleReq(Channel channel, boolean isKeepAlive, Req req, Object extra) throws Exception {
return handler.execute(req.response());
}

Expand Down
Expand Up @@ -24,7 +24,7 @@
import org.rapidoid.annotation.Since;
import org.rapidoid.commons.MediaType;
import org.rapidoid.http.*;
import org.rapidoid.http.handler.FastParamsAwareHttpHandler;
import org.rapidoid.http.handler.FastHttpHandler;
import org.rapidoid.http.handler.FastStaticHttpHandler;
import org.rapidoid.http.handler.HttpHandlers;
import org.rapidoid.http.handler.optimized.FastCallableHttpHandler;
Expand Down Expand Up @@ -76,7 +76,7 @@ public Object execute(Req req) throws Exception {

private void register(PageOptions options, NParamLambda lambda) {
for (FastHttp http : httpImpls) {
FastParamsAwareHttpHandler handler = HttpHandlers.from(http, lambda, options.contentType, wrappers);
FastHttpHandler handler = HttpHandlers.from(http, lambda, options.contentType, wrappers);
http.on("GET", path, handler);
http.on("POST", path, handler);
}
Expand Down

0 comments on commit 78d44aa

Please sign in to comment.