org.glassfish.jersey.server.ResourceConfig Java Examples

The following examples show how to use org.glassfish.jersey.server.ResourceConfig. 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: JerseyValidationTest.java    From parsec-libraries with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure() {
    //enable(TestProperties.LOG_TRAFFIC);
    //enable(TestProperties.DUMP_ENTITY);
    //
    // TODO: load web.xml directly
    // .property(
    //        "contextConfigLocation",
    //        "classpath:**/my-web-test-context.xml"
    //
    return new ResourceConfig(MyResource.class)
            .register(ParsecMoxyProvider.class)
            .register(JaxbExceptionMapper.class)
            .property(JaxbExceptionMapper.PROP_JAXB_DEFAULT_ERROR_CODE, JAXB_ERROR_CODE)
            .property(JaxbExceptionMapper.PROP_JAXB_DEFAULT_ERROR_MSG, JAXB_ERROR_MSG)
            .register(ValidationConfigurationContextResolver.class)
            .register(ParsecValidationExceptionMapper.class)
            .property(ParsecValidationExceptionMapper.PROP_VALIDATION_DEFAULT_ERROR_CODE, VALIDATION_ERROR_CODE)
            .property(ParsecValidationExceptionMapper.PROP_VALIDATION_DEFAULT_ERROR_MSG, VALIDATION_ERROR_MSG)
            .property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
            .register(new MoxyJsonConfig().setFormattedOutput(true)
                    .property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE).resolver());

}
 
Example #2
Source File: WeatherServer.java    From training with MIT License 6 votes vote down vote up
public static void start(int port) throws IOException {
	String baseUrl = "http://localhost:"+port+"/";
	System.out.println("Starting Weather App local testing server: " + baseUrl);
	System.out.println("Not for production use");

	final ResourceConfig resourceConfig = new ResourceConfig();
	resourceConfig.register(RestWeatherCollectorEndpoint.class);
	resourceConfig.register(RestWeatherQueryEndpoint.class);
	resourceConfig.register(GenericExceptionMapper.class);
	resourceConfig.register(new MyApplicationBinder());
	server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUrl), resourceConfig, false);

	HttpServerProbe probe = new HttpServerProbe.Adapter() {
		@Override
		public void onRequestReceiveEvent(HttpServerFilter filter, @SuppressWarnings("rawtypes") Connection connection, Request request) {
			System.out.println(request.getRequestURI());
		}
	};

	server.getServerConfiguration().getMonitoringConfig().getWebServerConfig().addProbes(probe);
	System.out.println(format("Weather Server started.\n url=%s\n", baseUrl));
	server.start();
}
 
Example #3
Source File: CubeResourceGeneralTest.java    From cubedb with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  //create ResourceConfig from Resource class
  ResourceConfig rc = new ResourceConfig();
  cube = new MultiCubeImpl(null);
  rc.registerInstances(new CubeResource(cube));
  rc.register(JsonIteratorConverter.class);

  //create the Grizzly server instance
  httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
  //start the server
  httpServer.start();

  //configure client with the base URI path
  Client client = ClientBuilder.newClient();
  client.register(JsonIteratorConverter.class);
  webTarget = client.target(baseUri);
}
 
Example #4
Source File: HttpProcessorIT.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure() {
  forceSet(TestProperties.CONTAINER_PORT, "0");
  return new ResourceConfig(
      Sets.newHashSet(
          TestGet.class,
          TestNull.class,
          TestGetZip.class,
          TestPut.class,
          HttpStageTestUtil.TestPostCustomType.class,
          TestXmlGet.class,
          TestHead.class,
          StreamTokenResetResource.class,
          Auth2Resource.class,
          Auth2ResourceOwnerWithIdResource.class,
          Auth2BasicResource.class,
          Auth2JWTResource.class,
          TestTimeEL.class
      )
  );
}
 
Example #5
Source File: Jersey2BackstopperConfigHelperTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test
public void setupJersey2ResourceConfigForBackstopperExceptionHandling_sets_up_expected_defaults() {
    // given
    ResourceConfig resourceConfigMock = mock(ResourceConfig.class);

    // when
    setupJersey2ResourceConfigForBackstopperExceptionHandling(resourceConfigMock, projectApiErrors, utils);

    // then
    ArgumentCaptor<Object> registerArgCaptor = ArgumentCaptor.forClass(Object.class);
    verify(resourceConfigMock, times(2)).register(registerArgCaptor.capture());
    List<Object> registeredResources = registerArgCaptor.getAllValues();
    assertThat(registeredResources).hasSize(2);
    assertThat(registeredResources.get(0)).isInstanceOf(ExceptionMapperFactoryOverrideBinder.class);
    assertThat(registeredResources.get(1)).isInstanceOf(Jersey2ApiExceptionHandler.class);
    Jersey2ApiExceptionHandler registeredHandler = (Jersey2ApiExceptionHandler) registeredResources.get(1);
    verifyDefaultJersey2ApiExceptionHandler(registeredHandler);
}
 
Example #6
Source File: GatewayRequestObjectHandlerIntTest.java    From jrestless with Apache License 2.0 6 votes vote down vote up
@Test
public void testProxyBasePathingWithDomainWithoutPathBasePath() {
	ResourceConfig config = new ResourceConfig();
	config.register(DynamicProxyBasePathFilter.class);
	GatewayRequestObjectHandlerImpl handlerWithProxyFilter = null;
	try {
		handlerWithProxyFilter = createAndStartHandler(config, testService);
		DefaultGatewayRequest request = new DefaultGatewayRequestBuilder()
				.httpMethod("GET")
				.resource("/a/{proxy+}")
				.pathParams(Collections.singletonMap("proxy", "uris"))
				.domain("api.example.com")
				.build();
		handlerWithProxyFilter.handleRequest(request, context);
		verify(testService).baseUri(URI.create("https://api.example.com/a/"));
		verify(testService).requestUri(URI.create("https://api.example.com/a/uris"));
	} finally {
		handlerWithProxyFilter.stop();
	}
}
 
Example #7
Source File: CoreModule.java    From onedev with MIT License 6 votes vote down vote up
private void configureRestServices() {
	bind(ResourceConfig.class).toProvider(ResourceConfigProvider.class).in(Singleton.class);
	bind(ServletContainer.class).to(DefaultServletContainer.class);
	
	contribute(FilterChainConfigurator.class, new FilterChainConfigurator() {

		@Override
		public void configure(FilterChainManager filterChainManager) {
			filterChainManager.createChain("/rest/**", "noSessionCreation, authcBasic");
		}
		
	});
	
	contribute(JerseyConfigurator.class, new JerseyConfigurator() {
		
		@Override
		public void configure(ResourceConfig resourceConfig) {
			resourceConfig.packages(RestConstants.class.getPackage().getName());
		}
		
	});
}
 
Example #8
Source File: RestUtils.java    From chipster with MIT License 6 votes vote down vote up
public static ResourceConfig getResourceConfig() {

		ResourceConfig rc = new ResourceConfig()
				/*
				 * Disable auto discovery so that we can decide what we want to register and
				 * what not. Don't register JacksonFeature, because it will register
				 * JacksonMappingExceptionMapper, which annoyingly swallows response's
				 * JsonMappingExceptions. Register directly the JacksonJaxbJsonProvider which is
				 * enough for the actual JSON conversion (see the code of JacksonFeature).
				 */
				.property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true).register(JacksonJaxbJsonProvider.class)
//				.register(JavaTimeObjectMapperProvider.class)
//				// register all exception mappers
//				.packages(NotFoundExceptionMapper.class.getPackage().getName())
//				// enable the RolesAllowed annotation
//				.register(RolesAllowedDynamicFeature.class)
				.register(JsonPrettyPrintQueryParamContainerResponseFilter.class);

		return rc;
	}
 
Example #9
Source File: MCRJerseyUtil.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the base URL of the mycore system.
 *
 * @param info the UriInfo
 *
 * @return base URL of the mycore system as string
 */
public static String getBaseURL(UriInfo info, Application app) {
    String baseURL = info.getBaseUri().toString();
    List<String> applicationPaths = MCRConfiguration2
        .getOrThrow("MCR.Jersey.Resource.ApplicationPaths", MCRConfiguration2::splitValue)
        .collect(Collectors.toList());
    for (String path : applicationPaths) {
        baseURL = removeAppPath(baseURL, path);
    }
    Optional<String> appPath = Optional.ofNullable(app)
        .map(a -> a instanceof ResourceConfig ? ((ResourceConfig) a).getApplication() : a)
        .map(Application::getClass)
        .map(c -> c.getAnnotation(ApplicationPath.class))
        .map(ApplicationPath::value)
        .map(s -> s.startsWith("/") ? s.substring(1) : s);
    if (appPath.isPresent()) {
        baseURL = removeAppPath(baseURL, appPath.get());
    }
    return baseURL;
}
 
Example #10
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 #11
Source File: ClientAndServerTest.java    From logbook with MIT License 5 votes vote down vote up
@Override
protected Application configure() {
    // jersey calls this method within the constructor before our fields are initialized... WTF
    this.client = mock(Sink.class);
    this.server = mock(Sink.class);

    return new ResourceConfig(TestWebService.class)
            .register(new LogbookServerFilter(
                    Logbook.builder()
                            // do not replace multi-part form bodies, which is the default
                            .requestFilter(replaceBody(stream()))
                            .sink(server)
                            .build()))
            .register(MultiPartFeature.class);
}
 
Example #12
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an application descriptor that defines
 * how the test container is configured.
 *
 * @param jaxrsApplication an application describing how to configure the
 *                         test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Application jaxrsApplication) throws TestContainerException {
    ResourceConfig config = getResourceConfig(jaxrsApplication);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #13
Source File: ServerMock.java    From javaee8-cookbook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        final ResourceConfig resourceConfig = new ResourceConfig(SseResource.class);

        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(CONTEXT, resourceConfig, false);
        server.start();

        System.out.println(String.format("Mock Server started at %s%s", CONTEXT, BASE_PATH));

        Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
        System.out.println(ex.getMessage());
    }
}
 
Example #14
Source File: TrellisHttpResourceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Override
protected Application configure() {

    initMocks(this);

    System.setProperty(WebSubHeaderFilter.CONFIG_HTTP_WEB_SUB_HUB, HUB);

    final ResourceConfig config = new ResourceConfig();
    config.register(new TrellisHttpResource(mockBundler, singletonMap(ACL, PreferAccessControl), null));
    config.register(new CacheControlFilter());
    config.register(new TrellisHttpFilter());
    config.register(new WebSubHeaderFilter());
    return config;
}
 
Example #15
Source File: AbstractApiControllerTest.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@Before
public void cleanState() {
    super.cleanState();

    try {
        try (ServerSocket sock = new ServerSocket(0)) {
            httpServerBaseUri = URI.create(String.format("http://%s:%d/", InetAddressUtils.formatInetAddress(InetAddress.getLoopbackAddress()), sock.getLocalPort()));
        }

        final ResourceConfig rc = new ResourceConfig()
            .registerInstances(Sets.newHashSet(
                new ApiController(factory),
                new ClusterCleanupController(cluster,factory),
                new ClusterRepairController(cluster,factory),
                new ClusterRollingRestartController(cluster,factory),
                new ClusterBackupController(cluster,factory),
                new ClusterRestoreController(cluster,factory),
                new ConfigController(cluster,factory),
                new LiveEndpointsController(cluster,factory),
                new NodeController(cluster,factory),
                new QaReportController(cluster, factory)
            ));
        httpServer = GrizzlyHttpServerFactory.createHttpServer(httpServerBaseUri, rc);
        httpServer.start();

    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #16
Source File: ServiceHttpClient.java    From ignite-book-code-samples with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    URI baseUri = UriBuilder.fromUri("http://localhost/").port(9988).build();
    // start the Ignite client
    Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG);
    IgniteServices services = ignite.services().withAsync();

    bankService = services.serviceProxy(BankService.NAME, BankService.class, /*not-sticky*/false);

    ResourceConfig config = new ResourceConfig(ServiceHttpClient.class);
    HttpServer server = JdkHttpServerFactory.createHttpServer(baseUri, config);
}
 
Example #17
Source File: RegistryTest.java    From TeaStore with Apache License 2.0 5 votes vote down vote up
/**
 * Setup the test by deploying an embedded tomcat and adding the rest endpoints.
 * @throws Throwable Throws uncaught throwables for test to fail.
 */
@Before
public void setup() throws Throwable {
	testTomcat = new Tomcat();
	testTomcat.setPort(0);
	testTomcat.setBaseDir(testWorkingDir);
	Context context = testTomcat.addWebapp(CONTEXT, testWorkingDir);
	ResourceConfig restServletConfig = new ResourceConfig();
	restServletConfig.register(RegistryREST.class);
	restServletConfig.register(Registry.class);
	ServletContainer restServlet = new ServletContainer(restServletConfig);
	testTomcat.addServlet(CONTEXT, "restServlet", restServlet);
	context.addServletMappingDecoded("/rest/*", "restServlet");
	testTomcat.start();
}
 
Example #18
Source File: UserResourceAuthenticatedTest.java    From dependency-track with Apache License 2.0 5 votes vote down vote up
@Override
protected DeploymentContext configureDeployment() {
    return ServletDeploymentContext.forServlet(new ServletContainer(
            new ResourceConfig(UserResource.class)
                    .register(AuthenticationFilter.class)))
            .build();
}
 
Example #19
Source File: CRUDClientServerTest.java    From TeaStore with Apache License 2.0 5 votes vote down vote up
/**
 * Setup the test by deploying an embedded tomcat and adding the rest endpoints.
 * @throws Throwable Throws uncaught throwables for test to fail.
 */
@Before
public void setup() throws Throwable {
	testTomcat = new Tomcat();
	testTomcat.setPort(0);
	testTomcat.setBaseDir(testWorkingDir);
	Context context = testTomcat.addWebapp(CONTEXT, testWorkingDir);
	ResourceConfig restServletConfig = new ResourceConfig();
	restServletConfig.register(TestEntityEndpoint.class);
	ServletContainer restServlet = new ServletContainer(restServletConfig);
	testTomcat.addServlet(CONTEXT, "restServlet", restServlet);
	context.addServletMappingDecoded("/rest/*", "restServlet");
	testTomcat.start();
}
 
Example #20
Source File: LinkFactoryResourceConfig.java    From rest-schemagen with Apache License 2.0 5 votes vote down vote up
public static void configureWithoutPlugins(ResourceConfig config) {
    config.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(RestJsonSchemaGeneratorFactory.class, Singleton.class).to(JsonSchemaGenerator.class).in(
                    Singleton.class);
            bind(BaseUriCreatorDefault.class).to(BaseUriCreator.class).in(Singleton.class);
            bindFactory(LinkFactoryContextFactory.class).to(LinkFactoryContext.class).in(RequestScoped.class).proxy(
                    true);
            bindFactory(LinkMetaFactoryFactory.class).to(LinkMetaFactory.class);
        }
    });

}
 
Example #21
Source File: TeamResourceTest.java    From dependency-track with Apache License 2.0 5 votes vote down vote up
@Override
protected DeploymentContext configureDeployment() {
    return ServletDeploymentContext.forServlet(new ServletContainer(
            new ResourceConfig(TeamResource.class)
                    .register(AuthenticationFilter.class)))
            .build();
}
 
Example #22
Source File: ShiroBundle.java    From dropwizard-shiro with Apache License 2.0 5 votes vote down vote up
@Override
public void run(T configuration, Environment environment) {
    ShiroConfiguration shiroConfig = narrow(configuration);
    ResourceConfig resourceConfig = environment.jersey().getResourceConfig();

    resourceConfig.register(new AuthorizationFilterFeature());
    resourceConfig.register(new SubjectFactory());
    resourceConfig.register(new AuthInjectionBinder());

    Filter shiroFilter = createFilter(configuration);
    environment.servlets()
        .addFilter("ShiroFilter", shiroFilter)
        .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, shiroConfig.filterUrlPattern());
}
 
Example #23
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 config = new ResourceConfig()
			.register(SnsFeature.class)
			.packages("com.jrestless.aws.examples");
	init(config);
	start();
}
 
Example #24
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an {@link Application} class.
 *
 * @param jaxrsApplicationClass an application describing how to configure the
 *                              test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Class<? extends Application> jaxrsApplicationClass) throws TestContainerException {
    ResourceConfig config = ResourceConfig.forApplicationClass(jaxrsApplicationClass);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #25
Source File: BooksEndpointInteractionTest.java    From Test-Driven-Java-Development-Second-Edition with MIT License 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    booksRepository = mock(BooksRepository.class);
    ResourceConfig resourceConfig = new MyApplication(new BooksEndpoint(booksRepository));
    server = GrizzlyHttpServerFactory.createHttpServer(FULL_PATH, resourceConfig);
    server.start();
}
 
Example #26
Source File: WeatherServer.java    From training with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try {
        System.out.println("Starting Weather App local testing server: " + BASE_URL);
        System.out.println("Not for production use");

        final ResourceConfig resourceConfig = new ResourceConfig();
        resourceConfig.register(RestWeatherCollectorEndpoint.class);
        resourceConfig.register(RestWeatherQueryEndpoint.class);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URL), resourceConfig, false);

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                server.shutdownNow();
            }
        }));

        HttpServerProbe probe = new HttpServerProbe.Adapter() {
            public void onRequestReceiveEvent(HttpServerFilter filter, Connection connection, Request request) {
                System.out.println(request.getRequestURI());
            }
        };

        server.getServerConfiguration().getMonitoringConfig().getWebServerConfig().addProbes(probe);
        System.out.println(format("Weather Server started.\n url=%s\n", BASE_URL));
        server.start();

        Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
        Logger.getLogger(WeatherServer.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
Example #27
Source File: MCRJerseyDefaultConfiguration.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #28
Source File: RequestMetricsContainerFilterTest.java    From cf-java-logging-support with Apache License 2.0 5 votes vote down vote up
@Override
protected Application configure() {
    ResourceConfig config = new ResourceConfig();
    config.register(TestResource.class);
    RequestMetricsFilterRegistry.registerContainerFilters(config);
    return config;

}
 
Example #29
Source File: ExecutionContainerModule.java    From flux with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the Jetty server instance for the Flux Execution API endpoint.
 * @return Jetty Server instance
 */
@Named("ExecutionAPIJettyServer")
@Provides
@Singleton
Server getExecutionAPIJettyServer(@Named("Execution.Node.Api.service.port") int port,
                         @Named("ExecutionAPIResourceConfig")ResourceConfig resourceConfig,
                         @Named("Execution.Node.Api.service.acceptors") int acceptorThreads,
                         @Named("Execution.Node.Api.service.selectors") int selectorThreads,
                         @Named("Execution.Node.Api.service.workers") int maxWorkerThreads,
                         ObjectMapper objectMapper, MetricRegistry metricRegistry) throws URISyntaxException, UnknownHostException {
    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(objectMapper);
    resourceConfig.register(provider);
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(maxWorkerThreads);
    Server server = new Server(threadPool);
    ServerConnector http = new ServerConnector(server, acceptorThreads, selectorThreads);
    http.setPort(port);
    server.addConnector(http);
    ServletContextHandler context = new ServletContextHandler(server, "/*");
    ServletHolder servlet = new ServletHolder(new ServletContainer(resourceConfig));
    context.addServlet(servlet, "/*");

    final InstrumentedHandler handler = new InstrumentedHandler(metricRegistry);
    handler.setHandler(context);
    server.setHandler(handler);

    server.setStopAtShutdown(true);
    return server;
}
 
Example #30
Source File: SimpleRequestHandlerIntTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
	ResourceConfig config = new ResourceConfig();
	testService = mock(TestService.class);
	Binder binder = new InstanceBinder.Builder().addInstance(testService, TestService.class).build();
	config.register(binder);
	config.register(TestResource.class);
	handler = new SimpleRequestHandlerImpl();
	handler.init(config);
	handler.start();
}