类javax.ws.rs.RuntimeType源码实例Demo

下面列出了怎么用javax.ws.rs.RuntimeType的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: FHIR   文件: FHIRJsonPatchProvider.java
@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");
    }
}
 
源代码2 项目: FHIR   文件: FHIRJsonPatchProvider.java
@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");
    }
}
 
源代码3 项目: FHIR   文件: FHIRProvider.java
@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");
    }
}
 
源代码4 项目: FHIR   文件: FHIRJsonProvider.java
@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");
    }
}
 
源代码5 项目: FHIR   文件: FHIRJsonProvider.java
@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");
    }
}
 
源代码6 项目: krazo   文件: CoreFeature.java
@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;

}
 
源代码7 项目: ozark   文件: OzarkCoreFeature.java
@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;

}
 
/**
 * 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();
    }
}
 
/**
 * 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();
    }
}
 
/**
 * 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();
    }
}
 
/**
 * 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();
    }
}
 
源代码12 项目: cxf   文件: ConfigurationImplTest.java
@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");
}
 
源代码13 项目: cxf   文件: ConfigurationImplTest.java
@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));
}
 
源代码14 项目: cxf   文件: ConfigurationImplTest.java
@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");
}
 
源代码15 项目: cxf   文件: ConfigurationImplTest.java
@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");
}
 
/**
 * 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();
    }
}
 
/**
 * 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();
    }
}
 
源代码18 项目: FHIR   文件: FHIRClientImpl.java
@Override
public WebTarget getWebTarget(String baseURL) throws Exception {
    ClientBuilder cb =
            ClientBuilder.newBuilder().register(new FHIRProvider(RuntimeType.CLIENT)).register(new FHIRJsonProvider(RuntimeType.CLIENT)).keyStore(getKeyStore(), getKeyStoreKeyPassword());

    KeyStore ts = getTrustStore();

    if (ts != null) {
        cb = cb.trustStore(ts);
    }
    Client client = cb.build();
    return client.target(baseURL);
}
 
源代码19 项目: FHIR   文件: ReadClaimTestMain.java
public static void main(String[] args) throws Exception {
    Client client = ClientBuilder.newBuilder()
            .register(new FHIRProvider(RuntimeType.CLIENT))
            .build();
    WebTarget target = client.target("http://fhirtest.uhn.ca/baseDstu2");
    Response response = target.path("Claim/14105").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
    Claim claim = response.readEntity(Claim.class);
    FHIRGenerator.generator( Format.JSON, false).generate(claim, System.out);
    System.out.println("");
    FHIRGenerator.generator( Format.XML, false).generate(claim, System.out);
    
}
 
源代码20 项目: FHIR   文件: UpdateTestMain.java
public static void main(String[] args) throws Exception {
    Client client = ClientBuilder.newBuilder()
            .register(new FHIRProvider(RuntimeType.CLIENT))
            .build();
    
    WebTarget target = client.target("http://localhost:9080/fhir-server/api/v4");
    Response response = target.path("Observation/14").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
    
    Observation observation = response.readEntity(Observation.class);
    
    FHIRGenerator.generator( Format.JSON, false).generate(observation, System.out);
    
            
    List <Component> newCompList = new ArrayList<Component>();
    int i = 0;
    for (Component component: observation.getComponent()) {
        // change first component only
        if ( i == 0 ) {
            component = component.toBuilder()
                    .value(Quantity.builder().value(Decimal.of(120)).unit(string("mmHg")).build()).build(); 
        } 
        newCompList.add(component);
        i++;
    }
    
    observation = observation.toBuilder().component(newCompList).build();
    
    Entity<Observation> observationEntity = Entity.entity(observation, FHIRMediaType.APPLICATION_FHIR_JSON);
    response = target.path("Observation/14").request().put(observationEntity);
    System.out.println(response.getStatusInfo().getReasonPhrase());
    System.out.println("location: " + response.getLocation());
}
 
源代码21 项目: FHIR   文件: FHIRProvider.java
@Override
public Resource readFrom(Class<Resource> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, String> httpHeaders,
        InputStream entityStream) throws IOException, WebApplicationException {
    log.entering(this.getClass().getName(), "readFrom");
    try {
        FHIRRequestContext requestContext = FHIRRequestContext.get();
        Format format = getFormat(mediaType);
        FHIRParser parser = FHIRParser.parser(format);
        if (parser.isPropertySupported(FHIRParser.PROPERTY_IGNORE_UNRECOGNIZED_ELEMENTS)) {
            parser.setProperty(FHIRParser.PROPERTY_IGNORE_UNRECOGNIZED_ELEMENTS,
                    HTTPHandlingPreference.LENIENT.equals(requestContext.getHandlingPreference()));
        }
        return parser.parse(entityStream);
    } catch (FHIRParserException 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(), e.getPath()))),
                            getMediaType(acceptHeader));
            throw new WebApplicationException(response);
        } else {
            throw new IOException("an error occurred during resource deserialization", e);
        }
    } finally {
        log.exiting(this.getClass().getName(), "readFrom");
    }
}
 
源代码22 项目: FHIR   文件: FHIRApplication.java
@Override
public Set<Object> getSingletons() {
    log.entering(this.getClass().getName(), "getSingletons");
    try {
        if (singletons == null) {
            singletons = new HashSet<Object>();
            singletons.add(new FHIRProvider(RuntimeType.SERVER));
            singletons.add(new FHIRJsonProvider(RuntimeType.SERVER));
            singletons.add(new FHIRJsonPatchProvider(RuntimeType.SERVER));
        }
        return singletons;
    } finally {
        log.exiting(this.getClass().getName(), "getSingletons");
    }
}
 
源代码23 项目: quarkus   文件: RestClientRecorder.java
public void initializeResteasyProviderFactory(RuntimeValue<InjectorFactory> ifc, boolean useBuiltIn,
        Set<String> providersToRegister,
        Set<String> contributedProviders) {
    ResteasyProviderFactory clientProviderFactory = new ResteasyProviderFactoryImpl(RuntimeType.CLIENT,
            new ResteasyProviderFactoryImpl()) {
        @Override
        public RuntimeType getRuntimeType() {
            return RuntimeType.CLIENT;
        }

        @Override
        public InjectorFactory getInjectorFactory() {
            return ifc.getValue();
        }
    };

    if (useBuiltIn) {
        RegisterBuiltin.register(clientProviderFactory);
        registerProviders(clientProviderFactory, contributedProviders, false);
    } else {
        providersToRegister.removeAll(contributedProviders);
        registerProviders(clientProviderFactory, providersToRegister, true);
        registerProviders(clientProviderFactory, contributedProviders, false);
    }

    RestClientBuilderImpl.setProviderFactory(clientProviderFactory);
    providerFactory = clientProviderFactory;
}
 
/**
 * 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();
    }
}
 
/**
 * 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();
    }
}
 
源代码26 项目: seed   文件: Jersey2Plugin.java
private Set<Class<?>> filterClasses(Collection<Class<?>> classes) {
    Set<Class<?>> result = new HashSet<>();

    if (classes != null) {
        for (Class<?> aClass : classes) {
            ConstrainedTo annotation = aClass.getAnnotation(ConstrainedTo.class);
            if (annotation == null || annotation.value() == RuntimeType.SERVER) {
                result.add(aClass);
            }
        }
    }

    return result;
}
 
/**
 * 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();
    }
}
 
/**
 * 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();
    }
}
 
源代码29 项目: cxf   文件: ConfigurableImpl.java
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;
}
 
源代码30 项目: cxf   文件: ConfigurableImpl.java
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;
}
 
 类所在包
 类方法
 同包方法