org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature Java Examples

The following examples show how to use org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature. 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: WebApplicationResourceConfig.java    From game-of-life-modern-java with MIT License 6 votes vote down vote up
public WebApplicationResourceConfig() {
   	packages("com.giorgiosironi.gameoflife.web");
   	property(MvcFeature.TEMPLATE_BASE_PATH, "templates");
   	register(FreemarkerMvcFeature.class);
   	register(new AbstractBinder() {
		@Override
		protected void configure() {
			InMemoryGenerationRepository repository = new InMemoryGenerationRepository();
			Generation original = Generation.withAliveCells(
					Cell.onXAndY(1, 1),
					Cell.onXAndY(1, 2),
					Cell.onXAndY(2, 1),
					Cell.onXAndY(2, 2),
					Cell.onXAndY(7, 1),
					Cell.onXAndY(7, 2),
					Cell.onXAndY(7, 3),
					Cell.onXAndY(7, 8)
			);
			repository.add("a-block-and-a-bar", 0, original);
			bind(repository).to(GenerationRepository.class);
		}
   	});
}
 
Example #2
Source File: MotdApplication.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public MotdApplication() {
    // scan com.gluonhq package for jax-rs classes
    packages(true, "com.gluonhq");

    // everything inside /webjars should not be handled by the jax-rs application
    property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, "/webjars/.*");

    // use freemarker for web templating
    register(FreemarkerMvcFeature.class);
    property(FreemarkerMvcFeature.TEMPLATE_BASE_PATH, "freemarker");
}
 
Example #3
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 #4
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 #5
Source File: Jersey2Plugin.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public InitState init(InitContext initContext) {
    RestPlugin restPlugin = initContext.dependency(RestPlugin.class);

    if (restPlugin.isEnabled()) {
        RestConfig restConfig = restPlugin.getRestConfig();

        Set<Class<?>> resources = new HashSet<>();
        Set<Class<?>> providers = new HashSet<>();
        List<RestProvider> restProviders = initContext.dependencies(RestProvider.class);
        for (RestProvider restProvider : restProviders) {
            resources.addAll(restProvider.resources());
            providers.addAll(filterClasses(restProvider.providers()));
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("{} JAX-RS resource(s) detected: {}", resources.size(), resources);
        } else {
            LOGGER.info("{} JAX-RS resource(s) detected (set logger to DEBUG to see them)", resources.size());
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("{} JAX-RS provider(s) detected: {}", providers.size(), providers);
        } else {
            LOGGER.info("{} JAX-RS provider(s) detected (set logger to DEBUG to see them)", providers.size());
        }

        Set<Class<?>> enabledFeatures = new HashSet<>();
        if (isMultipartFeaturePresent()) {
            enabledFeatures.add(MultiPartFeature.class);
            LOGGER.debug("Multipart feature is enabled");
        }

        if (isFreemarkerFeaturePresent()) {
            enabledFeatures.add(FreemarkerMvcFeature.class);
            LOGGER.debug("FreeMarker feature is enabled");
        }

        if (isJspFeaturePresent()) {
            enabledFeatures.add(JspMvcFeature.class);
            LOGGER.debug("JSP feature is enabled");
        }
        for (Class<?> featureClass : filterClasses(restConfig.getFeatures())) {
            enabledFeatures.add(featureClass);
            LOGGER.debug("Feature {} is enabled", featureClass.getCanonicalName());
        }

        Map<String, Object> jersey2Properties = buildJerseyProperties(restConfig);
        if (LOGGER.isTraceEnabled()) {
            for (Map.Entry<String, Object> entry : jersey2Properties.entrySet()) {
                LOGGER.debug("Jersey property {} = {}", entry.getKey(), entry.getValue());
            }
        }

        jersey2filterDefinition = new FilterDefinition("jersey2", SeedServletContainer.class);
        jersey2filterDefinition.setPriority(SeedFilterPriority.JERSEY);
        jersey2filterDefinition.setAsyncSupported(true);
        jersey2filterDefinition.addMappings(new FilterDefinition.Mapping(restConfig.getPath() + "/*"));
        jersey2filterDefinition.addInitParameters(buildInitParams(jersey2Properties));

        seedServletContainer = new SeedServletContainer(resources, providers, enabledFeatures, jersey2Properties);

        LOGGER.info("Jersey 2 serving JAX-RS resources on {}/*", restConfig.getPath());
    }

    return InitState.INITIALIZED;
}
 
Example #6
Source File: ViewApplicationConfig.java    From tutorials with MIT License 4 votes vote down vote up
public ViewApplicationConfig() {
    packages("com.baeldung.jersey.server");
    property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
    property(FreemarkerMvcFeature.TEMPLATE_BASE_PATH, "templates/freemarker");
    register(FreemarkerMvcFeature.class);;
}