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

se.fortnox.reactivewizard.jaxrs.params.annotated.CookieParamResolver Maven / Gradle / Ivy

There is a newer version: 24.6.0
Show newest version
package se.fortnox.reactivewizard.jaxrs.params.annotated;

import com.fasterxml.jackson.core.type.TypeReference;
import se.fortnox.reactivewizard.jaxrs.JaxRsRequest;
import se.fortnox.reactivewizard.jaxrs.params.ParamResolver;
import se.fortnox.reactivewizard.jaxrs.params.deserializing.Deserializer;
import se.fortnox.reactivewizard.jaxrs.params.deserializing.DeserializerFactory;

import javax.ws.rs.CookieParam;
import java.lang.annotation.Annotation;

/**
 * Bind a cookie to a method parameter.
 */
public class CookieParamResolver extends AnnotatedParamResolver {

    public CookieParamResolver(Deserializer deserializer, Annotation cookieParamAnnotation, String defaultValue) {
        super(deserializer, ((CookieParam)cookieParamAnnotation).value(), defaultValue);
    }

    @Override
    protected String getValue(JaxRsRequest request) {
        return request.getCookieValue(parameterName, getDefaultValue());
    }

    public static class Factory implements AnnotatedParamResolverFactory {

        private final DeserializerFactory deserializerFactory;

        public Factory(DeserializerFactory deserializerFactory) {
            this.deserializerFactory = deserializerFactory;
        }

        @Override
        public  ParamResolver create(TypeReference paramType, Annotation annotation, String defaultValue) {
            return new CookieParamResolver<>(deserializerFactory.getParamDeserializer(paramType), annotation, defaultValue);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy