当前位置: 首页>>代码示例>>Java>>正文


Java Feature类代码示例

本文整理汇总了Java中javax.ws.rs.core.Feature的典型用法代码示例。如果您正苦于以下问题:Java Feature类的具体用法?Java Feature怎么用?Java Feature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Feature类属于javax.ws.rs.core包,在下文中一共展示了Feature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRegister

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Test
public void testRegister() throws Exception {
	logger.info("start Register test");
	Client client = newClient();
	Map<Class<?>, Integer> myContracts = new HashMap<Class<?>, Integer>();
	myContracts.put(Feature.class, 1200);
	client.register(MyComponent.class, myContracts);
	Configuration configuration = client.getConfiguration();
	Set<Class<?>> classes = configuration.getClasses();
	for (Class<?> clazz : classes) {
		if (MyComponent.class.isAssignableFrom(clazz)) {
			Map<Class<?>, Integer> contracts = configuration.getContracts(clazz);
			int priority = contracts.get(Feature.class);
			assertTrue("Only standard: Feature, DynamicFeature, WriterInterceptor, "
					+ "ReaderInterceptor, ContainerResponseFilter, " + "ContainerRequestFilter, "
					+ "ClientResponseFilter, ClientRequestFilter, " + "ExceptionMapper, MessageBodyWriter, "
					+ "MessageBodyReader,ParamConverterProvider or implemented: InjectorFactory, "
					+ "StringParameterUnmarshaller, StringConverter, " + "ContextResolver, PostProcessInterceptor, "
					+ "PreProcessInterceptor, ClientExecutionInterceptor, ClientExceptionMapper"
					+ "can be registered as contracts. Registered priority", priority == 1200);
		}
	}
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:24,代码来源:ComponentTestCase.java

示例2: registerJerseyJsonFeature

import javax.ws.rs.core.Feature; //导入依赖的package包/类
/**
 * Register a Jersey JSON provider feature only if another JSON provider is not already registered, checking
 * {@link #JERSEY_JSON_PROVIDER_PROPERTY} property value.
 * @param context Feature context
 * @param feature Feature to register
 * @param featureName Feature name to register
 * @return <code>true</code> if feature was registered, <code>false</code> otherwise
 */
private static boolean registerJerseyJsonFeature(FeatureContext context, Class<? extends Feature> feature,
		String featureName) {
	final Configuration config = context.getConfiguration();

	final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
			JERSEY_JSON_PROVIDER_PROPERTY, featureName, String.class);
	if (!featureName.equalsIgnoreCase(jsonFeature)) {
		// Other JSON providers registered
		return false;
	}
	// Disable other JSON providers
	context.property(
			PropertiesHelper.getPropertyNameForRuntime(JERSEY_JSON_PROVIDER_PROPERTY, config.getRuntimeType()),
			featureName);
	// Register
	if (!config.isRegistered(feature)) {
		context.register(feature);
	}
	return true;
}
 
开发者ID:holon-platform,项目名称:holon-json,代码行数:29,代码来源:GsonAutoDiscoverable.java

示例3: TestChain

import javax.ws.rs.core.Feature; //导入依赖的package包/类
public TestChain(TestServiceRunnerBase serviceRunner) {
    this.actions = ImmutableList.of();
    this.serviceLocator = new ServiceLocatorHolder();

    Feature lifecycleListener = new Feature() {
        @Inject
        public void setServiceLocator(ServiceLocator s) {
            serviceLocator.set(s);
        }

        @Override
        public boolean configure(FeatureContext context) {
            return false;
        }
    };
    this.serviceRunner = serviceRunner
            .serviceConfig(serviceRunner.getServiceConfig()
                    .registerInstance(lifecycleListener)
            );
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:21,代码来源:TestChain.java

示例4: addFeature

import javax.ws.rs.core.Feature; //导入依赖的package包/类
public synchronized void addFeature(ApplicationKey application,
        Feature feature) {
    if (application == null || feature == null) {
        throw new RuntimeException(
                "Unable to add feature for " + application);
    }

    List<Feature> list;

    if (features.containsKey(application)) {
        list = features.get(application);
    } else {
        list = new ArrayList<>();
        features.put(application, list);
    }

    list.add(feature);
}
 
开发者ID:servicecatalog,项目名称:service-tools,代码行数:19,代码来源:ClientManager.java

示例5: createConfig

import javax.ws.rs.core.Feature; //导入依赖的package包/类
protected ClientConfig createConfig(Set<Feature> features) {
    ClientConfig config = new ClientConfig();
    config.property(ClientProperties.FOLLOW_REDIRECTS, followRedirects);
    config.property(ClientProperties.READ_TIMEOUT, readTimeoutMs);
    config.property(ClientProperties.CONNECT_TIMEOUT, connectTimeoutMs);
    config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, asyncThreadPoolSize);

    features.forEach(f -> config.register(f));

    if (compression) {
        config.register(new EncodingFeature(GZipEncoder.class));
    }

    configRequestLogging(config);

    return config;
}
 
开发者ID:bootique,项目名称:bootique-jersey-client,代码行数:18,代码来源:HttpClientFactoryFactory.java

示例6: testDefaultServiceReferencePropertiesAreAvailableInFeatures

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Test
public void testDefaultServiceReferencePropertiesAreAvailableInFeatures() {
    AtomicBoolean executed = new AtomicBoolean();
    AtomicReference<Object> propertyvalue = new AtomicReference<>();

    registerExtension(
        Feature.class, featureContext -> {
            executed.set(true);

            Map<String, Object> properties =
                (Map<String, Object>)
                    featureContext.getConfiguration().getProperty(
                        "osgi.jaxrs.application.serviceProperties");
            propertyvalue.set(properties.get(JAX_RS_NAME));

            return false;
        }, "Feature", JAX_RS_APPLICATION_SELECT,
        "("+ JAX_RS_NAME + "=" + JAX_RS_DEFAULT_APPLICATION + ")");

    assertTrue(executed.get());
    assertEquals(JAX_RS_DEFAULT_APPLICATION, propertyvalue.get());
}
 
开发者ID:apache,项目名称:aries-jax-rs-whiteboard,代码行数:23,代码来源:JaxrsTest.java

示例7: testErroredExtension

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Test
public void testErroredExtension() {
    registerApplication(new TestApplication());

    ServiceRegistration<Feature> serviceRegistration = registerExtension(
        Feature.class,
        context -> {
            throw new RuntimeException();
        },
        "ErrorFeature",
        JAX_RS_APPLICATION_SELECT,
        "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");

    RuntimeDTO runtimeDTO = _runtime.getRuntimeDTO();

    assertEquals(1, runtimeDTO.failedExtensionDTOs.length);
    assertEquals(
        serviceRegistration.getReference().getProperty("service.id"),
        runtimeDTO.failedExtensionDTOs[0].serviceId);
    assertEquals(
        DTOConstants.FAILURE_REASON_UNKNOWN,
        runtimeDTO.failedExtensionDTOs[0].failureReason);
}
 
开发者ID:apache,项目名称:aries-jax-rs-whiteboard,代码行数:24,代码来源:JaxrsTest.java

示例8: testFeatureExtension

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Test
public void testFeatureExtension() {
    WebTarget webTarget = createDefaultTarget().path("/test-application");

    registerApplication(new TestApplication());

    registerExtension(
        Feature.class,
        context -> {
            context.register(new TestFilter());

            return true;
        },
        "Feature",
        JAX_RS_APPLICATION_SELECT,
        "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");

    Response response = webTarget.request().get();

    assertEquals("Hello application", response.readEntity(String.class));

    assertEquals("true", response.getHeaders().getFirst("Filtered"));
}
 
开发者ID:apache,项目名称:aries-jax-rs-whiteboard,代码行数:24,代码来源:JaxrsTest.java

示例9: createResourceConfig

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Singleton
@Provides
private ResourceConfig createResourceConfig(Injector injector,
                                            Set<Feature> features,
                                            Set<DynamicFeature> dynamicFeatures,
                                            @JerseyResource Set<Object> resources, Set<Package> packages,
                                            @JerseyResource Map<String, Object> properties) {

    ResourceConfig config = new ResourceConfig();

    packages.forEach(p -> config.packages(true, p.getName()));
    resources.forEach(r -> config.register(r));

    features.forEach(f -> config.register(f));
    dynamicFeatures.forEach(df -> config.register(df));

    config.addProperties(properties);

    // TODO: make this pluggable?
    config.register(ResourceModelDebugger.class);

    // register Guice Injector as a service in Jersey HK2, and GuiceBridgeFeature as a
    GuiceBridgeFeature.register(config, injector);

    return config;
}
 
开发者ID:bootique,项目名称:bootique-jersey,代码行数:27,代码来源:JerseyModule.java

示例10: checkAdminGuiceFeature

import javax.ws.rs.core.Feature; //导入依赖的package包/类
private void checkAdminGuiceFeature(final Environment environment, final JerseyEnvironment jerseyEnvironment)
{
    try
    {
        Feature feature = new Feature()
        {
            @Override
            public boolean configure(FeatureContext context)
            {
                for ( Object obj : environment.jersey().getResourceConfig().getSingletons() )
                {
                    if ( obj instanceof InternalFeatureRegistrations )
                    {
                        ((InternalFeatureRegistrations)obj).apply(context);
                    }
                }
                return true;
            }
        };
        jerseyEnvironment.register(feature);
    }
    catch ( Exception ignore )
    {
        // ignore - GuiceBundle not added
    }
}
 
开发者ID:soabase,项目名称:soabase,代码行数:27,代码来源:SoaBundle.java

示例11: configureOAuth1

import javax.ws.rs.core.Feature; //导入依赖的package包/类
public static AccessToken configureOAuth1(
  String consumerKey,
  String consumerSecret,
  String token,
  String tokenSecret,
  ClientBuilder clientBuilder
) {
  ConsumerCredentials consumerCredentials = new ConsumerCredentials(consumerKey, consumerSecret);

  AccessToken accessToken = new AccessToken(token, tokenSecret);
  Feature feature = OAuth1ClientSupport.builder(consumerCredentials)
      .feature()
      .accessToken(accessToken)
      .build();
  clientBuilder.register(feature);

  return accessToken;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:JerseyClientUtil.java

示例12: configure

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Override
public Application configure() {

	EntityResolver mockResolver = mock(EntityResolver.class);
	DataChannel mockChannel = mock(DataChannel.class);
	when(mockChannel.getEntityResolver()).thenReturn(mockResolver);

	ServerRuntime runtime = mock(ServerRuntime.class);
	when(runtime.getChannel()).thenReturn(mockChannel);

	Feature lrFeature = LinkRestBuilder.build(runtime);

	Feature testFeature = new Feature() {

		@Override
		public boolean configure(FeatureContext context) {
			context.register(ExceptionResource.class);
			return true;
		}
	};

	return new ResourceConfig().register(testFeature).register(lrFeature);
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:24,代码来源:GET_ExceptionIT.java

示例13: configure

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Override
public Application configure() {

    Feature lrFeature = new LinkRestBuilder().adapter(new LinkRestAdapter() {

        @Override
        public void contributeToRuntime(Binder binder) {
            binder.bind(SelectProcessorFactory.class).toProvider(PojoSelectProcessorFactoryProvider.class);
            binder.bind(PojoFetchStage.class).to(PojoFetchStage.class);
            binder.bind(PojoDB.class).toInstance(pojoDB);
        }

        @Override
        public void contributeToJaxRs(Collection<Feature> features) {
            // nothing to contribute...
        }
    }).build();

    Feature unitFeature = context -> {
        doAddResources(context);
        return true;
    };

    return new ResourceConfig().register(unitFeature).register(lrFeature);
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:26,代码来源:JerseyTestOnPojo.java

示例14: configure

import javax.ws.rs.core.Feature; //导入依赖的package包/类
@Override
public Application configure() {

	EntityResolver mockResolver = mock(EntityResolver.class);
	DataChannel mockChannel = mock(DataChannel.class);
	when(mockChannel.getEntityResolver()).thenReturn(mockResolver);

	ServerRuntime runtime = mock(ServerRuntime.class);
	when(runtime.getChannel()).thenReturn(mockChannel);

	Feature lrFeature = LinkRestBuilder.build(runtime);

	Feature feature = new Feature() {

		@Override
		public boolean configure(FeatureContext context) {
			context.register(SimpleResponseResource.class);
			return true;
		}
	};

	return new ResourceConfig().register(feature).register(lrFeature);
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:24,代码来源:GET_SimpleResponseIT.java

示例15: UriTemplateApplication

import javax.ws.rs.core.Feature; //导入依赖的package包/类
/**
 * Create a new UriTemplateApplication.
 * 
 */
public UriTemplateApplication()
{
   registerClasses(UriTemplateResource.class);
   registerClasses(SchemaResource.class);
   register(new Feature()
   {

      @Override
      public boolean configure(final FeatureContext context)
      {
         final String disableMoxy = CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.'
               + context.getConfiguration().getRuntimeType().name().toLowerCase();
         context.property(disableMoxy, true);

         context.register(JacksonJaxbJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
         return true;
      }

   });
}
 
开发者ID:damnhandy,项目名称:Handy-URI-Templates-WebApp,代码行数:25,代码来源:UriTemplateApplication.java


注:本文中的javax.ws.rs.core.Feature类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。