Java Code Examples for org.glassfish.jersey.server.ResourceConfig#property()

The following examples show how to use org.glassfish.jersey.server.ResourceConfig#property() . 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: JettyServerProvider.java    From browserup-proxy with Apache License 2.0 8 votes vote down vote up
@Inject
public JettyServerProvider(@Named("port") int port, @Named("address") String address, MitmProxyManager proxyManager) throws UnknownHostException {
    OpenApiResource openApiResource = new OpenApiResource();
    openApiResource.setConfigLocation(SWAGGER_CONFIG_NAME);

    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.packages(SWAGGER_PACKAGE);
    resourceConfig.register(openApiResource);
    resourceConfig.register(proxyManagerToHkBinder(proxyManager));
    resourceConfig.register(JacksonFeature.class);
    resourceConfig.register(ConstraintViolationExceptionMapper.class);
    resourceConfig.registerClasses(LoggingFilter.class);

    resourceConfig.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
    resourceConfig.property(ServerProperties.WADL_FEATURE_DISABLE, true);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");

    context.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));;
    context.addServlet(DefaultServlet.class, "/");
    context.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");

    server = new Server(new InetSocketAddress(InetAddress.getByName(address), port));
    server.setHandler(context);
}
 
Example 2
Source File: EmissaryServer.java    From emissary with Apache License 2.0 6 votes vote down vote up
private ContextHandler buildMVCHandler() {

        final ResourceConfig application = new ResourceConfig();
        application.register(MultiPartFeature.class);
        // setup mustache templates
        application.property(MustacheMvcFeature.TEMPLATE_BASE_PATH, "/templates");
        application.register(MustacheMvcFeature.class).packages("emissary.server.mvc");

        ServletHolder mvcHolder = new ServletHolder(new org.glassfish.jersey.servlet.ServletContainer(application));
        // mvcHolder.setInitOrder(1);

        ServletContextHandler mvcHolderContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
        mvcHolderContext.addServlet(mvcHolder, "/*");

        return mvcHolderContext;
    }
 
Example 3
Source File: GrapheneRESTServer.java    From Graphene with GNU General Public License v3.0 6 votes vote down vote up
static ResourceConfig generateResourceConfig(Config config, Graphene graphene) {
	ResourceConfig rc = new ResourceConfig();

	// settings
	rc.property(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
	rc.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true); // TODO: remove in production

	// basic features
	rc.register(CORSFilter.class);
	rc.register(JacksonFeature.class);
	rc.register(ValidationFeature.class);

	// custom resources
	GrapheneResourceFactory factory = new GrapheneResourceFactory(config, graphene);

	rc.register(factory.createResource(AdminResource.class));
	rc.register(factory.createResource(CoreferenceResource.class));
	rc.register(factory.createResource(DiscourseSimplificationResource.class));
	rc.register(factory.createResource(RelationExtractionResource.class));

	return rc;
}
 
Example 4
Source File: GatewayBinaryResponseFilterIntTest.java    From jrestless with Apache License 2.0 6 votes vote down vote up
private JerseyTest createJerseyTest(Boolean binaryCompressionOnly) {
	return new JerseyTest() {
		@Override
		protected Application configure() {
			ResourceConfig config = new ResourceConfig();
			config.register(TestResource.class);
			config.register(EncodingFilter.class);
			config.register(GZipEncoder.class);
			config.register(GatewayBinaryResponseFilter.class);
			if (binaryCompressionOnly != null) {
				config.property(GatewayBinaryResponseFilter.BINARY_COMPRESSION_ONLY_PROPERTY,
						binaryCompressionOnly);
			}
			return config;
		}
	};
}
 
Example 5
Source File: HelixRestServer.java    From helix with Apache License 2.0 6 votes vote down vote up
protected ResourceConfig getResourceConfig(HelixRestNamespace namespace, ServletType type) {
  ResourceConfig cfg = new ResourceConfig();
  cfg.packages(type.getServletPackageArray());
  cfg.setApplicationName(namespace.getName());

  // Enable the default statistical monitoring MBean for Jersey server
  cfg.property(ServerProperties.MONITORING_STATISTICS_MBEANS_ENABLED, true);
  cfg.property(ContextPropertyKeys.SERVER_CONTEXT.name(),
      new ServerContext(namespace.getMetadataStoreAddress(), namespace.isMultiZkEnabled(),
          namespace.getMsdsEndpoint()));
  if (type == ServletType.DEFAULT_SERVLET) {
    cfg.property(ContextPropertyKeys.ALL_NAMESPACES.name(), _helixNamespaces);
  } else {
    cfg.property(ContextPropertyKeys.METADATA.name(), namespace);
  }

  cfg.register(new CORSFilter());
  cfg.register(new AuditLogFilter(_auditLoggers));
  return cfg;
}
 
Example 6
Source File: EndpointTestBase.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Override
protected Application configure() {
    new UnitTest().setupSystemProperties();
    // Tells Jersey to use first available port, fixes address already in use exception
    forceSet(TestProperties.CONTAINER_PORT, "0");
    final ResourceConfig application = new ResourceConfig();
    application.register(MultiPartFeature.class);
    application.property(MustacheMvcFeature.TEMPLATE_BASE_PATH, "/templates");
    application.register(MustacheMvcFeature.class).packages("emissary.server.mvc");
    application.register(MustacheMvcFeature.class).packages("emissary.server.api");

    return application;
}
 
Example 7
Source File: JerseySpringTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setApplicationContext(final ApplicationContext context) {
    _jerseyTest = new JerseyTest() {
        @Override
        protected Application configure() {
            ResourceConfig application = new ManagementApplication();
            application.register(AuthenticationFilter.class);
            application.property("contextConfig", context);

            return application;
        }
    };
}
 
Example 8
Source File: RequestHandler.java    From jrestless-examples with Apache License 2.0 5 votes vote down vote up
public RequestHandler() {
	// configure the application with the resource
	ResourceConfig resourceConfig = new ResourceConfig()
			.register(GatewayFeature.class)
			.register(RequestContextFilter.class)
			.packages("com.jrestless.aws.examples");
	resourceConfig.property("contextConfig", new AnnotationConfigApplicationContext(SpringConfig.class));
	init(resourceConfig);
	start();
}
 
Example 9
Source File: JerseySpringTest.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setApplicationContext(final ApplicationContext context)
{
    _jerseyTest = new JerseyTest()
    {
        
        @Override
        protected Application configure()
        {
            // Find first available port.
            forceSet(TestProperties.CONTAINER_PORT, "0");

            ResourceConfig application = new GraviteeManagementApplication(authenticationProviderManager);

            application.property("contextConfig", context);
            decorate(application);

            return application;
        }

        @Override
        protected void configureClient(ClientConfig config) {
            super.configureClient(config);

            config.register(ObjectMapperResolver.class);
            config.register(MultiPartFeature.class);
            config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);

        }
    };
}
 
Example 10
Source File: JerseySpringTest.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setApplicationContext(final ApplicationContext context)
{
    _jerseyTest = new JerseyTest()
    {
        @Override
        protected Application configure()
        {
            // Find first available port.
            forceSet(TestProperties.CONTAINER_PORT, "0");

            ResourceConfig application = new GraviteePortalApplication(authenticationProviderManager);

            application.property("contextConfig", context);
            decorate(application);

            return application;
        }

        @Override
        protected void configureClient(ClientConfig config) {
            super.configureClient(config);

            config.register(ObjectMapperResolver.class);
            config.register(MultiPartFeature.class);
        }
    };
}
 
Example 11
Source File: AbstractResourceTest.java    From yaas_java_jersey_wishlist with Apache License 2.0 5 votes vote down vote up
@Override
protected final Application configure() {
	final ResourceConfig application = new JerseyApplication();

	// configure spring context
	application.property("contextConfigLocation", "classpath:/META-INF/applicationContext.xml");

	return application;
}
 
Example 12
Source File: AbstractTestClass.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
protected Application configure() {
  // Configure server context
  ResourceConfig resourceConfig = new ResourceConfig();
  resourceConfig.packages(AbstractResource.class.getPackage().getName());
  ServerContext serverContext = new ServerContext(ZK_ADDR);
  resourceConfig.property(ContextPropertyKeys.SERVER_CONTEXT.name(), serverContext);
  resourceConfig.register(new AuditLogFilter(Collections.singletonList(new MockAuditLogger())));

  return resourceConfig;
}
 
Example 13
Source File: TestMSDAccessorLeaderElection.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
protected ResourceConfig getResourceConfig(HelixRestNamespace namespace, ServletType type) {
  ResourceConfig cfg = new ResourceConfig();
  List<String> packages = new ArrayList<>(Arrays.asList(type.getServletPackageArray()));
  packages.add(MockMetadataStoreDirectoryAccessor.class.getPackage().getName());
  cfg.packages(packages.toArray(new String[0]));
  cfg.setApplicationName(namespace.getName());
  cfg.property(ContextPropertyKeys.SERVER_CONTEXT.name(),
      new ServerContext(namespace.getMetadataStoreAddress()));
  cfg.property(ContextPropertyKeys.METADATA.name(), namespace);
  cfg.register(new CORSFilter());
  return cfg;
}
 
Example 14
Source File: DremioServer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public void startDremioServer(
  SingletonRegistry registry,
  DACConfig config,
  Provider<ServerHealthMonitor> serverHealthMonitor,
  Provider<NodeEndpoint> endpointProvider,
  Provider<SabotContext> contextProvider,
  Provider<RestServerV2> restServerProvider,
  Provider<APIServer> apiServerProvider,
  DremioBinder dremioBinder,
  Tracer tracer,
  String uiType,
  boolean isInternalUS
) throws Exception {
  try {
    if (!embeddedJetty.isRunning()) {
      createConnector(config);
      addHandlers();
    }

    // security header filters
    servletContextHandler.addFilter(SecurityHeadersFilter.class.getName(), "/*", EnumSet.of(DispatcherType.REQUEST));

    // server tracing filter.
    servletContextHandler.addFilter(SpanFinishingFilter.class.getName(), "/*", EnumSet.of(DispatcherType.REQUEST));

    // add the font mime type.
    final MimeTypes mimeTypes = servletContextHandler.getMimeTypes();
    mimeTypes.addMimeMapping("woff2", "application/font-woff2; charset=utf-8");
    servletContextHandler.setMimeTypes(mimeTypes);

    // WebSocket API
    final SocketServlet servlet = new SocketServlet(registry.lookup(JobsService.class), registry.lookup(TokenManager.class));
    final ServletHolder wsHolder = new ServletHolder(servlet);
    wsHolder.setInitOrder(3);
    servletContextHandler.addServlet(wsHolder, "/apiv2/socket");

    // Rest API
    ResourceConfig restServer = restServerProvider.get();

    restServer.property(RestServerV2.ERROR_STACKTRACE_ENABLE, config.sendStackTraceToClient);
    restServer.property(RestServerV2.TEST_API_ENABLE, config.allowTestApis);
    restServer.property(RestServerV2.FIRST_TIME_API_ENABLE, isInternalUS);

    restServer.register(dremioBinder);
    restServer.register(new ServerTracingDynamicFeature(tracer));

    final ServletHolder restHolder = new ServletHolder(new ServletContainer(restServer));
    restHolder.setInitOrder(2);
    servletContextHandler.addServlet(restHolder, "/apiv2/*");

    // Public API
    ResourceConfig apiServer = apiServerProvider.get();
    apiServer.register(dremioBinder);
    apiServer.register(new ServerTracingDynamicFeature(tracer));

    final ServletHolder apiHolder = new ServletHolder(new ServletContainer(apiServer));
    apiHolder.setInitOrder(3);
    servletContextHandler.addServlet(apiHolder, "/api/v3/*");

    if (config.verboseAccessLog) {
      accessLogFilter = new AccessLogFilter();
      servletContextHandler.addFilter(
        new FilterHolder(accessLogFilter),
        "/*",
        EnumSet.of(DispatcherType.REQUEST));
    }

    if (config.serveUI) {
      final String basePath = "rest/dremio_static/";
      final String markerPath = String.format("META-INF/%s.properties", uiType);

      final ServletHolder fallbackServletHolder = new ServletHolder("fallback-servlet", registry.lookup(DremioServlet.class));
      addStaticPath(fallbackServletHolder, basePath, markerPath);
      servletContextHandler.addServlet(fallbackServletHolder, "/*");

      // TODO DX-1556 - temporary static asset serving for showing Profiles
      final String baseStaticPath = "rest/static/";
      final String arrowDownResourceRelativePath = "rest/static/img/arrow-down-small.svg";
      ServletHolder restStaticHolder = new ServletHolder("static", DefaultServlet.class);
      // Get resource URL for legacy static assets, based on where some image is located
      addStaticPath(restStaticHolder, baseStaticPath, arrowDownResourceRelativePath);
      servletContextHandler.addServlet(restStaticHolder, "/static/*");
    }

    if (!embeddedJetty.isRunning()) {
      embeddedJetty.start();
    }

    setPortFromConnector();
    logger.info("Started on {}://localhost:" + port, config.webSSLEnabled() ? "https" : "http");

    serviceStarted = true;
  } catch (Exception ex) {
    throw new ServerErrorException(ex);
  }
}