use of org.webpieces.router.api.routes.MethodMeta in project webpieces by deanhiller.
the class StreamProxy method openStream.
@Override
public RouterStreamRef openStream(MethodMeta meta, ProxyStreamHandle handle) {
RequestContext requestCtx = meta.getCtx();
LoadedController loadedController = meta.getLoadedController();
Object instance = loadedController.getControllerInstance();
Method controllerMethod = loadedController.getControllerMethod();
Parameter[] parameters = loadedController.getParameters();
if (parameters.length != 1)
throw new IllegalArgumentException("Your method='" + controllerMethod + "' MUST one parameter and does not. It needs to take a RouterStreamHandler");
else if (!ResponseStreamHandle.class.equals(parameters[0].getType()))
throw new IllegalArgumentException("The single parameter must be RouterStreamHandle and was not for this method='" + controllerMethod + "'");
else if (!StreamRef.class.equals(controllerMethod.getReturnType()))
throw new IllegalArgumentException("The return value must be a subclass of StreamRef and was not for this method='" + controllerMethod + "'");
StreamRef streamRef = invokeStream(meta, controllerMethod, instance, requestCtx, handle);
XFuture<StreamWriter> writer = streamRef.getWriter();
XFuture<StreamWriter> newFuture = futureUtil.catchBlockWrap(() -> writer, (t) -> convert(loadedController, t));
Function<CancelReason, XFuture<Void>> cancelFunc = (reason) -> streamRef.cancel(reason);
return new RouterStreamRef("streamProxy", newFuture, cancelFunc);
}
use of org.webpieces.router.api.routes.MethodMeta in project webpieces by deanhiller.
the class JacksonCatchAllFilter method printPreRequestLog.
protected void printPreRequestLog(MethodMeta meta) {
Method method = meta.getLoadedController().getControllerMethod();
RouterRequest request = meta.getCtx().getRequest();
// Use this fancifully-named logger so that you can filter these out by controller method in your logging config
final Logger preRequestLog = LoggerFactory.getLogger(getClass().getSimpleName() + "." + method.getDeclaringClass().getName() + "." + method.getName());
String httpMethod = request.method.getCode();
String endpoint = httpMethod + " " + request.domain + ":" + request.port + request.relativePath;
List<String> headers = meta.getCtx().getRequest().originalRequest.getHeaders().stream().map(h -> h.getName() + ": " + h.getValue()).collect(Collectors.toList());
String json = new String(request.body.createByteArray());
// Print a pre-request log that describes the request
preRequestLog.info("The following log is the original request body and its headers. If this log is spammy or " + "unnecessary you can disable it in your logging config by filtering out this logger: {}", preRequestLog.getName());
preRequestLog.info("{}:\n\n" + "Headers: {}\n\n" + "Request Body JSON:\n{}", endpoint, headers, json);
}
Aggregations