javax.ws.rs.core.Configuration.getRuntimeType()方法的使用及代码示例

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

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

Configuration.getRuntimeType介绍

[英]Get the runtime type of this configuration context.
[中]获取此配置上下文的运行时类型。

代码示例

代码示例来源: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: jersey/jersey

@Override
public boolean configure(FeatureContext context) {
  boolean enabled = false;
  if (context.getConfiguration().getRuntimeType() == RuntimeType.CLIENT) {
    ClientLoggingFilter clientLoggingFilter = (ClientLoggingFilter) createLoggingFilter(context, RuntimeType.CLIENT);
    context.register(clientLoggingFilter);
    enabled = true;
  }
  if (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER) {
    ServerLoggingFilter serverClientFilter = (ServerLoggingFilter) createLoggingFilter(context, RuntimeType.SERVER);
    context.register(serverClientFilter);
    enabled = true;
  }
  return enabled;
}

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

@Override
  public void configure(final FeatureContext context) {
    context.register(new JaxbMessagingBinder());

    if (RuntimeType.SERVER == context.getConfiguration().getRuntimeType()) {
      context.register(new JaxbParamConverterBinder());
    }
  }
}

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

@Override
public boolean configure(FeatureContext context) {
  boolean enabled = false;
  if (context.getConfiguration().getRuntimeType() == RuntimeType.CLIENT) {
    ClientLoggingFilter clientLoggingFilter = (ClientLoggingFilter) createLoggingFilter(context, RuntimeType.CLIENT);
    context.register(clientLoggingFilter);
    enabled = true;
  }
  if (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER) {
    ServerLoggingFilter serverClientFilter = (ServerLoggingFilter) createLoggingFilter(context, RuntimeType.SERVER);
    context.register(serverClientFilter);
    enabled = true;
  }
  return enabled;
}

代码示例来源:origin: oracle/helidon

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

    //register client
    if (runtimeType == RuntimeType.CLIENT) {
      context.register(new ClientSecurityFilter());
    } else {
      throw new IllegalStateException(
          "ClientSecurityFeature is only available for client side Jersey. For servers, please use SecurityFeature");
    }

    return true;
  }
}

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

@Override
public boolean configure(FeatureContext context) {
  if (!GlobalTracer.isRegistered()) {
    LOGGER.warning(LocalizationMessages.OPENTRACING_TRACER_NOT_REGISTERED());
  }
  switch (context.getConfiguration().getRuntimeType()) {
    case CLIENT:
      context.register(OpenTracingClientRequestFilter.class).register(OpenTracingClientResponseFilter.class);
      break;
    case SERVER:
      context.register(new OpenTracingApplicationEventListener(verbosity));
  }
  return true;
}

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

, config.getRuntimeType()
, InternalProperties.JSON_FEATURE, JSON_FEATURE,
String.class
PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType())
, JSON_FEATURE);

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

@Override
public boolean configure(final FeatureContext context) {
  if (context.getConfiguration().isEnabled(this.getClass())) {
    return false;
  }
  switch (context.getConfiguration().getRuntimeType()) {
    case CLIENT:
      context.register(EventInputReader.class);
      context.register(InboundEventReader.class);
      break;
    case SERVER:
      context.register(OutboundEventWriter.class);
      context.register(new SseBinder());
      context.register(SseEventSinkValueParamProvider.class, ValueParamProvider.class);
      break;
  }
  return true;
}

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

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

    final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
        InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
      return false;
    }

    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()),
        JSON_FEATURE);

    // add the default Jackson exception mappers
    context.register(JsonParseExceptionMapper.class);
    context.register(JsonMappingExceptionMapper.class);
    context.register(JacksonJaxbJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
    return true;
  }
}

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

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

    final String jsonFeature = CommonProperties.getValue(
        config.getProperties(),
        config.getRuntimeType(),
        InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);

    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
      return false;
    }

    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(
        InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);

    context.register(JsonBindingProvider.class);

    return true;
  }
}

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

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

    final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
        InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
      return false;
    }

    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()),
        JSON_FEATURE);

    for (final Class<?> provider : PROVIDERS) {
      context.register(provider, MessageBodyReader.class, MessageBodyWriter.class);
    }

    return true;
  }
}

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

@Override
  public boolean configure(final FeatureContext context) {
    if (CommonProperties.getValue(context.getConfiguration().getProperties(), context.getConfiguration().getRuntimeType(),
        CommonProperties.JSON_PROCESSING_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) {
      return false;
    }

    // Make sure JSON-P workers have higher priority than other Json providers (in case there is a need to use JSON-P and some
    // other provider in an application).
    context.register(JsonValueBodyReader.class, Priorities.USER + 1000);
    context.register(JsonValueBodyWriter.class, Priorities.USER + 1000);

    return true;
  }
}

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

@Override
  public void configure(final FeatureContext context) {
    final Map<String, Object> properties = context.getConfiguration().getProperties();
    final RuntimeType runtimeType = context.getConfiguration().getRuntimeType();

    context.register(new AbstractBinder() {
      @Override
      protected void configure() {
        // Message Body providers.
        install(new ServiceFinderBinder<MessageBodyReader>(MessageBodyReader.class, properties, runtimeType));
        install(new ServiceFinderBinder<MessageBodyWriter>(MessageBodyWriter.class, properties, runtimeType));
        // Exception Mappers.
        install(new ServiceFinderBinder<ExceptionMapper>(ExceptionMapper.class, properties, runtimeType));
      }
    });
  }
}

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

@Override
public boolean configure(final FeatureContext context) {
  final Configuration config = context.getConfiguration();
  if (!config.isRegistered(EntityFilteringProcessor.class)) {
    // Binder (FilteringObjectProvider/FilteringGraphTransformer).
    if (!config.isRegistered(EntityFilteringBinder.class)) {
      context.register(new EntityFilteringBinder());
    }
    // Entity Processors.
    context.register(EntityFilteringProcessor.class);
    if (!config.isRegistered(DefaultEntityProcessor.class)) {
      context.register(DefaultEntityProcessor.class);
    }
    // Scope Providers.
    context.register(EntityFilteringScopeResolver.class);
    // Scope Resolver.
    if (RuntimeType.SERVER == config.getRuntimeType()) {
      context.register(ServerScopeProvider.class);
    } else {
      context.register(CommonScopeProvider.class);
    }
    return true;
  }
  return false;
}

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

final Configuration config = context.getConfiguration();
if (CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
    CommonProperties.MOXY_JSON_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) {
  return false;
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);

代码示例来源: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: jersey/jersey

@Override
public void configure(FeatureContext context) {
  if (!context.getConfiguration().isRegistered(LoggingFeature.class)) {
    Map properties = context.getConfiguration().getProperties();
    if (commonPropertyConfigured(properties)
        || (context.getConfiguration().getRuntimeType() == RuntimeType.CLIENT && clientConfigured(properties))
        || (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER && serverConfigured(properties))) {
      context.register(LoggingFeature.class);
    }
  }
}

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

@Override
public void configure(FeatureContext context) {
  if (!context.getConfiguration().isRegistered(LoggingFeature.class)) {
    Map properties = context.getConfiguration().getProperties();
    if (commonPropertyConfigured(properties)
        || (context.getConfiguration().getRuntimeType() == RuntimeType.CLIENT && clientConfigured(properties))
        || (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER && serverConfigured(properties))) {
      context.register(LoggingFeature.class);
    }
  }
}

代码示例来源: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: 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();
  }
}

相关文章