org.glassfish.jersey.CommonProperties Java Examples

The following examples show how to use org.glassfish.jersey.CommonProperties. 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: 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 #3
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 #4
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 #5
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 #6
Source File: RestUtils.java    From chipster with MIT License 6 votes vote down vote up
public static ResourceConfig getResourceConfig() {

		ResourceConfig rc = new ResourceConfig()
				/*
				 * Disable auto discovery so that we can decide what we want to register and
				 * what not. Don't register JacksonFeature, because it will register
				 * JacksonMappingExceptionMapper, which annoyingly swallows response's
				 * JsonMappingExceptions. Register directly the JacksonJaxbJsonProvider which is
				 * enough for the actual JSON conversion (see the code of JacksonFeature).
				 */
				.property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true).register(JacksonJaxbJsonProvider.class)
//				.register(JavaTimeObjectMapperProvider.class)
//				// register all exception mappers
//				.packages(NotFoundExceptionMapper.class.getPackage().getName())
//				// enable the RolesAllowed annotation
//				.register(RolesAllowedDynamicFeature.class)
				.register(JsonPrettyPrintQueryParamContainerResponseFilter.class);

		return rc;
	}
 
Example #7
Source File: FastJsonFeature.java    From metrics with Apache License 2.0 5 votes vote down vote up
public boolean configure(final FeatureContext context) {
    final String disableMoxy = CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.'
            + context.getConfiguration().getRuntimeType().name().toLowerCase();
    context.property(disableMoxy, true);
    context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
    return true;
}
 
Example #8
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 #9
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);
      }
    }
  });
}
 
Example #10
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 #11
Source File: PublicApi.java    From pay-publicapi with MIT License 4 votes vote down vote up
@Override
public void run(PublicApiConfig configuration, Environment environment) {
    initialiseSSLSocketFactory();

    final Injector injector = Guice.createInjector(new PublicApiModule(configuration, environment));

    environment.healthChecks().register("ping", new Ping());

    environment.jersey().register(injector.getInstance(HealthCheckResource.class));
    environment.jersey().register(injector.getInstance(PaymentsResource.class));
    environment.jersey().register(injector.getInstance(DirectDebitEventsResource.class));
    environment.jersey().register(injector.getInstance(PaymentRefundsResource.class));
    environment.jersey().register(injector.getInstance(RequestDeniedResource.class));
    environment.jersey().register(injector.getInstance(MandatesResource.class));
    environment.jersey().register(injector.getInstance(SearchRefundsResource.class));
    environment.jersey().register(injector.getInstance(DirectDebitPaymentsResource.class));
    environment.jersey().register(injector.getInstance(TransactionsResource.class));
    environment.jersey().register(injector.getInstance(TelephonePaymentNotificationResource.class));
    environment.jersey().register(new InjectingValidationFeature(injector));
    environment.jersey().register(injector.getInstance(ReturnUrlValidator.class));

    environment.jersey().register(injector.getInstance(RateLimiterFilter.class));
    environment.jersey().register(injector.getInstance(LoggingMDCRequestFilter.class));

    environment.servlets().addFilter("ClearMdcValuesFilter", injector.getInstance(ClearMdcValuesFilter.class))
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1/*");

    environment.servlets().addFilter("AuthorizationValidationFilter", injector.getInstance(AuthorizationValidationFilter.class))
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1/*");

    environment.servlets().addFilter("LoggingFilter", injector.getInstance(LoggingFilter.class))
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1/*");

    /*
       Turn off 'FilteringJacksonJaxbJsonProvider' which overrides dropwizard JacksonMessageBodyProvider.
       Fails on Integration tests if not disabled. 
           - https://github.com/dropwizard/dropwizard/issues/1341
    */
    environment.jersey().property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.TRUE);

    CachingAuthenticator<String, Account> cachingAuthenticator = new CachingAuthenticator<>(
            environment.metrics(),
            injector.getInstance(AccountAuthenticator.class),
            configuration.getAuthenticationCachePolicy());

    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<Account>()
                    .setAuthenticator(cachingAuthenticator)
                    .setPrefix("Bearer")
                    .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(Account.class));

    attachExceptionMappersTo(environment.jersey());

    initialiseMetrics(configuration, environment);

    //health check removed as redis is not a mandatory dependency
    environment.healthChecks().unregister("redis");
}
 
Example #12
Source File: BootPlugin.java    From micro-server with Apache License 2.0 4 votes vote down vote up
@Override
public Function<FeatureContext,Map<String,Object>> jacksonFeatureProperties(){
	return context-> MapX.fromMap(MapXs.of(  CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.'
               + context.getConfiguration().getRuntimeType().name().toLowerCase(),true));
}
 
Example #13
Source File: JerseyPlugin.java    From micro-server with Apache License 2.0 4 votes vote down vote up
@Override
public Function<FeatureContext,Map<String,Object>> jacksonFeatureProperties(){
	return context-> MapX.fromMap(MapXs.of(  CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.'
               + context.getConfiguration().getRuntimeType().name().toLowerCase(),true));
}