public NiFiRegistryResourceConfig(@Context ServletContext servletContext) { // register filters register(HttpMethodOverrideFilter.class); // register the exception mappers & jackson object mapper resolver packages("org.apache.nifi.registry.web.mapper"); // register endpoints register(AccessPolicyResource.class); register(AccessResource.class); register(BucketResource.class); register(BucketFlowResource.class); register(FlowResource.class); register(ItemResource.class); register(TenantResource.class); // include bean validation errors in response property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); // this is necessary for the /access/token/kerberos endpoint to work correctly // when sending 401 Unauthorized with a WWW-Authenticate: Negotiate header. // if this value needs to be changed, kerberos authentication needs to move to filter chain // so it can directly set the HttpServletResponse instead of indirectly through a JAX-RS Response property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, true); }
public WebhookApp() { packages(RESOURCE_PACKAGE); Logs.common.info("install package: {}", RESOURCE_PACKAGE); register(HttpMethodOverrideFilter.class); Logs.common.info("install filter: {}", HttpMethodOverrideFilter.class.getSimpleName()); Logs.common.info("{} installed.", WebhookApp.class.getSimpleName()); }
@Override public Handler getHandler(final Server server, String context, String applicationName) { ResourceConfig rc = new ResourceConfig(); if (enableSwagger) { BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.0"); beanConfig.setResourcePackage(""); beanConfig.setScan(true); beanConfig.setBasePath("/"); beanConfig.setTitle(applicationName); Set<String> packages = new HashSet<>(); packages.add(ApiListingResource.class.getPackage().getName()); for (Class<?> clazz : allClasses) { packages.add(clazz.getPackage().getName()); } rc.packages(packages.toArray(new String[0])); } rc.registerClasses(allClasses); rc.register(HttpMethodOverrideFilter.class); rc.register(new JacksonFeature().withMapper(mapper)); rc.register(MultiPartFeature.class); // adds support for multi-part API requests rc.registerInstances(allBinders); rc.registerInstances( new InjectableBinder(allInjectables), new AbstractBinder() { @Override protected void configure() { bind(server).to(Server.class); } } ); if (supportCORS) { rc.register(CorsContainerResponseFilter.class); } for (ContainerRequestFilter containerRequestFilter : containerRequestFilters) { rc.register(containerRequestFilter); } for (ContainerResponseFilter containerResponseFilter : containerResponseFilters) { rc.register(containerResponseFilter); } ServletHolder servletHolder = new ServletHolder(new ServletContainer(rc)); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); servletContextHandler.setContextPath(context); if (!applicationName.isEmpty()) { servletContextHandler.setDisplayName(applicationName); } servletContextHandler.addServlet(servletHolder, "/*"); servletContextHandler.addFilter(NewRelicRequestFilter.class, "/", EnumSet.of(DispatcherType.REQUEST)); return servletContextHandler; }
public Openscoring(){ super(ModelResource.class, MetricResource.class); final Config config = ConfigFactory.load(); Binder binder = new AbstractBinder(){ @Override public void configure(){ bind(config).to(Config.class).named("openscoring"); bind(ModelRegistry.class).to(ModelRegistry.class).in(Singleton.class); bind(MetricRegistry.class).to(MetricRegistry.class).in(Singleton.class); } }; register(binder); // JSON support register(JacksonJsonProvider.class); register(ObjectMapperProvider.class); // Convert exceptions to JSON objects register(WebApplicationExceptionMapper.class); // Permit the HTTP POST method to be changed to HTTP PUT or DELETE methods register(HttpMethodOverrideFilter.class); // File upload support register(MultiPartFeature.class); // Security support register(RolesAllowedDynamicFeature.class); // GZip and Deflate encoding support register(EncodingFilter.class); register(GZipEncoder.class); register(DeflateEncoder.class); Config applicationConfig = config.getConfig("application"); List<String> componentClassNames = applicationConfig.getStringList("componentClasses"); for(String componentClassName : componentClassNames){ Class<?> clazz; try { clazz = Class.forName(componentClassName); } catch(ClassNotFoundException cnfe){ throw new IllegalArgumentException(cnfe); } register(clazz); } }