Java Code Examples for org.glassfish.jersey.CommonProperties#getValue()

The following examples show how to use org.glassfish.jersey.CommonProperties#getValue() . 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: DACJacksonJaxbJsonFeature.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {
  final Configuration config = context.getConfiguration();

  final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
    InternalProperties.JSON_FEATURE, JSON_FEATURE_CLASSNAME, String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE_CLASSNAME.equalsIgnoreCase(jsonFeature)) {
      LOGGER.error("Another JSON provider has been registered: {}", jsonFeature);
      return false;
    }

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

  context.register(DACJacksonJaxbJsonProvider.class);

  return true;
}
 
Example 2
Source File: ParsecMoxyFeature.java    From parsec-libraries with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {
    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);
    // 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);

    final int workerPriority = Priorities.USER + 3000;
    context.register(ParsecMoxyProvider.class, workerPriority);

    return true;
}
 
Example 3
Source File: FastJsonFeature.java    From fastjson-jaxrs-json-provider with Apache License 2.0 6 votes vote down vote up
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);
	// Register FastJson.
	if (!config.isRegistered(FastJsonProvider.class)) {
		context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
	}
	return true;
}
 
Example 4
Source File: FastJsonFeature.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@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
        );

        // 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);

        // Register FastJson.
        if (!config.isRegistered(FastJsonProvider.class)) {
            context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
        }
    } catch (NoSuchMethodError e) {
        // skip
    }

    return true;
}