Search in sources :

Example 1 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project openremote by openremote.

the class JSAPIServlet method scanResources.

@SuppressWarnings("unchecked")
public void scanResources() throws Exception {
    ServletConfig config = getServletConfig();
    ServletContext servletContext = config.getServletContext();
    Map<String, ResteasyDeployment> deployments = (Map<String, ResteasyDeployment>) servletContext.getAttribute(ResteasyContextParameters.RESTEASY_DEPLOYMENTS);
    if (deployments == null)
        return;
    synchronized (this) {
        services = new HashMap<String, ServiceRegistry>();
        for (Map.Entry<String, ResteasyDeployment> entry : deployments.entrySet()) {
            ResourceMethodRegistry registry = (ResourceMethodRegistry) entry.getValue().getRegistry();
            ResteasyProviderFactory providerFactory = entry.getValue().getProviderFactory();
            ServiceRegistry service = new ServiceRegistry(null, registry, providerFactory, null);
            services.put(entry.getKey(), service);
        }
    }
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project syndesis-qe by syndesisio.

the class RestUtils method getClient.

public static Client getClient(ResteasyJackson2Provider jackson2Provider) throws RestClientException {
    final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(RestUtils.createAllTrustingClient());
    final Client client = new ResteasyClientBuilder().providerFactory(// this is needed otherwise default jackson2provider is used, which causes problems with JDK8 Optional
    new ResteasyProviderFactory()).register(jackson2Provider).httpEngine(engine).build();
    return client;
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) Client(javax.ws.rs.client.Client) HttpClient(org.apache.http.client.HttpClient) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Example 3 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project adeptj-modules by AdeptJ.

the class JaxRSWhiteboardManager method start.

/**
 * Bootstrap the RESTEasy Framework, open ServiceTracker for JAX-RS providers and resources.
 *
 * @param servletConfig the {@link ServletConfig} provided by OSGi HttpService.
 * @param vf            the Java Bean Validation's {@link ValidatorFactory}
 */
public void start(ServletConfig servletConfig, ValidatorFactory vf) {
    try {
        final long startTime = System.nanoTime();
        LOGGER.info("Bootstrapping JAX-RS Runtime!!");
        this.resteasyDispatcher = new HttpServlet30Dispatcher();
        this.resteasyDispatcher.init(servletConfig);
        Dispatcher dispatcher = this.resteasyDispatcher.getDispatcher();
        ResteasyProviderFactory providerFactory = dispatcher.getProviderFactory();
        ResteasyUtil.removeInternalValidators(providerFactory);
        ResteasyUtil.registerInternalProviders(providerFactory, this.config, vf);
        this.serviceTrackers.add(new JaxRSProviderTracker(this.context, providerFactory));
        this.serviceTrackers.add(new JaxRSResourceTracker(this.context, dispatcher.getRegistry()));
        LOGGER.info(JAXRS_RT_BOOTSTRAP_MSG, NANOSECONDS.toMillis(System.nanoTime() - startTime));
    } catch (Exception ex) {
        // NOSONAR
        LOGGER.error("Exception while bootstrapping JAX-RS Runtime!!", ex);
        throw new JaxRSBootstrapException(ex.getMessage(), ex);
    }
}
Also used : JaxRSResourceTracker(com.adeptj.modules.jaxrs.resteasy.internal.JaxRSResourceTracker) JaxRSProviderTracker(com.adeptj.modules.jaxrs.resteasy.internal.JaxRSProviderTracker) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) Dispatcher(org.jboss.resteasy.core.Dispatcher) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) JaxRSBootstrapException(com.adeptj.modules.jaxrs.resteasy.JaxRSBootstrapException) JaxRSBootstrapException(com.adeptj.modules.jaxrs.resteasy.JaxRSBootstrapException)

Example 4 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project candlepin by candlepin.

the class VerifyAuthorizationFilter method getArguments.

protected Map<Verify, Object> getArguments(HttpRequest request, Method method) {
    ResteasyProviderFactory resourceFactory = ResteasyProviderFactory.getInstance();
    InjectorFactory injectorFactory = resourceFactory.getInjectorFactory();
    ResourceLocator locator = locatorMap.get(method);
    if (null == locator) {
        throw new IseException("Method " + method.getName() + " not registered as RESTful.");
    }
    MethodInjector methodInjector = injectorFactory.createMethodInjector(locator, resourceFactory);
    HttpResponse response = ResteasyProviderFactory.popContextData(HttpResponse.class);
    Object[] args = methodInjector.injectArguments(request, response);
    // LinkedHashMap preserves insertion order
    Map<Verify, Object> argMap = new LinkedHashMap<>();
    Annotation[][] allAnnotations = method.getParameterAnnotations();
    // Any occurrence of the Verify annotation means the method is not superadmin exclusive.
    for (int i = 0; i < allAnnotations.length; i++) {
        for (Annotation a : allAnnotations[i]) {
            if (a instanceof Verify) {
                Verify v = (Verify) a;
                if (!v.nullable() && args[i] == null) {
                    throw new IllegalStateException("Null passed to a non-nullable Verify annotation.");
                } else {
                    argMap.put(v, args[i]);
                }
            }
        }
    }
    return argMap;
}
Also used : HttpResponse(org.jboss.resteasy.spi.HttpResponse) Annotation(java.lang.annotation.Annotation) LinkedHashMap(java.util.LinkedHashMap) MethodInjector(org.jboss.resteasy.spi.MethodInjector) IseException(org.candlepin.common.exceptions.IseException) InjectorFactory(org.jboss.resteasy.spi.InjectorFactory) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Verify(org.candlepin.auth.Verify) ResourceLocator(org.jboss.resteasy.spi.metadata.ResourceLocator)

Example 5 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project narayana by jbosstm.

the class BaseTest method startRestEasy.

protected static void startRestEasy(Class<?>... classes) throws Exception {
    server = new TJWSEmbeddedJaxrsServer();
    server.setPort(PORT);
    server.start();
    Registry registry = server.getDeployment().getRegistry();
    ResteasyProviderFactory factory = server.getDeployment().getDispatcher().getProviderFactory();
    if (classes != null)
        for (Class<?> clazz : classes) registry.addPerRequestResource(clazz);
    factory.registerProvider(TMUnavailableMapper.class);
    factory.registerProvider(TransactionStatusMapper.class);
    factory.registerProvider(HttpResponseMapper.class);
    factory.registerProvider(NotFoundMapper.class);
}
Also used : TJWSEmbeddedJaxrsServer(org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer) AfterClass(org.junit.AfterClass) Registry(org.jboss.resteasy.spi.Registry) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Aggregations

ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)17 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)6 HttpClient (org.apache.http.client.HttpClient)4 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)4 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)4 Client (javax.ws.rs.client.Client)3 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)3 LocalResteasyProviderFactory (org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory)3 ResteasyJackson2Provider (org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider)3 HashMap (java.util.HashMap)2 ServletContext (javax.servlet.ServletContext)2 Configuration (javax.ws.rs.core.Configuration)2 Dispatcher (org.jboss.resteasy.core.Dispatcher)2 Registry (org.jboss.resteasy.spi.Registry)2 JaxRSBootstrapException (com.adeptj.modules.jaxrs.resteasy.JaxRSBootstrapException)1 JaxRSProviderTracker (com.adeptj.modules.jaxrs.resteasy.internal.JaxRSProviderTracker)1 JaxRSResourceTracker (com.adeptj.modules.jaxrs.resteasy.internal.JaxRSResourceTracker)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 GuiceRegistry (com.peterphi.std.guice.apploader.impl.GuiceRegistry)1 LogReportMessageBodyReader (com.peterphi.std.guice.common.logging.logreport.jaxrs.LogReportMessageBodyReader)1