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

The following examples show how to use org.glassfish.jersey.server.ResourceConfig#forApplication() . 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: Util.java    From tessera with Apache License 2.0 6 votes vote down vote up
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 2
Source File: Q2TRestAppTest.java    From tessera with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    final Set services = new HashSet();
    services.add(mock(TransactionManager.class));

    serviceLocator = (MockServiceLocator) ServiceLocator.create();
    serviceLocator.setServices(services);

    q2TRestApp = new Q2TRestApp();

    jersey =
            new JerseyTest() {
                @Override
                protected Application configure() {
                    enable(TestProperties.LOG_TRAFFIC);
                    enable(TestProperties.DUMP_ENTITY);
                    ResourceConfig jerseyconfig = ResourceConfig.forApplication(q2TRestApp);
                    return jerseyconfig;
                }
            };

    jersey.setUp();
}
 
Example 3
Source File: ThirdPartyRestAppTest.java    From tessera with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    serviceLocator = (MockServiceLocator) ServiceLocator.create();

    Set services = new HashSet();
    services.add(mock(IPWhitelistFilter.class));
    services.add(mock(TransactionManager.class));
    services.add(mock(PartyInfoService.class));

    serviceLocator.setServices(services);

    thirdParty = new ThirdPartyRestApp();

    jersey =
            new JerseyTest() {
                @Override
                protected Application configure() {
                    enable(TestProperties.LOG_TRAFFIC);
                    enable(TestProperties.DUMP_ENTITY);
                    ResourceConfig jerseyconfig = ResourceConfig.forApplication(thirdParty);
                    return jerseyconfig;
                }
            };
    jersey.setUp();
}
 
Example 4
Source File: RESTServer.java    From pravega with Apache License 2.0 6 votes vote down vote up
public RESTServer(LocalController localController, ControllerService controllerService, AuthHandlerManager pravegaAuthManager, RESTServerConfig restServerConfig, ConnectionFactory connectionFactory) {
    this.objectId = "RESTServer";
    this.restServerConfig = restServerConfig;
    final String serverURI = "http://" + restServerConfig.getHost() + "/";
    this.baseUri = UriBuilder.fromUri(serverURI).port(restServerConfig.getPort()).build();

    final Set<Object> resourceObjs = new HashSet<>();
    resourceObjs.add(new PingImpl());
    resourceObjs.add(new StreamMetadataResourceImpl(localController, controllerService, pravegaAuthManager, connectionFactory));

    final ControllerApplication controllerApplication = new ControllerApplication(resourceObjs);
    this.resourceConfig = ResourceConfig.forApplication(controllerApplication);
    this.resourceConfig.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);

    // Register the custom JSON parser.
    this.resourceConfig.register(new CustomObjectMapperProvider());

}
 
Example 5
Source File: BargeResourceTest.java    From barge with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure() {
  raftService = mock(Raft.class);


  ResourceConfig resourceConfig = ResourceConfig.forApplication(new Application() {
    @Override
    public Set<Object> getSingletons() {
      return Sets.newHashSet((Object) new BargeResource(raftService, CLUSTER_CONFIG));
    }
  });

  resourceConfig.register(Jackson.customJacksonProvider());

  return resourceConfig;
}
 
Example 6
Source File: JerseyServerBootstrap.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void setupServer(Application application) {
  ResourceConfig rc = ResourceConfig.forApplication(application);

  Properties serverProperties = readProperties();
  int port = Integer.parseInt(serverProperties.getProperty(PORT_PROPERTY));
  URI serverUri = UriBuilder.fromPath(ROOT_RESOURCE_PATH).scheme("http").host("localhost").port(port).build();

  final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(serverUri, rc);
  try {
    grizzlyServer.start();
  } catch (IOException e) {
    e.printStackTrace();
  }

  server = grizzlyServer;

}
 
Example 7
Source File: P2PRestAppTest.java    From tessera with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    Set services = new HashSet<>();
    services.add(mock(PartyInfoService.class));
    services.add(mock(TransactionManager.class));
    services.add(mock(Enclave.class));

    Client client = mock(Client.class);
    when(runtimeContext.getP2pClient()).thenReturn(client);
    when(runtimeContext.isRemoteKeyValidation()).thenReturn(true);


    MockServiceLocator serviceLocator = (MockServiceLocator) ServiceLocator.create();
    serviceLocator.setServices(services);

    p2PRestApp = new P2PRestApp();

    jersey =
        new JerseyTest() {
            @Override
            protected Application configure() {
                enable(TestProperties.LOG_TRAFFIC);
                enable(TestProperties.DUMP_ENTITY);
                ResourceConfig jerseyconfig = ResourceConfig.forApplication(p2PRestApp);
                return jerseyconfig;
            }
        };

    jersey.setUp();
}
 
Example 8
Source File: BargeJaxRsClientTest.java    From barge with Apache License 2.0 5 votes vote down vote up
@Override
protected Application configure() {
  ResourceConfig resourceConfig = ResourceConfig.forApplication(new Application() {
    @Override
    public Set<Object> getSingletons() {
      return Sets.newHashSet((Object) new DummyBargeServer());
    }
  });

  resourceConfig.register(Jackson.customJacksonProvider());

  return resourceConfig;
}
 
Example 9
Source File: JerseyServer.java    From tessera with Apache License 2.0 4 votes vote down vote up
@Override
public void start() throws Exception {
    LOGGER.debug("Starting {}", this);

    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();

    // https://jersey.github.io/documentation/latest/appendix-properties.html
    final Map<String, Object> initParams = new HashMap<>();
    initParams.put("jersey.config.server.application.name", application.getClass().getSimpleName());
    initParams.put("jersey.config.server.tracing.type", "ON_DEMAND");
    initParams.put("jersey.config.server.tracing.threshold", "SUMMARY");
    initParams.put("jersey.config.logging.verbosity", "PAYLOAD_ANY");
    initParams.put("jersey.config.beanValidation.enableOutputValidationErrorEntity.server", "true");
    initParams.put("jersey.config.server.monitoring.statistics.enabled", "true");
    initParams.put("jersey.config.server.monitoring.enabled", "true");
    initParams.put("jersey.config.server.monitoring.statistics.mbeans.enabled", "true");

    final ResourceConfig config = ResourceConfig.forApplication(application);

    config.addProperties(initParams).register(MetricsResource.class).register(LoggingFilter.class);

    if (serverConfig.getCrossDomainConfig() != null && !serverConfig.isUnixSocket()) {
        config.register(new CorsDomainResponseFilter(serverConfig.getCrossDomainConfig()));
    }

    LOGGER.debug("Building Server from {}", serverConfig);
    this.server = ServerUtils.buildWebServer(serverConfig);
    LOGGER.debug("Built Server from {}", serverConfig);

    ServletContextHandler context = new ServletContextHandler(server, "/");
    ServletContainer servletContainer = new ServletContainer(config);
    ServletHolder jerseyServlet = new ServletHolder(servletContainer);

    context.addServlet(jerseyServlet, "/*");

    LOGGER.info("Starting {}", uri);

    this.server.start();

    LOGGER.info("Started {}", uri);
    LOGGER.info("WADL {}/application.wadl", uri);

    if (influxConfig != null) {
        startInfluxMonitoring();
    }
}
 
Example 10
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 4 votes vote down vote up
private ResourceConfig getResourceConfig(Application app) {
    return ResourceConfig.forApplication(app);
}
 
Example 11
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 4 votes vote down vote up
private ResourceConfig getResourceConfig(Application app) {
    return ResourceConfig.forApplication(app);
}
 
Example 12
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 4 votes vote down vote up
private ResourceConfig getResourceConfig(Application app) {
    return ResourceConfig.forApplication(app);
}