org.glassfish.jersey.server.model.Parameter Java Examples
The following examples show how to use
org.glassfish.jersey.server.model.Parameter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FernetTokenValueParamProvider.java From fernet-java8 with Apache License 2.0 | 6 votes |
public Function<ContainerRequest, Token> getValueProvider(final Parameter parameter) { return request -> { if (parameter.getRawType().equals(Token.class) && parameter.isAnnotationPresent(FernetToken.class)) { final Token xAuthorizationToken = getTokenHeaderUtility().getXAuthorizationToken(request); if (xAuthorizationToken != null) { return xAuthorizationToken; } final Token authorizationToken = getTokenHeaderUtility().getAuthorizationToken(request); if (authorizationToken != null) { return authorizationToken; } throw new NotAuthorizedException("Bearer error=\"invalid_token\", error_description=\"no token found in Authorization or X-Authorization header\""); } throw new IllegalStateException("misconfigured annotation"); }; }
Example #2
Source File: FernetSecretValueParamProvider.java From fernet-java8 with Apache License 2.0 | 6 votes |
public Function<ContainerRequest, T> getValueProvider(final Parameter parameter) { return request -> { if (parameter.isAnnotationPresent(FernetSecret.class)) { final Collection<? extends Key> keys = getKeySupplier().get(); final Token xAuthorizationToken = getHeaderUtility().getXAuthorizationToken(request); if (xAuthorizationToken != null) { return getValidator().validateAndDecrypt(keys, xAuthorizationToken); } final Token authorizationToken = getHeaderUtility().getAuthorizationToken(request); if (authorizationToken != null) { return getValidator().validateAndDecrypt(keys, authorizationToken); } throw new NotAuthorizedException("Bearer error=\"invalid_token\", error_description=\"no token found in Authorization or X-Authorization header\""); } throw new IllegalStateException("misconfigured annotation"); }; }
Example #3
Source File: SearchFactoryProvider.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Factory<?> createValueFactory(Parameter parameter) { Class<?> paramType = parameter.getRawType(); SearchParam annotation = parameter.getAnnotation(SearchParam.class); if (annotation != null && paramType.isAssignableFrom(SearchModel.class)) { return new SearchFactory(); } return null; }
Example #4
Source File: SecurityCheckFactoryProvider.java From commafeed with Apache License 2.0 | 5 votes |
@Override protected Factory<?> createValueFactory(final Parameter parameter) { final Class<?> classType = parameter.getRawType(); SecurityCheck securityCheck = parameter.getAnnotation(SecurityCheck.class); if (securityCheck == null) return null; if (classType.isAssignableFrom(User.class)) { return new SecurityCheckFactory(securityCheck.value(), securityCheck.apiKeyAllowed()); } else { return null; } }
Example #5
Source File: SearchFactoryProviderTest.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
private Parameter getParameter(String methodName, Class clazz) throws NoSuchMethodException { return Parameter.create( clazz, SampleResource.class, SampleResource.class.getDeclaredMethod(methodName, clazz), true ).get(0); }
Example #6
Source File: SearchFactoryProviderTest.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void createValueFactory() throws Exception { Parameter parameter = getParameter("test1", SearchModel.class); SearchFactoryProvider provider = Mockito.mock(SearchFactoryProvider.class); Mockito.when(provider.createValueFactory(parameter)).thenCallRealMethod(); SearchFactory factory = (SearchFactory) provider.createValueFactory(parameter); assertNotNull(factory); }
Example #7
Source File: SearchFactoryProviderTest.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void createValueFactoryWithoutAnnotation() throws Exception { Parameter parameter = getParameter("test2", SearchModel.class); SearchFactoryProvider provider = Mockito.mock(SearchFactoryProvider.class); Mockito.when(provider.createValueFactory(parameter)).thenCallRealMethod(); SearchFactory factory = (SearchFactory) provider.createValueFactory(parameter); assertNull(factory); }
Example #8
Source File: SearchFactoryProviderTest.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void createValueFactoryWrongType() throws Exception { Parameter parameter = getParameter("test3", String.class); SearchFactoryProvider provider = Mockito.mock(SearchFactoryProvider.class); Mockito.when(provider.createValueFactory(parameter)).thenCallRealMethod(); SearchFactory factory = (SearchFactory) provider.createValueFactory(parameter); assertNull(factory); }
Example #9
Source File: TokenFactoryProvider.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
@Inject public TokenFactoryProvider( final MultivaluedParameterExtractorProvider extractorProvider, ServiceLocator locator) { super(extractorProvider, locator, Parameter.Source.UNKNOWN); }
Example #10
Source File: TokenFactoryProvider.java From robe with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Factory<?> createValueFactory(Parameter parameter) { Class<?> paramType = parameter.getRawType(); RobeAuth annotation = parameter.getAnnotation(RobeAuth.class); if (annotation != null && paramType.isAssignableFrom(BasicToken.class)) { return new TokenFactory<>(annotation.required()); } return null; }
Example #11
Source File: TypeFactory.java From shiro-jersey with Apache License 2.0 | 5 votes |
@Override public Factory<?> getValueFactory(Parameter parameter) { if (type.equals(parameter.getRawType()) && parameter.isAnnotationPresent(Auth.class)) { return this; } return null; }
Example #12
Source File: PrincipalValueFactoryProvider.java From jersey-hmac-auth with Apache License 2.0 | 5 votes |
protected Factory<? extends P> createValueFactory(final Parameter parameter) { final HmacAuth auth = parameter.getAnnotation(HmacAuth.class); if (auth != null) { // TODO introduce type checking return getFactory(); } return null; }
Example #13
Source File: DSLContextValueParamProvider.java From droptools with Apache License 2.0 | 5 votes |
@Override public Function<ContainerRequest, ?> getValueProvider(Parameter parameter) { final Class<?> classType = parameter.getRawType(); final JooqInject jooqInjectParam = parameter.getAnnotation(JooqInject.class); return (classType == null || !classType.equals(DSLContext.class) || jooqInjectParam == null) ? null // return null when parameter not supported : (req) -> DSL.using(getConfiguration(jooqInjectParam.value())); }
Example #14
Source File: TypeFactory.java From shiro-jersey with Apache License 2.0 | 5 votes |
@Override public Factory<?> getValueFactory(Parameter parameter) { if (type.equals(parameter.getRawType()) && parameter.isAnnotationPresent(Auth.class)) { return this; } return null; }
Example #15
Source File: SingularityAuthFactoryProvider.java From Singularity with Apache License 2.0 | 5 votes |
@Override protected Factory<?> createValueFactory(Parameter parameter) { Class<?> paramType = parameter.getRawType(); Auth annotation = parameter.getAnnotation(Auth.class); if (annotation != null && paramType.isAssignableFrom(SingularityUser.class)) { return authFactory; } return null; }
Example #16
Source File: DummyAuth.java From dropwizard-experiment with MIT License | 5 votes |
@Override protected Factory<?> createValueFactory(Parameter parameter) { if (!parameter.isAnnotationPresent(Auth.class)) { return null; } return new AbstractContainerRequestValueFactory<Principal>() { public Principal provide() { return user; } }; }
Example #17
Source File: SessionHelperFactoryProvider.java From commafeed with Apache License 2.0 | 5 votes |
@Override protected Factory<?> createValueFactory(final Parameter parameter) { final Class<?> classType = parameter.getRawType(); Context context = parameter.getAnnotation(Context.class); if (context == null) return null; if (classType.isAssignableFrom(SessionHelper.class)) { return new SessionHelperFactory(); } else { return null; } }
Example #18
Source File: JerseyRouteExecutionStrategyUtils.java From servicetalk with Apache License 2.0 | 5 votes |
private static HttpExecutionStrategy computeDefaultExecutionStrategy(final Invocable invocable) { final Parameter entityParam = invocable.getParameters().stream().filter(p -> p.getSource() == ENTITY) .findFirst() .orElse(null); final boolean consumesStreaming = entityParam != null && Publisher.class.isAssignableFrom(entityParam.getRawType()); final boolean consumesAsync = consumesStreaming || (entityParam != null && Single.class.isAssignableFrom(entityParam.getRawType())); final boolean producesStreaming = Publisher.class.isAssignableFrom(invocable.getRawResponseType()); final boolean producesAsync = producesStreaming || Single.class.isAssignableFrom(invocable.getRawResponseType()) || Completable.class.isAssignableFrom(invocable.getRawResponseType()); if (!consumesAsync && !producesAsync) { // blocking-aggregated // HttpApiConversions/BlockingToStreamingService uses OFFLOAD_RECEIVE_DATA_STRATEGY because we are invoking // the service within a callback of Single<HttpRequest>, which may call the service on the eventloop. // Here we are not invoking the service as part of collecting the request payload, // so OFFLOAD_RECEIVE_META is sufficient. return OFFLOAD_RECEIVE_META; } else if (consumesAsync && !consumesStreaming && producesAsync && !producesStreaming) { // async-aggregated return OFFLOAD_RECEIVE_META_AND_SEND; } else { // default to async-streaming, as it has the most aggressive offloading strategy return OFFLOAD_ALL; } }
Example #19
Source File: Pac4JValueFactoryProvider.java From jax-rs-pac4j with Apache License 2.0 | 5 votes |
@Inject protected Pac4JProfileValueFactoryProvider( ProfileManagerFactoryBuilder manager, OptionalProfileFactoryBuilder opt, ProfileFactoryBuilder profile, Provider<MultivaluedParameterExtractorProvider> mpep ) { super(mpep, Parameter.Source.UNKNOWN); this.manager = manager; this.optProfile = opt; this.profile = profile; }
Example #20
Source File: RateLimitBundle.java From ratelimitj with Apache License 2.0 | 5 votes |
@Inject public RateLimitingFactoryProvider(final MultivaluedParameterExtractorProvider extractorProvider, final ServiceLocator injector, final RateLimiterFactoryProvider rateLimiterFactoryProvider) { super(extractorProvider, injector, Parameter.Source.UNKNOWN); this.requestRateLimiterFactory = rateLimiterFactoryProvider.factory; }
Example #21
Source File: RateLimitBundle.java From ratelimitj with Apache License 2.0 | 5 votes |
@Override protected Factory<RequestRateLimiterFactory> createValueFactory(final Parameter parameter) { final RateLimiting annotation = parameter.getAnnotation(RateLimiting.class); if (null == annotation) { return null; } else { return new AbstractContainerRequestValueFactory<RequestRateLimiterFactory>() { @Override public RequestRateLimiterFactory provide() { return requestRateLimiterFactory; } }; } }
Example #22
Source File: RateLimit429EnforcerFilterTest.java From ratelimitj with Apache License 2.0 | 5 votes |
@Override protected Factory<?> createValueFactory(final Parameter parameter) { final RateLimiting annotation = parameter.getAnnotation(RateLimiting.class); if (null == annotation) { return null; } else { return new AbstractContainerRequestValueFactory<RequestRateLimiterFactory>() { @Override public RequestRateLimiterFactory provide() { return requestRateLimiterFactory; } }; } }
Example #23
Source File: Pac4JValueFactoryProvider.java From jax-rs-pac4j with Apache License 2.0 | 5 votes |
@Inject protected Pac4JProfileValueFactoryProvider(ProfileManagerFactoryBuilder manager, OptionalProfileFactoryBuilder opt, ProfileFactoryBuilder profile, MultivaluedParameterExtractorProvider mpep, ServiceLocator locator) { super(mpep, locator, Parameter.Source.UNKNOWN); this.manager = manager; this.optProfile = opt; this.profile = profile; }
Example #24
Source File: Pac4JValueFactoryProvider.java From jax-rs-pac4j with Apache License 2.0 | 5 votes |
@Override protected Factory<?> createValueFactory(Parameter parameter) { if (parameter.isAnnotationPresent(Pac4JProfileManager.class)) { if (ProfileManager.class.isAssignableFrom(parameter.getRawType())) { return manager.get(); } throw new IllegalStateException("Cannot inject a Pac4J profile manager into a parameter of type " + parameter.getRawType().getName()); } if (parameter.isAnnotationPresent(Pac4JProfile.class)) { if (CommonProfile.class.isAssignableFrom(parameter.getRawType())) { return profile.get(); } if (Optional.class.isAssignableFrom(parameter.getRawType())) { List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(parameter.getRawType()); ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null; if (ctp == null || CommonProfile.class.isAssignableFrom(ctp.rawClass())) { return optProfile.get(); } } throw new IllegalStateException( "Cannot inject a Pac4J profile into a parameter of type " + parameter.getRawType().getName()); } return null; }
Example #25
Source File: Pac4JValueFactoryProvider.java From jax-rs-pac4j with Apache License 2.0 | 5 votes |
@Override protected Function<ContainerRequest, ?> createValueProvider(Parameter parameter) { if (parameter.isAnnotationPresent(Pac4JProfileManager.class)) { if (ProfileManager.class.isAssignableFrom(parameter.getRawType())) { return manager.get(); } throw new IllegalStateException("Cannot inject a Pac4J profile manager into a parameter of type " + parameter.getRawType().getName()); } if (parameter.isAnnotationPresent(Pac4JProfile.class)) { if (CommonProfile.class.isAssignableFrom(parameter.getRawType())) { return profile.get(); } if (Optional.class.isAssignableFrom(parameter.getRawType())) { List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(parameter.getRawType()); ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null; if (ctp == null || CommonProfile.class.isAssignableFrom(ctp.rawClass())) { return optProfile.get(); } } throw new IllegalStateException( "Cannot inject a Pac4J profile into a parameter of type " + parameter.getRawType().getName()); } return null; }
Example #26
Source File: Pac4JValueFactoryProvider.java From jax-rs-pac4j with Apache License 2.0 | 5 votes |
@Inject protected Pac4JProfileValueFactoryProvider( ProfileManagerFactoryBuilder manager, OptionalProfileFactoryBuilder opt, ProfileFactoryBuilder profile, Provider<MultivaluedParameterExtractorProvider> mpep ) { super(mpep, org.glassfish.jersey.model.Parameter.Source.UNKNOWN); this.manager = manager; this.optProfile = opt; this.profile = profile; }
Example #27
Source File: Pac4JValueFactoryProvider.java From jax-rs-pac4j with Apache License 2.0 | 5 votes |
@Override protected Function<ContainerRequest, ?> createValueProvider(Parameter parameter) { if (parameter.isAnnotationPresent(Pac4JProfileManager.class)) { if (ProfileManager.class.isAssignableFrom(parameter.getRawType())) { return manager.get(); } throw new IllegalStateException("Cannot inject a Pac4J profile manager into a parameter of type " + parameter.getRawType().getName()); } if (parameter.isAnnotationPresent(Pac4JProfile.class)) { if (CommonProfile.class.isAssignableFrom(parameter.getRawType())) { return profile.get(); } if (Optional.class.isAssignableFrom(parameter.getRawType())) { List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(parameter.getRawType()); ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null; if (ctp == null || CommonProfile.class.isAssignableFrom(ctp.rawClass())) { return optProfile.get(); } } throw new IllegalStateException( "Cannot inject a Pac4J profile into a parameter of type " + parameter.getRawType().getName()); } return null; }
Example #28
Source File: AuthResolver.java From keywhiz with Apache License 2.0 | 5 votes |
@Inject public AuthValueFactoryProvider(final MultivaluedParameterExtractorProvider extractorProvider, final ServiceLocator injector, ClientAuthFactory clientAuthFactory, AutomationClientAuthFactory automationClientAuthFactory, UserAuthFactory userAuthFactory) { super(extractorProvider, injector, Parameter.Source.UNKNOWN); this.clientAuthFactory = clientAuthFactory; this.automationClientAuthFactory = automationClientAuthFactory; this.userAuthFactory = userAuthFactory; }
Example #29
Source File: AuthResolver.java From keywhiz with Apache License 2.0 | 5 votes |
@Override protected Factory<?> createValueFactory(final Parameter parameter) { final Class<?> classType = parameter.getRawType(); final Auth auth = parameter.getAnnotation(Auth.class); if (auth == null) { return null; } if (classType.equals(Client.class)) { return new AbstractContainerRequestValueFactory<Client>() { @Override public Client provide() { return clientAuthFactory.provide(getContainerRequest()); } }; } if (classType.equals(AutomationClient.class)) { return new AbstractContainerRequestValueFactory<AutomationClient>() { @Override public AutomationClient provide() { return automationClientAuthFactory.provide(getContainerRequest()); } }; } if (classType.equals(User.class)) { return new AbstractContainerRequestValueFactory<User>() { @Override public User provide() { return userAuthFactory.provide(getContainerRequest()); } }; } return null; }
Example #30
Source File: AuthValueFactoryProvider.java From dropwizard-simpleauth with Apache License 2.0 | 5 votes |
@Override public AbstractContainerRequestValueFactory<?> createValueFactory(final Parameter parameter) { if (parameter.getAnnotation(Auth.class) == null) { return null; } if (parameter.getRawType() == Optional.class) { return new OptionalContainerRequestValueFactory(parameter); } else { return new StandardContainerReqeustValueFactory(parameter); } }