Java源码示例:org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters

示例1
@Bean
ServletRegistrationBean<HttpServlet30Dispatcher> keycloakJaxRsApplication(
		KeycloakServerProperties keycloakServerProperties, DataSource dataSource) throws Exception {

	mockJndiEnvironment(dataSource);
	EmbeddedKeycloakApplication.keycloakServerProperties = keycloakServerProperties;

	ServletRegistrationBean<HttpServlet30Dispatcher> servlet = new ServletRegistrationBean<>(
			new HttpServlet30Dispatcher());
	servlet.addInitParameter("javax.ws.rs.Application", EmbeddedKeycloakApplication.class.getName());
	servlet.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX,
			keycloakServerProperties.getContextPath());
	servlet.addInitParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, "true");
	servlet.addUrlMappings(keycloakServerProperties.getContextPath() + "/*");
	servlet.setLoadOnStartup(1);
	servlet.setAsyncSupported(true);

	return servlet;
}
 
示例2
@Bean
ServletRegistrationBean<HttpServlet30Dispatcher> keycloakJaxRsApplication(KeycloakServerProperties keycloakServerProperties, DataSource dataSource) throws Exception {

    mockJndiEnvironment(dataSource);
    EmbeddedKeycloakApplication.keycloakServerProperties = keycloakServerProperties;

    ServletRegistrationBean<HttpServlet30Dispatcher> servlet = new ServletRegistrationBean<>(new HttpServlet30Dispatcher());
    servlet.addInitParameter("javax.ws.rs.Application", EmbeddedKeycloakApplication.class.getName());
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX, keycloakServerProperties.getContextPath());
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, "true");
    servlet.addUrlMappings(keycloakServerProperties.getContextPath() + "/*");
    servlet.setLoadOnStartup(1);
    servlet.setAsyncSupported(true);

    return servlet;
}
 
示例3
@Bean
ServletRegistrationBean<HttpServlet30Dispatcher> keycloakJaxRsApplication(
		KeycloakServerProperties keycloakServerProperties, DataSource dataSource) throws Exception {

	mockJndiEnvironment(dataSource);
	EmbeddedKeycloakApplication.keycloakServerProperties = keycloakServerProperties;

	ServletRegistrationBean<HttpServlet30Dispatcher> servlet = new ServletRegistrationBean<>(
			new HttpServlet30Dispatcher());
	servlet.addInitParameter("javax.ws.rs.Application", EmbeddedKeycloakApplication.class.getName());
	servlet.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX,
			keycloakServerProperties.getContextPath());
	servlet.addInitParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, "true");
	servlet.addUrlMappings(keycloakServerProperties.getContextPath() + "/*");
	servlet.setLoadOnStartup(1);
	servlet.setAsyncSupported(true);

	return servlet;
}
 
示例4
@Bean
ServletRegistrationBean<HttpServlet30Dispatcher> keycloakJaxRsApplication(SpringBootConfigProvider configProvider) {

    //FIXME: hack to propagate Spring Boot Properties to Keycloak Application
    EmbeddedKeycloakApplication.keycloakProperties = keycloakProperties;

    //FIXME: hack to propagate Spring Boot Properties to Keycloak Application
    EmbeddedKeycloakApplication.customProperties = customProperties;

    //FIXME: hack to propagate Spring Boot ConfigProvider to Keycloak Application
    EmbeddedKeycloakApplication.configProvider = configProvider;

    ServletRegistrationBean<HttpServlet30Dispatcher> servlet = new ServletRegistrationBean<>(new HttpServlet30Dispatcher());
    servlet.addInitParameter("javax.ws.rs.Application", EmbeddedKeycloakApplication.class.getName());
    String keycloakContextPath = customProperties.getServer().getContextPath();
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX, keycloakContextPath);
    servlet.addInitParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, "true");
    servlet.addUrlMappings(keycloakContextPath + "/*");
    servlet.setLoadOnStartup(1);
    servlet.setAsyncSupported(true);

    return servlet;
}
 
示例5
public static UndertowJaxrsServer buildServer() {
    UndertowJaxrsServer server;
    System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
    try {
        LogManager.getLogManager().readConfiguration(Main.class.getClassLoader().getResourceAsStream("logging.jboss.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    server = new UndertowJaxrsServer().start();

    ResteasyDeployment deployment = new ResteasyDeploymentImpl();

    deployment.setApplicationClass(TracingApp.class.getName());

    DeploymentInfo di = server.undertowDeployment(deployment);
    di.setClassLoader(TracingApp.class.getClassLoader());
    di.setContextPath("");
    di.setDeploymentName("Resteasy");
    di.getServlets().get("ResteasyServlet").addInitParam(ResteasyContextParameters.RESTEASY_TRACING_TYPE, ResteasyContextParameters.RESTEASY_TRACING_TYPE_ALL)
            .addInitParam(ResteasyContextParameters.RESTEASY_TRACING_THRESHOLD, ResteasyContextParameters.RESTEASY_TRACING_LEVEL_VERBOSE);
    server.deploy(di);
    return server;
}
 
示例6
@BuildStep
public void process(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<ServletInitParamBuildItem> initParamProducer,
        BuildProducer<ResteasyDeploymentCustomizerBuildItem> deploymentCustomizerProducer) {

    validateControllers(beanArchiveIndexBuildItem);

    final IndexView index = beanArchiveIndexBuildItem.getIndex();
    final Collection<AnnotationInstance> annotations = index.getAnnotations(REST_CONTROLLER_ANNOTATION);
    if (annotations.isEmpty()) {
        return;
    }

    final Set<String> classNames = new HashSet<>();
    for (AnnotationInstance annotation : annotations) {
        classNames.add(annotation.target().asClass().toString());
    }

    // initialize the init params that will be used in case of servlet
    initParamProducer.produce(
            new ServletInitParamBuildItem(
                    ResteasyContextParameters.RESTEASY_SCANNED_RESOURCE_CLASSES_WITH_BUILDER,
                    SpringResourceBuilder.class.getName() + ":" + String.join(",", classNames)));
    // customize the deployment that will be used in case of RESTEasy standalone
    deploymentCustomizerProducer.produce(new ResteasyDeploymentCustomizerBuildItem(new Consumer<ResteasyDeployment>() {
        @Override
        public void accept(ResteasyDeployment resteasyDeployment) {
            resteasyDeployment.getScannedResourceClassesWithBuilder().put(SpringResourceBuilder.class.getName(),
                    new ArrayList<>(classNames));
        }
    }));

    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, false, SpringResourceBuilder.class.getName()));
}
 
示例7
private static void registerProviders(ResteasyDeployment deployment,
        Map<String, String> resteasyInitParameters,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<UnremovableBeanBuildItem> unremovableBeans,
        JaxrsProvidersToRegisterBuildItem jaxrsProvidersToRegisterBuildItem) {

    if (jaxrsProvidersToRegisterBuildItem.useBuiltIn()) {
        // if we find a wildcard media type, we just use the built-in providers
        resteasyInitParameters.put(ResteasyContextParameters.RESTEASY_USE_BUILTIN_PROVIDERS, "true");
        deployment.setRegisterBuiltin(true);

        if (!jaxrsProvidersToRegisterBuildItem.getContributedProviders().isEmpty()) {
            deployment.getProviderClasses().addAll(jaxrsProvidersToRegisterBuildItem.getContributedProviders());
            resteasyInitParameters.put(ResteasyContextParameters.RESTEASY_PROVIDERS,
                    String.join(",", jaxrsProvidersToRegisterBuildItem.getContributedProviders()));
        }
    } else {
        deployment.setRegisterBuiltin(false);
        deployment.getProviderClasses().addAll(jaxrsProvidersToRegisterBuildItem.getProviders());
        resteasyInitParameters.put(ResteasyContextParameters.RESTEASY_USE_BUILTIN_PROVIDERS, "false");
        resteasyInitParameters.put(ResteasyContextParameters.RESTEASY_PROVIDERS,
                String.join(",", jaxrsProvidersToRegisterBuildItem.getProviders()));
    }

    // register the providers for reflection
    for (String providerToRegister : jaxrsProvidersToRegisterBuildItem.getProviders()) {
        reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, providerToRegister));
    }

    // special case: our config providers
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
            ServletConfigSource.class,
            ServletContextConfigSource.class,
            FilterConfigSource.class));

    // Providers that are also beans are unremovable
    unremovableBeans.produce(new UnremovableBeanBuildItem(
            b -> jaxrsProvidersToRegisterBuildItem.getProviders().contains(b.getBeanClass().toString())));
}
 
示例8
@Test
public void basicTest() {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8081/type");
    assertEquals(ResteasyContextParameters.RESTEASY_TRACING_TYPE_ALL, target.request().get(String.class));

    target = client.target("http://localhost:8081/level");
    assertEquals(ResteasyContextParameters.RESTEASY_TRACING_LEVEL_VERBOSE, target.request().get(String.class));

    target = client.target("http://localhost:8081/logger");
    assertEquals(RESTEasyTracingLogger.class.getName(), target.request().get(String.class));

    client.close();

}
 
示例9
private DeploymentInfo createAuthServerDeploymentInfo() {
    ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplicationClass(KeycloakApplication.class.getName());

    // RESTEASY-2034
    deployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, true);

    DeploymentInfo di = undertow.undertowDeployment(deployment);
    di.setClassLoader(getClass().getClassLoader());
    di.setContextPath("/auth");
    di.setDeploymentName("Keycloak");
    if (configuration.getKeycloakConfigPropertyOverridesMap() != null) {
        try {
            di.addInitParameter(JsonConfigProviderFactory.SERVER_CONTEXT_CONFIG_PROPERTY_OVERRIDES,
              JsonSerialization.writeValueAsString(configuration.getKeycloakConfigPropertyOverridesMap()));
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    di.setDefaultServletConfig(new DefaultServletConfig(true));
    di.addWelcomePage("theme/keycloak/welcome/resources/index.html");

    FilterInfo filter = Servlets.filter("SessionFilter", TestKeycloakSessionServletFilter.class);
    di.addFilter(filter);
    di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
    filter.setAsyncSupported(true);

    return di;
}
 
示例10
public QuarkusFilter() {
    //TODO: a temporary hack for https://github.com/quarkusio/quarkus/issues/9647, we need to disable the sanitizer to avoid
    // escaping text/html responses from the server
    Resteasy.getContextData(ResteasyDeployment.class).setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, Boolean.TRUE);
}