All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clouway.friendlyserve.RequiresParam Maven / Gradle / Ivy

There is a newer version: 0.1.5
Show newest version
package com.clouway.friendlyserve;

import java.io.IOException;

import static com.google.common.base.Strings.isNullOrEmpty;

/**
 * RequiresParam is a decorating class over {@link Fork} which checks whether the provided param is passed with the request.
 *
 * 

* In cases when param is not passed, the route method is throwing {@link HttpException} with BAD_REQUEST value to indicate * that some of the params is missing. *

* * @author Miroslav Genov ([email protected]) */ public class RequiresParam implements Take { private final String param; private final Take origin; public RequiresParam(String param, Take origin) { this.param = param; this.origin = origin; } @Override public Response ack(Request request) throws IOException { String paramValue = request.param(this.param); if (isNullOrEmpty(paramValue)) { return new RsBadRequest(); } return origin.ack(request); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy