Created
June 4, 2017 16:33
-
-
Save abhirockzz/3d51417149d7097090f64c88f1fe2aa8 to your computer and use it in GitHub Desktop.
JAX-RS filter to validate query parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Provider | |
@QueryParamValidator | |
public class JAXRSReqFilter implements ContainerRequestFilter{ | |
@Override | |
public void filter(ContainerRequestContext requestContext) throws IOException { | |
MultivaluedMap<String, String> queryParameters = requestContext.getUriInfo().getQueryParameters(); | |
String queryParam = queryParameters.keySet().stream().findFirst().get(); | |
System.out.println("Query param - "+ queryParam); | |
if(!queryParam.equals("p")){ | |
requestContext.abortWith(Response | |
.status(Response.Status.BAD_REQUEST) | |
.entity("Invalid Query Param "+ queryParam) | |
.build()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment