com.yahoo.bard.webservice.web.DataApiRequestMapperUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fili-core Show documentation
Show all versions of fili-core Show documentation
Fili web service library provides core capabilities for RESTful aggregation navigation, query planning and
metadata
// Copyright 2019 Yahoo Inc.
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms.
package com.yahoo.bard.webservice.web;
import com.yahoo.bard.webservice.data.config.ResourceDictionaries;
import com.yahoo.bard.webservice.web.apirequest.ApiRequest;
import java.util.function.BiFunction;
import javax.ws.rs.container.ContainerRequestContext;
/**
* A set of methods for generating utility mappers for ApiRequestMapping chains.
*/
public class DataApiRequestMapperUtils {
/**
* Create a request mapper that always returns an unmodified request.
*
* @param resourceDictionaries The dictionaries used for mapping the request.
*
* @return The request passed in, unmodified.
*/
public static RequestMapper identityMapper(ResourceDictionaries resourceDictionaries) {
return new RequestMapper(resourceDictionaries) {
@Override
public ApiRequest apply(final ApiRequest request, final ContainerRequestContext context)
throws RequestValidationException {
return request;
};
};
};
/**
* Create a requestMapper that always throws a validation exception based on the request.
* This can be used to 'cap' a filter path where the 'default' should only be hit exceptionally.
*
* @param resourceDictionaries The dictionaries used for mapping the request.
* @param exceptionSource A function to create a request validation exception.
*
* @return A request mapper that will always fail on a validation exception.
*/
public static RequestMapper validationExceptionMapper(
ResourceDictionaries resourceDictionaries,
BiFunction exceptionSource
) {
return new RequestMapper(resourceDictionaries) {
@Override
public ApiRequest apply(final ApiRequest request, final ContainerRequestContext context)
throws RequestValidationException {
throw exceptionSource.apply(request, context);
};
};
};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy