org.glassfish.jersey.internal.util.PropertiesHelper Java Examples

The following examples show how to use org.glassfish.jersey.internal.util.PropertiesHelper. 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: JerseyApplication.java    From onedev with MIT License 6 votes vote down vote up
@Inject
public JerseyApplication(ServiceLocator serviceLocator) {
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
	GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(AppLoader.injector);
    
    String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(
    		CommonProperties.MOXY_JSON_FEATURE_DISABLE,
               getConfiguration().getRuntimeType());
       property(disableMoxy, true);
       property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);

       // add the default Jackson exception mappers
       register(JacksonFeature.class);
       
       packages(JerseyApplication.class.getPackage().getName());
       
    for (JerseyConfigurator configurator: AppLoader.getExtensions(JerseyConfigurator.class)) {
    	configurator.configure(this);
    }
}
 
Example #2
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Get the port to be used for test application deployments.
 *
 * @return The HTTP port of the URI
 */
protected final int getPort() {
    final String value = AccessController.doPrivileged(PropertiesHelper.getSystemProperty(TestProperties.CONTAINER_PORT));
    if (value != null) {

        try {
            final int i = Integer.parseInt(value);
            if (i <= 0) {
                throw new NumberFormatException("Value not positive.");
            }
            return i;
        } catch (NumberFormatException e) {
            LOGGER.log(Level.CONFIG,
                    "Value of " + TestProperties.CONTAINER_PORT
                            + " property is not a valid positive integer [" + value + "]."
                            + " Reverting to default [" + TestProperties.DEFAULT_CONTAINER_PORT + "].",
                    e);
        }
    }
    return TestProperties.DEFAULT_CONTAINER_PORT;
}
 
Example #3
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
private String getProperty(String propertyName) {
    if (forcedPropertyMap.containsKey(propertyName)) {
        return forcedPropertyMap.get(propertyName);
    }

    final Properties systemProperties = AccessController.doPrivileged(PropertiesHelper.getSystemProperties());
    if (systemProperties.containsKey(propertyName)) {
        return systemProperties.getProperty(propertyName);
    }

    if (propertyMap.containsKey(propertyName)) {
        return propertyMap.get(propertyName);
    }

    return null;
}
 
Example #4
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Get the port to be used for test application deployments.
 *
 * @return The HTTP port of the URI
 */
protected final int getPort() {
    final String value = AccessController.doPrivileged(PropertiesHelper.getSystemProperty(TestProperties.CONTAINER_PORT));
    if (value != null) {

        try {
            final int i = Integer.parseInt(value);
            if (i <= 0) {
                throw new NumberFormatException("Value not positive.");
            }
            return i;
        } catch (NumberFormatException e) {
            LOGGER.log(Level.CONFIG,
                    "Value of " + TestProperties.CONTAINER_PORT
                            + " property is not a valid positive integer [" + value + "]."
                            + " Reverting to default [" + TestProperties.DEFAULT_CONTAINER_PORT + "].",
                    e);
        }
    }
    return TestProperties.DEFAULT_CONTAINER_PORT;
}
 
Example #5
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
private String getProperty(String propertyName) {
    if (forcedPropertyMap.containsKey(propertyName)) {
        return forcedPropertyMap.get(propertyName);
    }

    final Properties systemProperties = AccessController.doPrivileged(PropertiesHelper.getSystemProperties());
    if (systemProperties.containsKey(propertyName)) {
        return systemProperties.getProperty(propertyName);
    }

    if (propertyMap.containsKey(propertyName)) {
        return propertyMap.get(propertyName);
    }

    return null;
}
 
Example #6
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
/**
 * Get the port to be used for test application deployments.
 *
 * @return The HTTP port of the URI
 */
protected final int getPort() {
    final String value = AccessController.doPrivileged(PropertiesHelper.getSystemProperty(TestProperties.CONTAINER_PORT));
    if (value != null) {

        try {
            final int i = Integer.parseInt(value);
            if (i <= 0) {
                throw new NumberFormatException("Value not positive.");
            }
            return i;
        } catch (NumberFormatException e) {
            LOGGER.log(Level.CONFIG,
                    "Value of " + TestProperties.CONTAINER_PORT
                            + " property is not a valid positive integer [" + value + "]."
                            + " Reverting to default [" + TestProperties.DEFAULT_CONTAINER_PORT + "].",
                    e);
        }
    }
    return TestProperties.DEFAULT_CONTAINER_PORT;
}
 
Example #7
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
private String getProperty(String propertyName) {
    if (forcedPropertyMap.containsKey(propertyName)) {
        return forcedPropertyMap.get(propertyName);
    }

    final Properties systemProperties = AccessController.doPrivileged(PropertiesHelper.getSystemProperties());
    if (systemProperties.containsKey(propertyName)) {
        return systemProperties.getProperty(propertyName);
    }

    if (propertyMap.containsKey(propertyName)) {
        return propertyMap.get(propertyName);
    }

    return null;
}
 
Example #8
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 #9
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 #10
Source File: APIServer.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
protected void init(ScanResult result) {
  // FILTERS
  register(JSONPrettyPrintFilter.class);
  register(MediaTypeFilter.class);

  // RESOURCES
  for (Class<?> resource : result.getAnnotatedClasses(APIResource.class)) {
    register(resource);
  }

  // FEATURES
  register(DACAuthFilterFeature.class);
  register(DACJacksonJaxbJsonFeature.class);
  register(DACExceptionMapperFeature.class);

  // EXCEPTION MAPPERS
  register(JsonParseExceptionMapper.class);
  register(JsonMappingExceptionMapper.class);

  // PROPERTIES
  property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true");

  final String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(CommonProperties.MOXY_JSON_FEATURE_DISABLE,
    getConfiguration().getRuntimeType());
  property(disableMoxy, true);
}
 
Example #11
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 #12
Source File: AbstractTemplateProcessor.java    From ameba with MIT License 5 votes vote down vote up
/**
 * <p>Constructor for AbstractTemplateProcessor.</p>
 *
 * @param config              a {@link javax.ws.rs.core.Configuration} object.
 * @param propertySuffix      a {@link java.lang.String} object.
 * @param supportedExtensions a {@link java.lang.String} object.
 */
public AbstractTemplateProcessor(Configuration config, String propertySuffix, String... supportedExtensions) {
    this.config = config;
    this.suffix = '.' + propertySuffix;
    Map<String, Object> properties = config.getProperties();
    String basePath = TemplateHelper.getBasePath(properties, propertySuffix);

    Collection<String> basePaths = TemplateHelper.getBasePaths(basePath);

    this.basePath = basePaths.toArray(new String[basePaths.size()]);

    Boolean cacheEnabled = PropertiesHelper.getValue(properties,
            MvcFeature.CACHE_TEMPLATES + this.suffix, Boolean.class, null);
    if (cacheEnabled == null) {
        cacheEnabled = PropertiesHelper.getValue(properties, MvcFeature.CACHE_TEMPLATES, false, null);
    }

    this.cache = cacheEnabled ? DataStructures.createConcurrentMap() : null;
    this.encoding = TemplateHelper.getTemplateOutputEncoding(config, this.suffix);

    this.supportedExtensions = Sets.newHashSet(Collections2.transform(
            Arrays.asList(supportedExtensions), input -> {
                input = input.toLowerCase();
                return input.startsWith(".") ? input : "." + input;
            }));

}
 
Example #13
Source File: DataViewMessageBodyWriter.java    From ameba with MIT License 5 votes vote down vote up
/**
 * <p>Constructor for DataViewMessageBodyWriter.</p>
 *
 * @param application a {@link ameba.core.Application} object.
 */
@Inject
public DataViewMessageBodyWriter(Application application) {
    dataViewDisabled = "true".equals(application.getProperty(DISABLE_DATA_VIEW));
    defaultDataViewDisabled = "true".equals(application.getProperty(DISABLE_DEFAULT_DATA_VIEW));
    Map<String, Object> properties = application.getProperties();
    dataViewList = PropertiesHelper.getValue(properties, DATA_VIEW_LIST_KEY, DEFAULT_DATA_LIST, null);
    dataViewItem = PropertiesHelper.getValue(properties, DATA_VIEW_ITEM_KEY, DEFAULT_DATA_ITEM, null);
    dataViewNull = PropertiesHelper.getValue(properties, DATA_VIEW_NULL_KEY, DEFAULT_DATA_NULL, null);
}
 
Example #14
Source File: TemplateHelper.java    From ameba with MIT License 5 votes vote down vote up
/**
 * Get output encoding from configuration.
 *
 * @param configuration Configuration.
 * @param suffix        Template processor suffix of the
 *                      to configuration property {@link org.glassfish.jersey.server.mvc.MvcFeature#ENCODING}.
 * @return Encoding read from configuration properties or a default encoding if no encoding is configured.
 */
public static Charset getTemplateOutputEncoding(Configuration configuration, String suffix) {
    final String enc = PropertiesHelper.getValue(configuration.getProperties(), MvcFeature.ENCODING + suffix,
            String.class, null);
    if (enc == null) {
        return DEFAULT_ENCODING;
    } else {
        return Charset.forName(enc);
    }
}
 
Example #15
Source File: TemplateHelper.java    From ameba with MIT License 5 votes vote down vote up
/**
 * <p>getBasePath.</p>
 *
 * @param properties a {@link java.util.Map} object.
 * @param cfgSuffix a {@link java.lang.String} object.
 * @return a {@link java.lang.String} object.
 */
public static String getBasePath(Map<String, Object> properties, String cfgSuffix) {
    String basePath = PropertiesHelper.getValue(properties,
            MvcFeature.TEMPLATE_BASE_PATH + "." + cfgSuffix, String.class, null);
    if (basePath == null) {
        basePath = PropertiesHelper.getValue(properties, MvcFeature.TEMPLATE_BASE_PATH, "", null);
    }
    return basePath;
}
 
Example #16
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;
}
 
Example #17
Source File: GatewayBinaryResponseFilter.java    From jrestless with Apache License 2.0 4 votes vote down vote up
private boolean isBinaryCompressionOnly() {
	Object binaryCompressionOnlyProp = configuration.getProperty(BINARY_COMPRESSION_ONLY_PROPERTY);
	return binaryCompressionOnlyProp == null
			|| PropertiesHelper.isProperty(binaryCompressionOnlyProp);
}
 
Example #18
Source File: ElasticConnectionPool.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public void connect() throws IOException {
  final ClientConfig configuration = new ClientConfig();
  configuration.property(ClientProperties.READ_TIMEOUT, readTimeoutMillis);
  final AWSCredentialsProvider awsCredentialsProvider = elasticsearchAuthentication.getAwsCredentialsProvider();
  if (awsCredentialsProvider != null) {
    configuration.property(REGION_NAME, elasticsearchAuthentication.getRegionName());
    configuration.register(ElasticsearchRequestClientFilter.class);
    configuration.register(new InjectableAWSCredentialsProvider(awsCredentialsProvider), InjectableAWSCredentialsProvider.class);
  }

  final ClientBuilder builder = ClientBuilder.newBuilder()
      .withConfig(configuration);

  switch(sslMode) {
  case UNSECURE:
    builder.sslContext(SSLHelper.newAllTrustingSSLContext("SSL"));
    // fall-through
  case VERIFY_CA:
    builder.hostnameVerifier(SSLHelper.newAllValidHostnameVerifier());
    // fall-through
  case STRICT:
    break;

  case OFF:
    // no TLS/SSL configuration
  }

  client = builder.build();
  client.register(GZipEncoder.class);
  client.register(DeflateEncoder.class);
  client.register(EncodingFilter.class);

  if (REQUEST_LOGGER.isDebugEnabled()) {
    java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(REQUEST_LOGGER_NAME);
    client.register(new LoggingFeature(
        julLogger,
        Level.FINE,
        REQUEST_LOGGER.isTraceEnabled() ? LoggingFeature.Verbosity.PAYLOAD_TEXT : LoggingFeature.Verbosity.HEADERS_ONLY,
        65536));
  }

  final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
  provider.setMapper(ElasticMappingSet.MAPPER);

  // Disable other JSON providers.
  client.property(
    PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, client.getConfiguration().getRuntimeType()),
    JacksonJaxbJsonProvider.class.getSimpleName());

  client.register(provider);

  HttpAuthenticationFeature httpAuthenticationFeature = elasticsearchAuthentication.getHttpAuthenticationFeature();
  if (httpAuthenticationFeature != null) {
    client.register(httpAuthenticationFeature);
  }

  updateClients();
}
 
Example #19
Source File: RestServerV2.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
protected void init(ScanResult result) {
  // FILTERS //
  register(JSONPrettyPrintFilter.class);
  register(MediaTypeFilter.class);

  // RESOURCES //
  for (Class<?> resource : result.getAnnotatedClasses(RestResource.class)) {
    register(resource);
  }

  // FEATURES
  property(FreemarkerMvcFeature.TEMPLATE_OBJECT_FACTORY, getFreemarkerConfiguration());
  register(FreemarkerMvcFeature.class);
  register(MultiPartFeature.class);
  register(FirstTimeFeature.class);
  register(DACAuthFilterFeature.class);
  register(DACExceptionMapperFeature.class);
  register(DACJacksonJaxbJsonFeature.class);
  register(JSONJobDataFilter.class);
  register(TestResourcesFeature.class);

  // LISTENERS //
  register(TimingApplicationEventListener.class);

  // EXCEPTION MAPPERS //
  register(JsonParseExceptionMapper.class);
  register(JsonMappingExceptionMapper.class);


  //  BODY WRITERS //
  register(QlikAppMessageBodyGenerator.class);
  register(TableauMessageBodyGenerator.class);


  // PROPERTIES //
  property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true");

  final String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(CommonProperties.MOXY_JSON_FEATURE_DISABLE,
      getConfiguration().getRuntimeType());
  property(disableMoxy, true);
  property(TableauMessageBodyGenerator.CUSTOMIZATION_ENABLED, false);
}
 
Example #20
Source File: DrillRestServer.java    From Bats with Apache License 2.0 4 votes vote down vote up
public DrillRestServer(final WorkManager workManager, final ServletContext servletContext, final Drillbit drillbit) {
  register(DrillRoot.class);
  register(StatusResources.class);
  register(StorageResources.class);
  register(ProfileResources.class);
  register(QueryResources.class);
  register(MetricsResources.class);
  register(ThreadsResources.class);
  register(LogsResources.class);

  property(FreemarkerMvcFeature.TEMPLATE_OBJECT_FACTORY, getFreemarkerConfiguration(servletContext));
  register(FreemarkerMvcFeature.class);

  register(MultiPartFeature.class);
  property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, true);

  final boolean isAuthEnabled =
      workManager.getContext().getConfig().getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED);

  if (isAuthEnabled) {
    register(LogInLogOutResources.class);
    register(AuthDynamicFeature.class);
    register(RolesAllowedDynamicFeature.class);
  }

  //disable moxy so it doesn't conflict with jackson.
  final String disableMoxy = PropertiesHelper.getPropertyNameForRuntime(CommonProperties.MOXY_JSON_FEATURE_DISABLE,
      getConfiguration().getRuntimeType());
  property(disableMoxy, true);

  register(JsonParseExceptionMapper.class);
  register(JsonMappingExceptionMapper.class);
  register(GenericExceptionMapper.class);

  JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
  provider.setMapper(workManager.getContext().getLpPersistence().getMapper());
  register(provider);

  // Get an EventExecutor out of the BitServer EventLoopGroup to notify listeners for WebUserConnection. For
  // actual connections between Drillbits this EventLoopGroup is used to handle network related events. Though
  // there is no actual network connection associated with WebUserConnection but we need a CloseFuture in
  // WebSessionResources, so we are using EvenExecutor from network EventLoopGroup pool.
  final EventExecutor executor = workManager.getContext().getBitLoopGroup().next();

  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bind(drillbit).to(Drillbit.class);
      bind(workManager).to(WorkManager.class);
      bind(executor).to(EventExecutor.class);
      bind(workManager.getContext().getLpPersistence().getMapper()).to(ObjectMapper.class);
      bind(workManager.getContext().getStoreProvider()).to(PersistentStoreProvider.class);
      bind(workManager.getContext().getStorage()).to(StoragePluginRegistry.class);
      bind(new UserAuthEnabled(isAuthEnabled)).to(UserAuthEnabled.class);
      if (isAuthEnabled) {
        bindFactory(DrillUserPrincipalProvider.class).to(DrillUserPrincipal.class);
        bindFactory(AuthWebUserConnectionProvider.class).to(WebUserConnection.class);
      } else {
        bindFactory(AnonDrillUserPrincipalProvider.class).to(DrillUserPrincipal.class);
        bindFactory(AnonWebUserConnectionProvider.class).to(WebUserConnection.class);
      }
    }
  });
}