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

io.crnk.rs.internal.legacy.JaxrsParameterProvider Maven / Gradle / Ivy

There is a newer version: 2.6.20180430102904
Show newest version
package io.crnk.rs.internal.legacy;

import java.lang.reflect.Method;
import javax.ws.rs.CookieParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.SecurityContext;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.crnk.core.utils.Optional;
import io.crnk.legacy.internal.RepositoryMethodParameterProvider;
import io.crnk.rs.internal.legacy.provider.Parameter;
import io.crnk.rs.internal.legacy.provider.RequestContextParameterProvider;

/**
 * 

* An implementation of legacy provider for JAX-RS integration based on a registry of RequestContextParameterProvider * provided by an instance of RequestContextParameterProviderRegistry. * By default, the registry supports the following parameters: *

*
    *
  1. {@link ContainerRequestContext}
  2. *
  3. {@link SecurityContext}
  4. *
  5. Values annotated with {@link CookieParam}
  6. *
  7. Values annotated with {@link HeaderParam}
  8. *
  9. Values annotated with {@link QueryParam}
  10. *
*

* Value casting for values annotated with {@link CookieParam} and {@link HeaderParam} does not conform with the * definitions described in the JAX-RS specification. If a value is not String or {@link Cookie} for * {@link CookieParam}, an instance of {@link ObjectMapper} is used to map the value to the desired type. *

*/ public class JaxrsParameterProvider implements RepositoryMethodParameterProvider { private final ObjectMapper objectMapper; private final ContainerRequestContext requestContext; private final RequestContextParameterProviderRegistry parameterProviderRegistry; public JaxrsParameterProvider(ObjectMapper objectMapper, ContainerRequestContext requestContext, RequestContextParameterProviderRegistry parameterProviderRegistry) { this.objectMapper = objectMapper; this.requestContext = requestContext; this.parameterProviderRegistry = parameterProviderRegistry; } @Override public T provide(Method method, int parameterIndex) { Parameter parameter = new Parameter(method, parameterIndex); Optional provider = parameterProviderRegistry.findProviderFor(parameter); return provider.isPresent() ? (T) provider.get().provideValue(parameter, requestContext, objectMapper) : null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy