javax.ws.rs.RuntimeType Java Examples

The following examples show how to use javax.ws.rs.RuntimeType. 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: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #2
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testChecksConstrainedToAnnotationDuringRegistration() {
    TestHandler handler = new TestHandler();
    LogUtils.getL7dLogger(ConfigurableImpl.class).addHandler(handler);

    try (ConfigurableImpl<Client> configurable 
            = new ConfigurableImpl<>(createClientProxy(), RuntimeType.CLIENT)) {
        Configuration config = configurable.getConfiguration();

        configurable.register(ContainerResponseFilterImpl.class);

        assertEquals(0, config.getInstances().size());

        for (String message : handler.messages) {
            if (message.startsWith("WARN") && message.contains("Null, empty or invalid contracts specified")) {
                return; // success
            }
        }
    }
    fail("did not log expected message");
}
 
Example #3
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidConstraintOnProvider() {
    TestHandler handler = new TestHandler();
    LogUtils.getL7dLogger(ConfigurableImpl.class).addHandler(handler);

    try (ConfigurableImpl<Client> configurable 
            = new ConfigurableImpl<>(createClientProxy(), RuntimeType.CLIENT)) {
        Configuration config = configurable.getConfiguration();

        configurable.register(ClientFilterConstrainedToServer.class);

        assertEquals(0, config.getInstances().size());

        for (String message : handler.messages) {
            if (message.startsWith("WARN") && message.contains("cannot be registered in ")) {
                return; // success
            }
        }
    }
    fail("did not log expected message");
}
 
Example #4
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @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() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    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 #5
Source File: FHIRJsonPatchProvider.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@Override
public JsonArray readFrom(Class<JsonArray> type, Type genericType, Annotation[] annotations, MediaType mediaType,
    MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    log.entering(this.getClass().getName(), "readFrom");
    try (JsonReader reader = JSON_READER_FACTORY.createReader(nonClosingInputStream(entityStream))) {
        return reader.readArray();
    } catch (JsonException e) {
        if (RuntimeType.SERVER.equals(runtimeType)) {
            String acceptHeader = httpHeaders.getFirst(HttpHeaders.ACCEPT);
            Response response = buildResponse(
                buildOperationOutcome(Collections.singletonList(
                    buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.INVALID, "FHIRProvider: " + e.getMessage(), null))), getMediaType(acceptHeader));
            throw new WebApplicationException(response);
        } else {
            throw new IOException("an error occurred during JSON Patch deserialization", e);
        }
    } finally {
        log.exiting(this.getClass().getName(), "readFrom");
    }
}
 
Example #6
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test 
public void testIsEnabledWithMultipleFeaturesOfSameType() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);

    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());

    Configuration config = configurable.getConfiguration();
    assertEquals(3, config.getInstances().size());
    assertFalse(config.isEnabled(DisablableFeature.class));

    DisablableFeature enabledFeature = new DisablableFeature();
    enabledFeature.enabled = true;

    featureContext.register(enabledFeature);
    assertEquals(4, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));

    featureContext.register(new DisablableFeature());
    assertEquals(5, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));
}
 
Example #7
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #8
Source File: FHIRJsonPatchProvider.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(JsonArray t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
    MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    log.entering(this.getClass().getName(), "writeTo");
    try (JsonWriter writer = JSON_WRITER_FACTORY.createWriter(nonClosingOutputStream(entityStream))) {
        writer.writeArray(t);
    } catch (JsonException e) {
        // log the error but don't throw because that seems to block to original IOException from bubbling for some reason
        log.log(Level.WARNING, "an error occurred during JSON Patch serialization", e);
        if (RuntimeType.SERVER.equals(runtimeType)) {
            String acceptHeader = (String) httpHeaders.getFirst(HttpHeaders.ACCEPT);
            Response response = buildResponse(
                buildOperationOutcome(Collections.singletonList(
                    buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.EXCEPTION, "FHIRProvider: " + e.getMessage(), null))), getMediaType(acceptHeader));
            throw new WebApplicationException(response);
        }
    } finally {
        log.exiting(this.getClass().getName(), "writeTo");
    }
}
 
Example #9
Source File: FHIRProvider.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(Resource t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, Object> httpHeaders,
        OutputStream entityStream) throws IOException, WebApplicationException {
    log.entering(this.getClass().getName(), "writeTo");
    try {
        FHIRGenerator.generator(getFormat(mediaType), isPretty(requestHeaders, uriInfo)).generate(t, entityStream);
    } catch (FHIRGeneratorException e) {
        // log the error but don't throw because that seems to block to original IOException from bubbling for some reason
        log.log(Level.WARNING, "an error occurred during resource serialization", e);
        if (RuntimeType.SERVER.equals(runtimeType)) {
            Response response =
                    buildResponse(
                            buildOperationOutcome(Collections.singletonList(
                                    buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.EXCEPTION,
                                            "FHIRProvider: " + e.getMessage(), e.getPath()))),
                            mediaType);
            throw new WebApplicationException(response);
        }
    } finally {
        log.exiting(this.getClass().getName(), "writeTo");
    }
}
 
Example #10
Source File: FHIRJsonProvider.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@Override
public JsonObject readFrom(Class<JsonObject> type, Type genericType, Annotation[] annotations, MediaType mediaType,
    MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    log.entering(this.getClass().getName(), "readFrom");
    try (JsonReader reader = JSON_READER_FACTORY.createReader(nonClosingInputStream(entityStream))) {
        return reader.readObject();
    } catch (JsonException e) {
        if (RuntimeType.SERVER.equals(runtimeType)) {
            String acceptHeader = httpHeaders.getFirst(HttpHeaders.ACCEPT);
            Response response = buildResponse(
                buildOperationOutcome(Collections.singletonList(
                    buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.INVALID, "FHIRProvider: " + e.getMessage(), null))), getMediaType(acceptHeader));
            throw new WebApplicationException(response);
        } else {
            throw new IOException("an error occurred during resource deserialization", e);
        }
    } finally {
        log.exiting(this.getClass().getName(), "readFrom");
    }
}
 
Example #11
Source File: CoreFeature.java    From krazo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {

    // RESTEasy seems to ignore @ConstrainedTo in some cases
    if (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER) {

        // https://issues.apache.org/jira/browse/CXF-7501
        // https://issues.apache.org/jira/browse/TOMEE-2122
        if (servletContext == null) {
            log.warning("The ServletContext wasn't injected into the JAX-RS Feature class");
        }

        Initializer.initialize(context, servletContext);
        return true;

    }
    return false;

}
 
Example #12
Source File: OzarkCoreFeature.java    From ozark with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {

    // RESTEasy seems to ignore @ConstrainedTo in some cases
    if (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER) {

        // https://issues.apache.org/jira/browse/CXF-7501
        // https://issues.apache.org/jira/browse/TOMEE-2122
        if (servletContext == null) {
            log.warning("The ServletContext wasn't injected into the JAX-RS Feature class");
        }

        OzarkInitializer.initialize(context, servletContext);
        return true;

    }
    return false;

}
 
Example #13
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidContract() {
    TestHandler handler = new TestHandler();
    LogUtils.getL7dLogger(ConfigurationImpl.class).addHandler(handler);

    ConfigurationImpl c = new ConfigurationImpl(RuntimeType.SERVER);
    ContainerResponseFilter filter = new ContainerResponseFilterImpl();
    assertFalse(c.register(filter,
                           Collections.<Class<?>, Integer>singletonMap(MessageBodyReader.class, 1000)));

    for (String message : handler.messages) {
        if (message.startsWith("WARN") && message.contains("does not implement specified contract")) {
            return; // success
        }
    }
    fail("did not log expected message");
}
 
Example #14
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @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() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    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 #15
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #16
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @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() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    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 #17
Source File: FHIRJsonProvider.java    From FHIR with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(JsonObject t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
    MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    log.entering(this.getClass().getName(), "writeTo");
    try (JsonWriter writer = JSON_WRITER_FACTORY.createWriter(nonClosingOutputStream(entityStream))) {
        writer.writeObject(t);
    } catch (JsonException e) {
        // log the error but don't throw because that seems to block to original IOException from bubbling for some reason
        log.log(Level.WARNING, "an error occurred during resource serialization", e);
        if (RuntimeType.SERVER.equals(runtimeType)) {
            Response response = buildResponse(
                buildOperationOutcome(Collections.singletonList(
                    buildOperationOutcomeIssue(IssueSeverity.FATAL, IssueType.EXCEPTION, "FHIRProvider: " + e.getMessage(), null))), mediaType);
            throw new WebApplicationException(response);
        }
    } finally {
        log.exiting(this.getClass().getName(), "writeTo");
    }
}
 
Example #18
Source File: ClientBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public ClientBuilder withConfig(Configuration cfg) {
    if (cfg.getRuntimeType() != RuntimeType.CLIENT) {
        throw new IllegalArgumentException();
    }
    configImpl = new ClientConfigurableImpl<>(this, cfg);
    return this;
}
 
Example #19
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubClassIsRegisteredOnConfigurable() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(ContainerResponseFilterSubClassImpl.class);
    Configuration config = configurable.getConfiguration();
    Map<Class<?>, Integer> contracts = config.getContracts(ContainerResponseFilter.class);
    assertEquals(1, contracts.size());
    assertTrue(contracts.containsKey(ContainerResponseFilter.class));
}
 
Example #20
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 {@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 #21
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientFilterContractsOnServerFeatureIsRejected() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(TestFilter.class);
    Configuration config = configurable.getConfiguration();
    Map<Class<?>, Integer> contracts = config.getContracts(TestFilter.class);
    assertFalse(contracts.containsKey(ClientRequestFilter.class));
    assertFalse(contracts.containsKey(ClientResponseFilter.class));
    assertTrue(contracts.containsKey(ContainerRequestFilter.class));
    assertTrue(contracts.containsKey(ContainerResponseFilter.class));
}
 
Example #22
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureDisabledClass() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(DisablableFeature.class);

    Configuration config = configurable.getConfiguration();
    assertFalse(config.isEnabled(DisablableFeature.class));
}
 
Example #23
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureDisabledInstance() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    Feature feature = new DisablableFeature();
    featureContext.register(feature);

    Configuration config = configurable.getConfiguration();
    assertFalse(config.isEnabled(feature));
}
 
Example #24
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientFilterWithNestedInterfacesIsAccepted() {
    try (ConfigurableImpl<Client> configurable 
            = new ConfigurableImpl<>(createClientProxy(), RuntimeType.CLIENT)) {
        Configuration config = configurable.getConfiguration();
        configurable.register(NestedInterfaceTestFilter.class);
        Map<Class<?>, Integer> contracts = config.getContracts(NestedInterfaceTestFilter.class);
        assertTrue(contracts.containsKey(ClientRequestFilter.class));
        assertTrue(contracts.containsKey(ClientResponseFilter.class));
    }
}
 
Example #25
Source File: ConfigurableImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean checkConstraints(Object provider) {
    Class<?> providerClass = provider.getClass();
    ConstrainedTo providerConstraint = providerClass.getAnnotation(ConstrainedTo.class);
    if (providerConstraint != null) {
        RuntimeType currentRuntime = config.getRuntimeType();
        RuntimeType providerRuntime = providerConstraint.value();
        // need to check (1) whether the registration is occurring in the specified runtime type
        // and (2) does the provider implement an invalid interface based on the constrained runtime type
        if (!providerRuntime.equals(currentRuntime)) {
            LOG.warning("Provider " + provider + " cannot be registered in this " + currentRuntime
                        + " runtime because it is constrained to " + providerRuntime + " runtimes.");
            return false;
        }
        
        Class<?>[] restrictedInterfaces = RuntimeType.CLIENT.equals(providerRuntime) ? RESTRICTED_CLASSES_IN_CLIENT
                                                                                     : RESTRICTED_CLASSES_IN_SERVER;
        for (Class<?> restrictedContract : restrictedInterfaces) {
            if (restrictedContract.isAssignableFrom(providerClass)) {
                RuntimeType opposite = RuntimeType.CLIENT.equals(providerRuntime) ? RuntimeType.SERVER
                                                                                  : RuntimeType.CLIENT;
                LOG.warning("Provider " + providerClass.getName() + " is invalid - it is constrained to "
                    + providerRuntime + " runtimes but implements a " + opposite + " interface ");
                return false;
            }
        }
    }
    return true;
}
 
Example #26
Source File: CxfRsHttpListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
private boolean isNotServerProvider(Class<?> clazz) {
    final ConstrainedTo ct = clazz.getAnnotation(ConstrainedTo.class);
    if (ct != null && ct.value() != RuntimeType.SERVER) {
        if (!FAIL_ON_CONSTRAINED_TO) {
            LOGGER.warning(clazz + " is not a SERVER provider, ignoring");
            return true;
        }
        throw new IllegalArgumentException(clazz + " is not a SERVER provider");
    }
    return false;
}
 
Example #27
Source File: ConfigurableImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public ConfigurableImpl(C configurable, Configuration config) {
    this.configurable = configurable;
    this.config = config instanceof ConfigurationImpl
        ? (ConfigurationImpl)config : new ConfigurationImpl(config);
    this.classLoader = Thread.currentThread().getContextClassLoader();
    restrictedContractTypes = RuntimeType.CLIENT.equals(config.getRuntimeType()) ? RESTRICTED_CLASSES_IN_CLIENT
        : RESTRICTED_CLASSES_IN_SERVER;
}
 
Example #28
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 {@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 #29
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 #30
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();
    }
}