Java Code Examples for org.glassfish.jersey.server.ResourceConfig#packages()
The following examples show how to use
org.glassfish.jersey.server.ResourceConfig#packages() .
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 |
@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: Util.java From tessera with Apache License 2.0 | 6 votes |
public static JerseyTest create(Enclave enclave) { SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); return new JerseyTest() { @Override protected Application configure() { enable(TestProperties.LOG_TRAFFIC); enable(TestProperties.DUMP_ENTITY); set(TestProperties.CONTAINER_PORT, SocketUtils.findAvailableTcpPort()); EnclaveApplication application = new EnclaveApplication(new EnclaveResource(enclave)); ResourceConfig config = ResourceConfig.forApplication(application); config.packages("com.quorum.tessera.enclave.rest"); return config; } }; }
Example 3
Source File: HelixRestServer.java From helix with Apache License 2.0 | 6 votes |
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 4
Source File: ProxyServer.java From pulsar with Apache License 2.0 | 5 votes |
public void addRestResources(String basePath, String javaPackages, String attribute, Object attributeValue) { ResourceConfig config = new ResourceConfig(); config.packages("jersey.config.server.provider.packages", javaPackages); config.register(JsonMapperProvider.class); ServletHolder servletHolder = new ServletHolder(new ServletContainer(config)); servletHolder.setAsyncSupported(true); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(basePath); context.addServlet(servletHolder, "/*"); context.setAttribute(attribute, attributeValue); handlers.add(context); }
Example 5
Source File: EmbeddedServer.java From java-client with Apache License 2.0 | 5 votes |
private HttpServer createHttpServer() throws IOException { ResourceConfig config = new ResourceConfig(); config.packages(true, "com.blockcypher.model"); config.register(new DynamicBinding()); config.register(new WebhookJsonReader()); return JdkHttpServerFactory.createHttpServer(getURI(), config); }
Example 6
Source File: ClassDefinitionFastJsonProviderTest.java From fastjson-jaxrs-json-provider with Apache License 2.0 | 5 votes |
@Override protected Application configure() { enable(TestProperties.LOG_TRAFFIC); enable(TestProperties.DUMP_ENTITY); ResourceConfig config = new ResourceConfig(); Class<?>[] jsonTypes = {User.class}; config.register(new FastJsonFeature()).register(new FastJsonProvider(jsonTypes)); config.packages("com.colobu.fastjson", "com.colobu.test"); return config; }
Example 7
Source File: FastJsonProviderTest.java From fastjson-jaxrs-json-provider with Apache License 2.0 | 5 votes |
@Override protected Application configure() { enable(TestProperties.LOG_TRAFFIC); enable(TestProperties.DUMP_ENTITY); ResourceConfig config = new ResourceConfig(); //config.register(new FastJsonFeature()).register(FastJsonProvider.class); config.register(new FastJsonFeature()).register(new FastJsonProvider().setPretty(true)); config.packages("com.colobu.fastjson"); return config; }
Example 8
Source File: TestMSDAccessorLeaderElection.java From helix with Apache License 2.0 | 5 votes |
@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 9
Source File: AbstractTestClass.java From helix with Apache License 2.0 | 5 votes |
@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 10
Source File: WebServer.java From pulsar with Apache License 2.0 | 5 votes |
public void addRestResources(String basePath, String javaPackages, String attribute, Object attributeValue) { ResourceConfig config = new ResourceConfig(); config.packages("jersey.config.server.provider.packages", javaPackages); config.register(JsonMapperProvider.class); ServletHolder servletHolder = new ServletHolder(new ServletContainer(config)); servletHolder.setAsyncSupported(true); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(basePath); context.addServlet(servletHolder, "/*"); context.setAttribute(attribute, attributeValue); handlers.add(context); }
Example 11
Source File: WebService.java From pulsar with Apache License 2.0 | 5 votes |
public void addRestResources(String basePath, String javaPackages, boolean requiresAuthentication, Map<String,Object> attributeMap) { ResourceConfig config = new ResourceConfig(); config.packages("jersey.config.server.provider.packages", javaPackages); config.register(JsonMapperProvider.class); config.register(MultiPartFeature.class); ServletHolder servletHolder = new ServletHolder(new ServletContainer(config)); servletHolder.setAsyncSupported(true); addServlet(basePath, servletHolder, requiresAuthentication, attributeMap); }
Example 12
Source File: MCRJerseyDefaultConfiguration.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * Setup features. By default the multi part feature and every mycore feature * class in "org.mycore.frontend.jersey.feature". * * @param resourceConfig the jersey resource configuration */ protected void setupFeatures(ResourceConfig resourceConfig) { // multi part resourceConfig.register(MultiPartFeature.class); // mycore features resourceConfig.packages("org.mycore.frontend.jersey.feature"); }
Example 13
Source File: MCRJerseyDefaultConfiguration.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * Setup the jersey resources. * * @param resourceConfig the jersey resource configuration */ protected void setupResources(ResourceConfig resourceConfig) { String propertyString = MCRConfiguration2.getString("MCR.Jersey.Resource.Packages") .orElse("org.mycore.frontend.jersey.resources"); resourceConfig.packages(propertyString.split(",")); LogManager.getLogger().info("Scanning jersey resource packages {}", propertyString); }
Example 14
Source File: Server.java From livestream-api-samples with MIT License | 4 votes |
public void start() { URI baseUri = UriBuilder.fromUri(getServerAddress() + "/").build(); ResourceConfig config = new ResourceConfig(); config.packages("com.livestream.api.samples.securetoken.server"); JdkHttpServerFactory.createHttpServer(baseUri, config); }
Example 15
Source File: Server.java From livestream-api-samples with MIT License | 4 votes |
public void start() { URI baseUri = UriBuilder.fromUri(getServerAddress() + "/").build(); ResourceConfig config = new ResourceConfig(); config.packages("com.livestream.api.samples.apikeys.server"); JdkHttpServerFactory.createHttpServer(baseUri, config); }
Example 16
Source File: DemoApp.java From bromium with MIT License | 4 votes |
public void runOnSeparateThread() throws Exception { for (String resource: resourcesToBeExtractedInDirectory) { InputStream resourceAsStream = this.getClass().getResourceAsStream("/" + resource); File outputFile = Paths.get(baseOutputDirectory.getAbsolutePath(), resource).toFile(); FileOutputStream fileOutputStream = FileUtils.openOutputStream(outputFile); IOUtils.copy(resourceAsStream, fileOutputStream); } ResourceConfig config = new ResourceConfig(); config.packages("com.hribol.bromium.demo.app"); ServletHolder servlet = new ServletHolder(new ServletContainer(config)); server = new Server(0); ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase(baseOutputDirectory.getAbsolutePath()); resourceHandler.setDirectoriesListed(true); resourceHandler.setWelcomeFiles(new String[] { "index.html" }); ServletContextHandler context = new ServletContextHandler(server, "/*"); context.addServlet(servlet, "/*"); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { resourceHandler, context }); server.setHandler(handlers); server.start(); this.port = ((ServerConnector) server.getConnectors()[0]).getLocalPort(); logger.info("Server started on port " + port); new Thread(() -> { try { server.join(); } catch (InterruptedException e) { logger.info("Interrupted!", e); } }).start(); }
Example 17
Source File: RestServer.java From DataLink with Apache License 2.0 | 4 votes |
public void start(Keeper keeper) { log.info("Starting REST server"); ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.packages("com.ucar.datalink.worker.core.runtime.rest.resources"); resourceConfig.register(new FastJsonProvider()); resourceConfig.register(RootResource.class); resourceConfig.register(new TasksResource(keeper)); resourceConfig.register(RestExceptionMapper.class); resourceConfig.register(FlushResource.class); resourceConfig.register(HBaseMetaResource.class); resourceConfig.register(WorkerResource.class); ServletContainer servletContainer = new ServletContainer(resourceConfig); ServletHolder servletHolder = new ServletHolder(servletContainer); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); String allowedOrigins = config.getString(WorkerConfig.ACCESS_CONTROL_ALLOW_ORIGIN_CONFIG); if (allowedOrigins != null && !allowedOrigins.trim().isEmpty()) { FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter()); filterHolder.setName("cross-origin"); filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, allowedOrigins); String allowedMethods = config.getString(WorkerConfig.ACCESS_CONTROL_ALLOW_METHODS_CONFIG); if (allowedMethods != null && !allowedOrigins.trim().isEmpty()) { filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, allowedMethods); } context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); } RequestLogHandler requestLogHandler = new RequestLogHandler(); Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setLoggerName(RestServer.class.getCanonicalName()); requestLog.setLogLatency(true); requestLogHandler.setRequestLog(requestLog); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[]{context, new DefaultHandler(), requestLogHandler}); /* Needed for graceful shutdown as per `setStopTimeout` documentation */ StatisticsHandler statsHandler = new StatisticsHandler(); statsHandler.setHandler(handlers); jettyServer.setHandler(statsHandler); jettyServer.setStopTimeout(GRACEFUL_SHUTDOWN_TIMEOUT_MS); jettyServer.setStopAtShutdown(true); try { jettyServer.start(); } catch (Exception e) { throw new DatalinkException("Unable to start REST server", e); } log.info("REST server listening at " + jettyServer.getURI() + ", advertising URL " + advertisedUrl()); }
Example 18
Source File: ExoPlatformLocator.java From exo-demo with MIT License | 4 votes |
/** * Initializes Grizzly-based REST interfaces as defined in the messaging config. This method will * allow for REST endpoints using HTTPS by defining keystore information in exo-config.json. * Enabling REST will automatically expose the endpoints service and generate an ANNOUNCE_NODE message. * @param restConfig */ public static void initREST(MessagingConfig restConfig) { URI baseUri = UriBuilder.fromUri("http://0.0.0.0").port(restConfig.port).build(); ResourceConfig config = new ResourceConfig() .packages("com.txmq.exo.messaging.rest") .register(new CORSFilter()) .register(JacksonFeature.class) .register(MultiPartFeature.class); for (String pkg : restConfig.handlers) { config.packages(pkg); } System.out.println("Attempting to start Grizzly on " + baseUri); HttpServer grizzly = null; if (restConfig.secured == true) { SSLContextConfigurator sslContext = new SSLContextConfigurator(); sslContext.setKeyStoreFile(restConfig.serverKeystore.path); sslContext.setKeyStorePass(restConfig.serverKeystore.password); sslContext.setTrustStoreFile(restConfig.serverTruststore.path); sslContext.setTrustStorePass(restConfig.serverTruststore.password); grizzly = GrizzlyHttpServerFactory.createHttpServer( baseUri, config, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false) ); } else { grizzly = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); } //Track Grizzly instances so they can be shut down later if (grizzly != null) { httpServers.add(grizzly); } //Publish available Exo API endpoints to the HG. try { String externalUrl = baseUri.toString(); if (platform != null) { externalUrl = "http://"; byte[] rawAddress = platform.getAddress().getAddressExternalIpv4(); for (int ptr = 0; ptr < rawAddress.length; ptr++) { int i = rawAddress[ptr] & 0xFF; externalUrl += Integer.toString(i); if (ptr < rawAddress.length - 1) { externalUrl += "."; } } externalUrl += ":" + restConfig.port; System.out.println("Reporting available REST API at " + externalUrl); } else { } createTransaction( new ExoMessage( new ExoTransactionType(ExoTransactionType.ANNOUNCE_NODE), externalUrl ) ); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }