javax.ws.rs.core.Configuration类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(433)

本文整理了Java中javax.ws.rs.core.Configuration类的一些代码示例,展示了Configuration类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration类的具体详情如下:
包路径:javax.ws.rs.core.Configuration
类名称:Configuration

Configuration介绍

[英]A configuration state associated with a Configurable JAX-RS context. Defines the components as well as additional meta-data for the configured context.

A configuration state may be used to retrieve configuration information about of the associated JAX-RS context (e.g. application, resource method, etc.) or component (e.g. javax.ws.rs.client.Client, javax.ws.rs.client.WebTarget, etc.). Configuration information consists of properties, registered JAX-RS component classes and/or instances.

This interface can be injected using the Context annotation.
[中]与可配置JAX-RS上下文关联的配置状态。为配置的上下文定义组件以及其他元数据。
配置状态可用于检索相关JAX-RS上下文(例如应用程序、资源方法等)或组件(例如javax.ws.RS.client.client、javax.ws.RS.client.WebTarget等)的配置信息。配置信息包括属性、注册的JAX-RS组件类和/或实例。
可以使用上下文注释注入此接口。

代码示例

代码示例来源:origin: jersey/jersey

@Override
  public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();

    // Validation disabled?
    if (PropertiesHelper.isProperty(config.getProperty(ServerProperties.BV_FEATURE_DISABLE))) {
      return false;
    }

    context.register(new ValidationBinder());

    // Set ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR to make sure no sendError is called on servlet container
    // when ServerProperties.BV_SEND_ERROR_IN_RESPONSE is enabled.
    if (PropertiesHelper.isProperty(config.getProperty(ServerProperties.BV_SEND_ERROR_IN_RESPONSE))
        && config.getProperty(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR) == null) {
      context.property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, true);
    }

    return true;
  }
}

代码示例来源:origin: alibaba/fastjson

@Override
public boolean configure(final FeatureContext context) {
  try {
    final Configuration config = context.getConfiguration();
    final String jsonFeature = CommonProperties.getValue(
        config.getProperties()
        , config.getRuntimeType()
        , InternalProperties.JSON_FEATURE, JSON_FEATURE,
        String.class
    context.property(
        PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType())
        , JSON_FEATURE);
    if (!config.isRegistered(FastJsonProvider.class)) {
      context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);

代码示例来源:origin: jersey/jersey

private void copyProviders(Configuration source, Configurable<?> target) {
  final Configuration targetConfig = target.getConfiguration();
  for (Class<?> c : source.getClasses()) {
    if (!targetConfig.isRegistered(c)) {
      target.register(c, source.getContracts(c));
    }
  }
  for (Object o : source.getInstances()) {
    Class<?> c = o.getClass();
    if (!targetConfig.isRegistered(o)) {
      target.register(c, source.getContracts(c));
    }
  }
}

代码示例来源:origin: jersey/jersey

@Override
  public void configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();

    // UriConnegFilter.
    final Object languageMappings = config.getProperty(ServerProperties.LANGUAGE_MAPPINGS);
    final Object mediaTypesMappings = config.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS);

    if (!config.isRegistered(UriConnegFilter.class)
        && (languageMappings != null || mediaTypesMappings != null)) {
      context.register(UriConnegFilter.class);
    }
  }
}

代码示例来源:origin: jersey/jersey

@Override
  public void configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    if (context.getConfiguration().isRegistered(SseFeature.class)) {
      return;
    }

    if (!PropertiesHelper.getValue(
        config.getProperties(), config.getRuntimeType(), SseFeature.DISABLE_SSE, Boolean.FALSE, Boolean.class, null)) {
      context.register(SseFeature.class);
    }
  }
}

代码示例来源:origin: alibaba/fastjson

@Override
  public void configure(final FeatureContext context) {

    final Configuration config = context.getConfiguration();

    // Register FastJson.
    if (!config.isRegistered(FastJsonFeature.class) && autoDiscover) {

      context.register(FastJsonFeature.class);
    }
  }
}

代码示例来源:origin: jersey/jersey

@Override
  public boolean configure(final FeatureContext context) {
    final RuntimeType runtime = context.getConfiguration().getRuntimeType();

    if (RuntimeType.SERVER.equals(runtime)) {
      context.register(FormDataParamInjectionFeature.class);
      context.register(MultiPartReaderServerSide.class);
    } else {
      context.register(MultiPartReaderClientSide.class);
    }

    context.register(MultiPartWriter.class);

    return true;
  }
}

代码示例来源:origin: com.oracle.ozark/ozark

@Override
public void configure(FeatureContext context) {
  final Configuration config = context.getConfiguration();
  if (config.isRegistered(ViewResponseFilter.class)) {
    return;     // already registered!
  }
  final boolean enableOzark = config.getClasses().stream().anyMatch(this::isController)
      || config.getInstances().stream().map(o -> o.getClass()).anyMatch(this::isController);
  if (enableOzark) {
    context.register(ViewResponseFilter.class);
    context.register(ViewableWriter.class);
  }
}

代码示例来源:origin: jersey/jersey

@Override
  public Boolean get() {
    return PropertiesHelper.isProperty(config.getProperty(MessageProperties.JAXB_PROCESS_XML_ROOT_ELEMENT));
  }
});

代码示例来源:origin: jersey/jersey

this.disableMetaProviderConfiguration = !commonConfig.enabledFeatureClasses.isEmpty();
} else {
  setProperties(config.getProperties());
  resetRegistrations();
  for (final Class<?> clazz : config.getClasses()) {
    if (Feature.class.isAssignableFrom(clazz) && config.isEnabled((Class<? extends Feature>) clazz)) {
      this.disableMetaProviderConfiguration = true;
    register(clazz, config.getContracts(clazz));
  for (final Object instance : config.getInstances()) {
    if (instance instanceof Feature && config.isEnabled((Feature) instance)) {
      this.disableMetaProviderConfiguration = true;
    register(instance, config.getContracts(instance.getClass()));

代码示例来源:origin: jersey/jersey

private LoggingInterceptor createLoggingFilter(FeatureContext context, RuntimeType runtimeType) {
  Map properties = context.getConfiguration().getProperties();
  String filterLoggerName = CommonProperties.getValue(
      properties,
      runtimeType == RuntimeType.SERVER ? LOGGING_FEATURE_LOGGER_NAME_SERVER : LOGGING_FEATURE_LOGGER_NAME_CLIENT,
      CommonProperties.getValue(
          properties,
          LOGGING_FEATURE_LOGGER_NAME,
          DEFAULT_LOGGER_NAME
      ));
  String filterLevel = CommonProperties.getValue(
      properties,
      runtimeType == RuntimeType.SERVER ? LOGGING_FEATURE_LOGGER_LEVEL_SERVER : LOGGING_FEATURE_LOGGER_LEVEL_CLIENT,
      CommonProperties.getValue(
          context.getConfiguration().getProperties(),
          LOGGING_FEATURE_LOGGER_LEVEL,
          DEFAULT_LOGGER_LEVEL));

代码示例来源:origin: jersey/jersey

@Override
public ResourceModel processResourceModel(final ResourceModel resourceModel, final Configuration configuration) {
  final boolean disabled = PropertiesHelper.isProperty(configuration.getProperty(ServerProperties.WADL_FEATURE_DISABLE));
  if (disabled) {
    return resourceModel;
  }
  final ResourceModel.Builder builder = ModelProcessorUtil.enhanceResourceModel(resourceModel, false, methodList, true);
  // Do not add WadlResource if already present in the classes (i.e. added during scanning).
  if (!configuration.getClasses().contains(WadlResource.class)) {
    final Resource wadlResource = Resource.builder(WadlResource.class).build();
    builder.addResource(wadlResource);
  }
  return builder.build();
}

代码示例来源:origin: jersey/jersey

@PostConstruct
private void init() {
  final String paramName = (String) configuration.getProperty(SelectableEntityFilteringFeature.QUERY_PARAM_NAME);
  SELECTABLE_PARAM_NAME = paramName != null ? paramName : SELECTABLE_PARAM_NAME;
}

代码示例来源:origin: jersey/jersey

private int getMaximumCacheLimit(Configuration configuration) {
  int limit = ClientProperties.getValue(configuration.getProperties(),
      ClientProperties.DIGESTAUTH_URI_CACHE_SIZELIMIT, MAXIMUM_DIGEST_CACHE_SIZE);
  if (limit < 1) {
    limit = MAXIMUM_DIGEST_CACHE_SIZE;
  }
  return limit;
}

代码示例来源:origin: jersey/jersey

/**
 * Enable a buffering of serialized entity. The buffering will be configured from configuration. The property
 * determining the size of the buffer is {@link CommonProperties#OUTBOUND_CONTENT_LENGTH_BUFFER}.
 * </p>
 * The buffering functionality is by default disabled and could be enabled by calling this method. In this case
 * this method must be called before first bytes are written to the {@link #getEntityStream() entity stream}.
 *
 * @param configuration runtime configuration.
 */
public void enableBuffering(Configuration configuration) {
  final Integer bufferSize = CommonProperties.getValue(configuration.getProperties(),
      configuration.getRuntimeType(), CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, Integer.class);
  if (bufferSize != null) {
    committingOutputStream.enableBuffering(bufferSize);
  } else {
    committingOutputStream.enableBuffering();
  }
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

private void copyProviders(Configuration source, Configurable<?> target) {
  for (Class<?> c : source.getClasses()) {
    target.register(c, source.getContracts(c));
  }
  for (Object o : source.getInstances()) {
    Class<?> c = o.getClass();
    target.register(c, source.getContracts(c));
  }
}

代码示例来源:origin: apache/cxf

private Set<Object> processProviders() {
    Set<Object> providers = new LinkedHashSet<>();
    for (Object provider : configuration.getInstances()) {
      Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider);
      if (provider instanceof ClientRequestFilter || provider instanceof ClientResponseFilter) {
        FilterProviderInfo<Object> filter = new FilterProviderInfo<>(providerCls, providerCls,
            provider, getBus(), configuration.getContracts(providerCls));
        providers.add(filter);
      } else {
        providers.add(provider);
      }
    }
    return providers;
  }
}

代码示例来源:origin: resteasy/Resteasy

@Override
public Set<Object> getInstances()
{
 return delegate.getInstances();
}

代码示例来源:origin: resteasy/Resteasy

@Override
public Map<Class<?>, Integer> getContracts(Class<?> componentClass)
{
 Map<Class<?>, Integer> contracts = new HashMap<>();
 contracts.putAll(getLocalContracts(componentClass));
 contracts.putAll(delegate.getContracts(componentClass));
 return contracts;
}

代码示例来源:origin: resteasy/Resteasy

@Override
public Set<Class<?>> getClasses()
{
 return delegate.getClasses();
}

相关文章