javax.ws.rs.core.Configuration源码实例Demo

类javax.ws.rs.core.Configuration源码实例Demo

下面列出了javax.ws.rs.core.Configuration 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: crnk-framework   文件: CrnkFeatureTest.java
private void testSecurityRegistration(boolean enabled) {
	CrnkFeature feature = new CrnkFeature();
	feature.setSecurityEnabled(enabled);
	feature.securityContext = Mockito.mock(SecurityContext.class);

	FeatureContext context = Mockito.mock(FeatureContext.class);
	Mockito.when(context.getConfiguration()).thenReturn(Mockito.mock(Configuration.class));

	feature.configure(context);

	CrnkBoot boot = feature.getBoot();
	if (enabled) {
		SecurityProvider securityProvider = boot.getModuleRegistry().getSecurityProvider();
		Assert.assertNotNull(securityProvider);
	} else {
		Assert.assertEquals(0, boot.getModuleRegistry().getSecurityProviders().size());
	}
}
 
源代码2 项目: 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");
}
 
源代码3 项目: datacollector   文件: GrizzlyClientCustomizer.java
@Override
public AsyncHttpClientConfig.Builder customize(
    Client client, Configuration config, AsyncHttpClientConfig.Builder configBuilder
) {
  if (useProxy && !StringUtils.isEmpty(username)) {
    Realm realm = new Realm.RealmBuilder().setScheme(Realm.AuthScheme.BASIC)
        .setUsePreemptiveAuth(true)
        .setTargetProxy(true)
        .setPrincipal(username)
        .setPassword(password)
        .build();

    configBuilder.setRealm(realm);
  }
  return configBuilder;
}
 
源代码4 项目: dremio-oss   文件: DACJacksonJaxbJsonFeature.java
@Override
public boolean configure(FeatureContext context) {
  final Configuration config = context.getConfiguration();

  final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
    InternalProperties.JSON_FEATURE, JSON_FEATURE_CLASSNAME, String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE_CLASSNAME.equalsIgnoreCase(jsonFeature)) {
      LOGGER.error("Another JSON provider has been registered: {}", jsonFeature);
      return false;
    }

    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()),
      JSON_FEATURE_CLASSNAME);

  context.register(DACJacksonJaxbJsonProvider.class);

  return true;
}
 
源代码5 项目: dremio-oss   文件: TestResourcesFeature.java
@Override
public boolean configure(FeatureContext context) {
  Configuration configuration = context.getConfiguration();
  Boolean enabled = PropertyHelper.getProperty(configuration, RestServerV2.TEST_API_ENABLE);

  // Default is not enabled
  if (enabled == null || !enabled) {
    return false;
  }

  for (Class<?> resource : scanResult.getAnnotatedClasses(RestResourceUsedForTesting.class)) {
    context.register(resource);
  }

  return true;
}
 
源代码6 项目: dremio-oss   文件: DACAuthFilterFeature.java
@Override
public boolean configure(FeatureContext context) {
  final Configuration configuration = context.getConfiguration();

  Boolean disabled = PropertyHelper.getProperty(configuration, RestServerV2.DAC_AUTH_FILTER_DISABLE);
  // Default is not disabled
  if (disabled != null && disabled) {
    return false;
  }

  context.register(DACAuthFilter.class);
  if (!configuration.isRegistered(RolesAllowedDynamicFeature.class)) {
    context.register(RolesAllowedDynamicFeature.class);
  }
  return true;
}
 
源代码7 项目: parsec-libraries   文件: ParsecMoxyFeature.java
@Override
public boolean configure(FeatureContext context) {
    final Configuration config = context.getConfiguration();

    if (CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
            CommonProperties.MOXY_JSON_FEATURE_DISABLE, Boolean.FALSE, Boolean.class)) {
        return false;
    }

    final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
            InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
        return false;
    }

    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE,
            config.getRuntimeType()), JSON_FEATURE);

    final int workerPriority = Priorities.USER + 3000;
    context.register(ParsecMoxyProvider.class, workerPriority);

    return true;
}
 
@Override
public void configure(FeatureContext context) {
    final int priorityInc = 3000;

    // Jersey MOXY provider have higher priority(7000), so we need set higher than it
    int priority = Priorities.USER + priorityInc;
    Configuration config = context.getConfiguration();

    if (!config.isRegistered(ParsecValidationExceptionMapper.class)) {
        context.register(ParsecValidationExceptionMapper.class, priority);
    }
    if (!config.isRegistered(ValidationConfigurationContextResolver.class)) {
        context.register(ValidationConfigurationContextResolver.class, priority);
    }
    if (!config.isRegistered(ParsecMoxyFeature.class)) {
        context.register(ParsecMoxyFeature.class, priority);
    }
    if (!config.isRegistered(JaxbExceptionMapper.class)) {
        context.register(JaxbExceptionMapper.class, priority);
    }
}
 
源代码9 项目: ameba   文件: SysFilteringFeature.java
/**
 * {@inheritDoc}
 */
@Override
public boolean configure(FeatureContext context) {
    Configuration configuration = context.getConfiguration();
    if (!configuration.isRegistered(UriConnegFilter.class)) {
        context.register(UriConnegFilter.class, Priorities.AUTHENTICATION - 100);
    }

    if (!context.getConfiguration().isRegistered(DownloadEntityFilter.class)) {
        context.register(DownloadEntityFilter.class);
    }

    if (!configuration.isRegistered(LoadBalancerRequestFilter.class)) {
        context.register(LoadBalancerRequestFilter.class);
    }
    return true;
}
 
源代码10 项目: cxf   文件: ClientBuilderImpl.java
@Override
public ClientBuilder withConfig(Configuration cfg) {
    if (cfg.getRuntimeType() != RuntimeType.CLIENT) {
        throw new IllegalArgumentException();
    }
    configImpl = new ClientConfigurableImpl<>(this, cfg);
    return this;
}
 
@Before
public final void initServerAndClient() throws Exception {
    HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
    HttpJerseyRouterBuilder routerBuilder = new HttpJerseyRouterBuilder();
    configureBuilders(serverBuilder, routerBuilder);
    DefaultJerseyStreamingHttpRouter router = routerBuilder.from(application());
    final Configuration config = router.configuration();

    streamingJsonEnabled = getValue(config.getProperties(), config.getRuntimeType(), JSON_FEATURE, "",
            String.class).toLowerCase().contains("servicetalk");

    HttpServerBuilder httpServerBuilder = serverBuilder
            .ioExecutor(SERVER_CTX.ioExecutor())
            .bufferAllocator(SERVER_CTX.bufferAllocator());

    switch (api) {
        case ASYNC_AGGREGATED:
            serverContext = buildRouter(httpServerBuilder, toAggregated(router));
            break;
        case ASYNC_STREAMING:
            serverContext = buildRouter(httpServerBuilder, router);
            break;
        case BLOCKING_AGGREGATED:
            serverContext = buildRouter(httpServerBuilder, toBlocking(router));
            break;
        case BLOCKING_STREAMING:
            serverContext = buildRouter(httpServerBuilder, toBlockingStreaming(router));
            break;
        default:
            throw new IllegalArgumentException(api.name());
    }
    final HostAndPort hostAndPort = serverHostAndPort(serverContext);
    httpClient = HttpClients.forSingleAddress(hostAndPort).buildStreaming();
    hostHeader = hostHeader(hostAndPort);
}
 
源代码12 项目: portals-pluto   文件: ViewEnginesProducer.java
@ApplicationScoped
@Produces
@ViewEngines
public List<ViewEngine> getViewEngines(BeanManager beanManager, PortletContext portletContext,
	Configuration configuration) {

	List<ViewEngine> viewEngines = BeanUtil.getBeanInstances(beanManager, ViewEngine.class);

	viewEngines.add(new ViewEngineJspImpl(configuration, portletContext));

	Collections.sort(viewEngines, new DescendingPriorityComparator(ViewEngine.PRIORITY_APPLICATION));

	return viewEngines;
}
 
源代码13 项目: cxf   文件: ConfigurationImplTest.java
@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));
}
 
源代码14 项目: agrest   文件: AgRuntime.java
/**
 * Returns a service of a specified type present in Agrest container that
 * is stored in JAX RS Configuration.
 */
public static <T> T service(Class<T> type, Configuration config) {

    if (config == null) {
        throw new NullPointerException("Null config");
    }

    Injector injector = (Injector) config.getProperty(AGREST_CONTAINER_PROPERTY);
    if (injector == null) {
        throw new IllegalStateException(
                "Agrest is misconfigured. No injector found for property: " + AGREST_CONTAINER_PROPERTY);
    }

    return injector.getInstance(type);
}
 
源代码15 项目: cxf   文件: MicroProfileClientProxyImpl.java
public MicroProfileClientProxyImpl(URI baseURI, ClassLoader loader, ClassResourceInfo cri,
                                   boolean isRoot, boolean inheritHeaders, ExecutorService executorService,
                                   Configuration configuration, CDIInterceptorWrapper interceptorWrapper, 
                                   Object... varValues) {
    super(new LocalClientState(baseURI, configuration.getProperties()), loader, cri,
        isRoot, inheritHeaders, varValues);
    this.interceptorWrapper = interceptorWrapper;
    init(executorService, configuration);
}
 
源代码16 项目: krazo   文件: ViewEngineBaseTest.java
@Test
public void resolveViewCustomFolder() {
	ViewEngineContext ctx = EasyMock.createMock(ViewEngineContext.class);
	Configuration config = EasyMock.createMock(Configuration.class);
	expect(config.getProperty(eq(ViewEngine.VIEW_FOLDER))).andReturn("/somewhere/else");
	expect(ctx.getConfiguration()).andReturn(config);
	expect(ctx.getView()).andReturn("index.jsp");
	replay(ctx, config);
	assertThat(viewEngineBase.resolveView(ctx), is("/somewhere/else/index.jsp"));
	verify(ctx, config);
}
 
@Test
public void shouldNotFailInitializationIfContextInjectionHappened() {

  RedirectScopeManager redirectScopeManager = new RedirectScopeManager();
  setFieldValue(redirectScopeManager, "config", createDummyInstance(Configuration.class));
  setFieldValue(redirectScopeManager, "response", createDummyInstance(HttpServletResponse.class));
  redirectScopeManager.init();

}
 
@GET
@Path("/get-context-params")
public String  getContextParams(
        final @Context HttpHeaders httpheaders,
        final @Context Request request,
        final @Context UriInfo uriInfo,
        final @Context ResourceContext resourceContext,
        final @Context Providers providers,
        final @Context Application application,
        final @Context SecurityContext securityContext,
        final @Context Configuration configuration) throws Exception {
    
    return "This is a GET request with context parameters";
}
 
源代码19 项目: cxf   文件: ServerProviderFactory.java
private void doApplyDynamicFeatures(ClassResourceInfo cri) {
    Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos();
    for (OperationResourceInfo ori : oris) {
        String nameBinding = DEFAULT_FILTER_NAME_BINDING
            + ori.getClassResourceInfo().getServiceClass().getName()
            + "."
            + ori.getMethodToInvoke().toString();
        for (DynamicFeature feature : dynamicFeatures) {
            FeatureContext featureContext = createServerFeatureContext();
            feature.configure(new ResourceInfoImpl(ori), featureContext);
            Configuration cfg = featureContext.getConfiguration();
            for (Object provider : cfg.getInstances()) {
                Map<Class<?>, Integer> contracts = cfg.getContracts(provider.getClass());
                if (contracts != null && !contracts.isEmpty()) {
                    Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider);
                    registerUserProvider(new FilterProviderInfo<Object>(provider.getClass(),
                        providerCls,
                        provider,
                        getBus(),
                        Collections.singleton(nameBinding),
                        true,
                        contracts));
                    ori.addNameBindings(Collections.singletonList(nameBinding));
                }
            }
        }
    }
    Collection<ClassResourceInfo> subs = cri.getSubResources();
    for (ClassResourceInfo sub : subs) {
        if (sub != cri) {
            doApplyDynamicFeatures(sub);
        }
    }
}
 
源代码20 项目: uavstack   文件: FastJsonFeature.java
@Override
public boolean configure(final FeatureContext context) {
    try {
        final Configuration config = context.getConfiguration();

        final String jsonFeature = CommonProperties.getValue(
                config.getProperties()
                , config.getRuntimeType()
                , InternalProperties.JSON_FEATURE, JSON_FEATURE,
                String.class
        );

        // Other JSON providers registered.
        if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
            return false;
        }

        // Disable other JSON providers.
        context.property(
                PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType())
                , JSON_FEATURE);

        // Register FastJson.
        if (!config.isRegistered(FastJsonProvider.class)) {
            context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
        }
    } catch (NoSuchMethodError e) {
        // skip
    }

    return true;
}
 
@Test
public void shouldRegisterInstance() {
    TestClientRequestFilter instance = new TestClientRequestFilter();
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(instance);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(TestClientRequestFilter.class), TestClientRequestFilter.class + " should be registered");
    assertTrue(configuration.isRegistered(instance), TestClientRequestFilter.class + " should be registered");
}
 
@Test
public void shouldRegisterInstanceWithPriority() {
    Integer priority = 1000;
    TestClientRequestFilter instance = new TestClientRequestFilter();
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(instance, priority);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(TestClientRequestFilter.class), TestClientRequestFilter.class + " should be registered");
    assertTrue(configuration.isRegistered(instance), TestClientRequestFilter.class + " should be registered");
    Map<Class<?>, Integer> contracts = configuration.getContracts(TestClientRequestFilter.class);
    assertEquals(contracts.size(), 1, "There should be a registered contract for "+TestClientRequestFilter.class);
    assertEquals(contracts.get(ClientRequestFilter.class), priority, "The priority for "+TestClientRequestFilter.class+" should be 1000");
}
 
源代码23 项目: ameba   文件: TemplateHelper.java
/**
 * Get output encoding from configuration.
 *
 * @param configuration Configuration.
 * @param suffix        Template processor suffix of the
 *                      to configuration property {@link org.glassfish.jersey.server.mvc.MvcFeature#ENCODING}.
 * @return Encoding read from configuration properties or a default encoding if no encoding is configured.
 */
public static Charset getTemplateOutputEncoding(Configuration configuration, String suffix) {
    final String enc = PropertiesHelper.getValue(configuration.getProperties(), MvcFeature.ENCODING + suffix,
            String.class, null);
    if (enc == null) {
        return DEFAULT_ENCODING;
    } else {
        return Charset.forName(enc);
    }
}
 
源代码24 项目: cxf   文件: ConfigurationImplTest.java
@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));
}
 
源代码25 项目: tomee   文件: ThreadLocalContextManager.java
public static Object findThreadLocal(final Class<?> type) {
    if (Request.class.equals(type)) {
        return REQUEST;
    } else if (UriInfo.class.equals(type)) {
        return URI_INFO;
    } else if (HttpHeaders.class.equals(type)) {
        return HTTP_HEADERS;
    } else if (SecurityContext.class.equals(type)) {
        return SECURITY_CONTEXT;
    } else if (ContextResolver.class.equals(type)) {
        return CONTEXT_RESOLVER;
    } else if (Providers.class.equals(type)) {
        return PROVIDERS;
    } else if (ServletRequest.class.equals(type)) {
        return SERVLET_REQUEST;
    } else if (HttpServletRequest.class.equals(type)) {
        return HTTP_SERVLET_REQUEST;
    } else if (HttpServletResponse.class.equals(type)) {
        return HTTP_SERVLET_RESPONSE;
    } else if (ServletConfig.class.equals(type)) {
        return SERVLET_CONFIG;
    } else if (ServletContext.class.equals(type)) {
        return SERVLET_CONTEXT;
    } else if (ResourceInfo.class.equals(type)) {
        return RESOURCE_INFO;
    } else if (ResourceContext.class.equals(type)) {
        return RESOURCE_CONTEXT;
    } else if (Application.class.equals(type)) {
        return APPLICATION;
    } else if (Configuration.class.equals(type)) {
        return CONFIGURATION;
    }
    return null;
}
 
源代码26 项目: dremio-oss   文件: TableauMessageBodyGenerator.java
@Inject
public TableauMessageBodyGenerator(@Context Configuration configuration, NodeEndpoint endpoint, OptionManager optionManager) {
  this.endpoint = endpoint;
  this.masterNode = MoreObjects.firstNonNull(endpoint.getAddress(), "localhost");
  this.customizationEnabled = MoreObjects.firstNonNull((Boolean) configuration.getProperty(CUSTOMIZATION_ENABLED), false);
  this.optionManager = optionManager;

  // The EnumValidator lower-cases the enum for some reason, so we upper case it to match our enum values again.
  this.exportType = TableauExportType.valueOf(optionManager.getOption(TABLEAU_EXPORT_TYPE).toUpperCase(Locale.ROOT));
}
 
源代码27 项目: dremio-oss   文件: DACJacksonJaxbJsonFeature.java
protected ObjectMapper newObjectMapper(Configuration configuration, ScanResult scanResult, ConnectionReader connectionReader) {
  Boolean property = PropertyHelper.getProperty(configuration, RestServerV2.JSON_PRETTYPRINT_ENABLE);
  final boolean prettyPrint = property != null && property;

  ObjectMapper mapper = prettyPrint ? JSONUtil.prettyMapper() : JSONUtil.mapper();

  JSONUtil.registerStorageTypes(mapper, scanResult, connectionReader);
  mapper.addMixIn(VirtualDatasetUI.class, VirtualDatasetUIMixin.class);
  return mapper;
}
 
源代码28 项目: dremio-oss   文件: DACExceptionMapperFeature.java
@Override
public boolean configure(FeatureContext context) {
  Configuration configuration = context.getConfiguration();
  Boolean property = PropertyHelper.getProperty(configuration, RestServerV2.ERROR_STACKTRACE_ENABLE);

  // Default is false
  boolean includeStackTraces = property != null && property;

  context.register(new UserExceptionMapper(includeStackTraces));
  context.register(new GenericExceptionMapper(includeStackTraces));

  return true;
}
 
源代码29 项目: ameba   文件: JacksonFilteringFeature.java
/**
 * {@inheritDoc}
 */
@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();

    if (!config.isRegistered(JacksonFilteringFeature.Binder.class)) {
        context.register(new Binder());
        return true;
    }
    return false;
}
 
源代码30 项目: cxf   文件: ConfigurationImplTest.java
@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));
}