Java 类org.glassfish.jersey.server.model.Parameter 实例源码

项目:jersey-properties    文件:PropertiesValueFactoryProvider.java   
@Override
protected Factory<?> createValueFactory(Parameter parameter) {

    if (!parameter.isAnnotationPresent(Prop.class)) {
        return null;
    }

    String parameterName = parameter.getSourceName();
    if (parameterName == null || parameterName.length() == 0) {
        // Invalid parameter name
        return null;
    }

    MultivaluedParameterExtractor e = get(parameter);
    if (e == null) {
        return null;
    }

    PropertyFactory factory = new PropertyFactory(e, parameter, i18nEnabled);
    serviceLocator.inject(factory);
    return factory;
}
项目:lightmare    文件:ParamBuilder.java   
/**
 * Converts {@link Parameter} to {@link InputStream} or {@link List} of
 * {@link InputStream} by {@link Parameter} nature
 * 
 * @param parameter
 * @return {@link Object}
 */
private Object getEntityStream(Parameter parameter) {

    Object stream;

    List<String> paramValues = uriParams.get(parameter.getSourceName());
    String value;
    if (CollectionUtils.valid(paramValues)) {
        if (paramValues.size() == PARAM_VALIES_LENGTH) {
            value = CollectionUtils.getFirst(paramValues);
            stream = RequestUtils.textToStream(value);
        } else {
            stream = RequestUtils.textsToStreams(paramValues);
        }
    } else {
        stream = null;
    }

    return stream;
}
项目:lightmare    文件:ParamBuilder.java   
/**
 * Reads from {@link InputStream} or {@link List} of {@link InputStream} in
 * case that parameters are multi valued
 * 
 * @param stream
 * @param parameter
 * @throws IOException
 */
private void fillParamList(Object stream, Parameter parameter) throws IOException {

    InputStream entityStream;

    if (stream instanceof InputStream) {
        entityStream = ObjectUtils.cast(stream, InputStream.class);
        readFromStream(entityStream, parameter);
    } else if (stream instanceof List) {
        List<InputStream> streamsList = ObjectUtils.cast(stream);
        Iterator<InputStream> streams = streamsList.iterator();
        while (streams.hasNext()) {
            entityStream = streams.next();
            readFromStream(entityStream, parameter);
        }
    }
}
项目:lightmare    文件:ParamBuilder.java   
/**
 * Extracts parameters from {@link ContainerRequestContext} instance
 * 
 * @return {@link List}<Object>
 * @throws IOException
 */
public List<Object> extractParams() throws IOException {

    paramsList = new ArrayList<Object>();

    check = check();
    httpHeaders = request.getHeaders();
    uriParams = extractParameters(request);
    Object stream;
    for (Parameter parameter : parameters) {
        reader = RequestUtils.getReader(workers, parameter, mediaType);
        stream = getEntityStream(request, parameter);
        if (ObjectUtils.notNull(stream)) {
            fillParamList(stream, parameter);
        } else {
            addNullParam(parameter);
        }
    }

    return paramsList;
}
项目:ratelimitj    文件:RateLimitBundle.java   
@Inject
public RateLimitingFactoryProvider(final MultivaluedParameterExtractorProvider extractorProvider,
                                   final ServiceLocator injector,
                                   final RateLimiterFactoryProvider rateLimiterFactoryProvider) {
    super(extractorProvider, injector, Parameter.Source.UNKNOWN);
    this.requestRateLimiterFactory = rateLimiterFactoryProvider.factory;
}
项目:ratelimitj    文件:RateLimitBundle.java   
@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>() {
            public RequestRateLimiterFactory provide() {
                return requestRateLimiterFactory;
            }
        };
    }
}
项目:ratelimitj    文件:RateLimit429EnforcerFilterTest.java   
@Override
protected Factory<?> createValueFactory(final Parameter parameter) {
    final RateLimiting annotation = parameter.getAnnotation(RateLimiting.class);
    if (null == annotation) {
        return null;
    } else {
        return new AbstractContainerRequestValueFactory<RequestRateLimiterFactory>() {
            public RequestRateLimiterFactory provide() {
                return requestRateLimiterFactory;
            }
        };
    }
}
项目:protox-webapp-archetype    文件:JsonParamValueFactoryProvider.java   
@Override
    protected Factory<?> createValueFactory(Parameter parameter) {

        LOGGER.debug("{}", parameter);
//        parameter.getSourceName()
        JsonParamValueFactory factory = new JsonParamValueFactory(parameter);
        getLocator().inject(factory);
        return factory;
    }
项目:jax-rs-pac4j    文件:Pac4JValueFactoryProvider.java   
@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;
}
项目:jax-rs-pac4j    文件:Pac4JValueFactoryProvider.java   
@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;
}
项目:JaxRs2Retrofit    文件:CustomAnnotationTest.java   
@Inject
protected CustomAnnotationProvider(
        MultivaluedParameterExtractorProvider mpep,
        ServiceLocator locator) {

    super(mpep, locator, Parameter.Source.UNKNOWN);
}
项目:JaxRs2Retrofit    文件:CustomAnnotationTest.java   
@Override
protected Factory<String> createValueFactory(Parameter parameter) {
    return new Factory<String>() {
        @Override
        public String provide() {
            return "hello world";
        }

        @Override
        public void dispose(String instance) {  }
    };
}
项目:keywhiz    文件:AuthResolver.java   
@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;
}
项目:keywhiz    文件:AuthResolver.java   
@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;
}
项目:dropwizard-jooq    文件:ConfigurationFactoryProvider.java   
@Inject
protected ConfigurationFactoryProvider(final MultivaluedParameterExtractorProvider extractorProvider,
        final ServiceLocator injector, final ConfigurationFactoryInfo configInfo) {
    super(extractorProvider, injector, Parameter.Source.UNKNOWN);
    this.configuration = configInfo.configuration;
    this.dataSource = configInfo.dataSource;
    this.multiTenantConnectionProvider = configInfo.multiTenantConnectionProvider;
}
项目:dropwizard-jooq    文件:ConfigurationFactoryProvider.java   
@Override
protected Factory<?> createValueFactory(Parameter parameter) {
    Class<?> classType = parameter.getRawType();

    if (classType == null || (!classType.equals(Configuration.class))) {
        return null;
    }

    return new ConfigurationFactory(configuration, dataSource, multiTenantConnectionProvider,
            parameter.getAnnotation(JooqConfiguration.class));
}
项目:graphql    文件:AuthContainerRequestFilter.java   
@Override
protected Factory<?> createValueFactory(Parameter parameter)
{

  Class<?> classType = parameter.getRawType();

  if (classType == null || (!classType.equals(UnverifiedCredentials.class)))
  {
    return null;
  }

  return new MyContextValueFactory();

}
项目:jersey-properties    文件:I18NConfigProperties.java   
@Override
Object getCachedPropery(Parameter parameter) {
    Locale locale = ThreadLocalLocale.get();
    Map<Locale, Object> props = cachedBundles.get(parameter);
    if (props == null) {
        props = new ConcurrentHashMap<Locale, Object>();
        cachedBundles.put(parameter, props);
        return null;
    } else {
        return props.get(locale);
    }
}
项目:jersey-properties    文件:I18NConfigProperties.java   
@Override
void putCachedProperty(Parameter key, Object value) {
    Map<Locale, Object> props = cachedBundles.get(key);
    if (props == null) {
        props = new ConcurrentHashMap<Locale, Object>();
    }
    Locale locale = ThreadLocalLocale.get();
    if (locale == null) {
        locale = defaultLocale;
    }
    props.put(locale, value);
    cachedBundles.put(key, props);
}
项目:jersey-properties    文件:PropertiesValueFactoryProvider.java   
@Inject
public PropertiesValueFactoryProvider(MultivaluedParameterExtractorProvider mpep,
        ServiceLocator locator,
        Configuration configuration) {
    super(mpep, locator, Parameter.Source.UNKNOWN);
    this.serviceLocator = locator;
    this.i18nEnabled = PropertiesHelper.getValue(configuration.getProperties(),
            RuntimeType.SERVER, JerseyPropertiesFeature.ENABLE_I18N, false, null);
}
项目:robe    文件:SearchFactoryProvider.java   
@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;
}
项目:robe    文件:SearchFactoryProviderTest.java   
private Parameter getParameter(String methodName, Class clazz) throws NoSuchMethodException {
    return Parameter.create(
            clazz,
            SampleResource.class,
            SampleResource.class.getDeclaredMethod(methodName, clazz),
            true
    ).get(0);
}
项目:robe    文件:SearchFactoryProviderTest.java   
@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);
}
项目:robe    文件:SearchFactoryProviderTest.java   
@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);
}
项目:robe    文件:SearchFactoryProviderTest.java   
@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);
}
项目:robe    文件:TokenFactoryProvider.java   
@Inject
public TokenFactoryProvider(
        final MultivaluedParameterExtractorProvider extractorProvider,
        ServiceLocator locator) {

    super(extractorProvider, locator, Parameter.Source.UNKNOWN);
}
项目:robe    文件:TokenFactoryProvider.java   
@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;
}
项目:shiro-jersey    文件:TypeFactory.java   
@Override
public Factory<?> getValueFactory(Parameter parameter) {
    if (type.equals(parameter.getRawType()) && parameter.isAnnotationPresent(Auth.class)) {
        return this;
    }
    return null;
}
项目:jersey-hmac-auth    文件:PrincipalValueFactoryProvider.java   
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;
}
项目:lens    文件:LensResourceMethod.java   
/**
 * Extract default value of a parameter from the parameter annotations of the handler method
 *
 * @param paramName value of {@link org.glassfish.jersey.media.multipart.FormDataParam} annotation on the handler
 *                  method. Which will be the name of the argument in the request parameters
 * @return value of {@link javax.ws.rs.DefaultValue} annotation on the handler method
 */
public String getDefaultValueForParam(final String paramName) {
  for (Parameter param : resourceMethod.getInvocable().getParameters()) {
    if (param.getSourceName().equals(paramName)) {
      return param.getDefaultValue();
    }
  }
  return null;
}
项目:droptools    文件:DSLContextValueFactoryProvider.java   
@Override
public Factory<?> getValueFactory(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
           : new DSLContextFactory(getConfiguration(configurationMap, jooqInjectParam.value())
           );
}
项目:shiro-jersey    文件:TypeFactory.java   
@Override
public Factory<?> getValueFactory(Parameter parameter) {
    if (type.equals(parameter.getRawType()) && parameter.isAnnotationPresent(Auth.class)) {
        return this;
    }
    return null;
}
项目:Singularity    文件:SingularityAuthFactoryProvider.java   
@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;
}
项目:dropwizard-experiment    文件:DummyAuth.java   
@Override
protected Factory<?> createValueFactory(Parameter parameter) {
    if (!parameter.isAnnotationPresent(Auth.class)) {
        return null;
    }

    return new AbstractContainerRequestValueFactory<Principal>() {
        public Principal provide() {
            return user;
        }
    };
}
项目:lightmare    文件:ResourceBuilder.java   
/**
    * Defines method for {@link Resource} to build
    * 
    * @param builder
    * @param method
    * @param metaData
    */
   private static void addMethod(Resource.Builder builder,
    ResourceMethod method, MetaData metaData) {

List<MediaType> consumedTypes = method.getConsumedTypes();
List<MediaType> producedTypes = method.getProducedTypes();
Invocable invocable = method.getInvocable();
Method realMethod = invocable.getHandlingMethod();
List<Parameter> parameters = invocable.getParameters();

// Defines media type
MediaType type;
if (CollectionUtils.valid(consumedTypes)) {
    type = CollectionUtils.getFirst(consumedTypes);
} else {
    type = null;
}
// REST Inflector to define bean methods
Inflector<ContainerRequestContext, Response> inflector = new RestInflector(
    realMethod, metaData, type, parameters);

// Builds new method for resource
ResourceMethod.Builder methodBuilder = builder.addMethod(method
    .getHttpMethod());
methodBuilder.consumes(consumedTypes);
methodBuilder.produces(producedTypes);
methodBuilder.nameBindings(method.getNameBindings());
methodBuilder.handledBy(inflector);
methodBuilder.build();
   }
项目:lightmare    文件:ResourceBuilder.java   
/**
 * Defines method for {@link Resource} to build
 * 
 * @param builder
 * @param method
 * @param metaData
 */
private static void addMethod(Resource.Builder builder, ResourceMethod method, MetaData metaData) {

    List<MediaType> consumedTypes = method.getConsumedTypes();
    List<MediaType> producedTypes = method.getProducedTypes();
    Invocable invocable = method.getInvocable();
    Method realMethod = invocable.getHandlingMethod();
    List<Parameter> parameters = invocable.getParameters();

    // Defines media type
    MediaType type;
    if (CollectionUtils.valid(consumedTypes)) {
        type = CollectionUtils.getFirst(consumedTypes);
    } else {
        type = null;
    }
    // Implementation of framework defined "Inflector" interface to define
    // bean
    // methods
    Inflector<ContainerRequestContext, Response> inflector = new RestInflector(realMethod, metaData, type,
            parameters);

    // Builds new method for resource
    ResourceMethod.Builder methodBuilder = builder.addMethod(method.getHttpMethod());
    methodBuilder.consumes(consumedTypes);
    methodBuilder.produces(producedTypes);
    methodBuilder.nameBindings(method.getNameBindings());
    methodBuilder.handledBy(inflector);
    methodBuilder.build();
}
项目:lightmare    文件:ParamBuilder.java   
public ParamBuilder(MediaType mediaType, List<Parameter> parameters, MessageBodyWorkers workers,
        ContainerRequestContext request) {
    this.mediaType = mediaType;
    this.parameters = parameters;
    this.workers = workers;
    this.request = request;
}
项目:lightmare    文件:ParamBuilder.java   
/**
 * Reads {@link InputStream} from passed {@link ContainerRequestContext} for
 * associated {@link Parameter} instance
 * 
 * @param request
 * @param parameter
 * @return {@link Object}
 */
private Object getEntityStream(ContainerRequestContext request, Parameter parameter) {

    Object entityStream;

    if (check) {
        entityStream = getEntityStream(parameter);
    } else {
        entityStream = request.getEntityStream();
    }

    return entityStream;
}
项目:lightmare    文件:ParamBuilder.java   
/**
 * Extracts parameter from passed {@link InputStream} (writes appropriate
 * value to {@link Object} instance)
 * 
 * @param parameter
 * @param entityStream
 * @return {@link Object}
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private Object extractParam(Parameter parameter, InputStream entityStream) throws IOException {

    Object param;

    try {
        param = reader.readFrom(ObjectUtils.cast(parameter.getRawType(), Class.class), parameter.getType(),
                parameter.getAnnotations(), mediaType, httpHeaders, entityStream);
    } finally {
        close(entityStream);
    }

    return param;
}
项目:lightmare    文件:ParamBuilder.java   
/**
 * Initializes and adds null parameter to {@link List} of parameters
 * 
 * @param parameter
 */
private void addNullParam(Parameter parameter) {

    Class<?> paramType = parameter.getRawType();
    Object nullParam;
    if (paramType.isPrimitive()) {
        nullParam = ClassUtils.getDefault(paramType);
    } else {
        nullParam = null;
    }

    paramsList.add(nullParam);
}