Search in sources :

Example 6 with ResteasyProviderFactory

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

the class ExternalVerifierService method verify.

@Override
public List<Result> verify(String connectorId, Map<String, String> options) {
    final ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider();
    resteasyJacksonProvider.setMapper(MAPPER);
    final ResteasyProviderFactory providerFactory = ResteasyProviderFactory.newInstance();
    providerFactory.register(resteasyJacksonProvider);
    final Configuration configuration = new LocalResteasyProviderFactory(providerFactory);
    Client client = ClientBuilder.newClient(configuration);
    WebTarget target = client.target(String.format("http://%s/api/v1/verifier/%s", config.getService(), connectorId));
    return target.request(MediaType.APPLICATION_JSON).post(Entity.entity(options, MediaType.APPLICATION_JSON), new GenericType<List<Result>>() {
    });
}
Also used : ResteasyJackson2Provider(org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider) Configuration(javax.ws.rs.core.Configuration) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) Client(javax.ws.rs.client.Client)

Example 7 with ResteasyProviderFactory

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

the class HttpClient method createClient.

/* default */
private Client createClient() {
    final ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider();
    resteasyJacksonProvider.setMapper(MAPPER);
    final ResteasyProviderFactory providerFactory = ResteasyProviderFactory.newInstance();
    providerFactory.register(resteasyJacksonProvider);
    final Configuration configuration = new LocalResteasyProviderFactory(providerFactory);
    return ClientBuilder.newClient(configuration);
}
Also used : ResteasyJackson2Provider(org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider) Configuration(javax.ws.rs.core.Configuration) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory)

Example 8 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project scheduling by ow2-proactive.

the class SchedulerStateRest method submitPlannings.

@Override
public String submitPlannings(String sessionId, PathSegment pathSegment, Map<String, String> jobContentXmlString) throws JobCreationRestException, NotConnectedRestException, IOException {
    checkAccess(sessionId, "plannings");
    Map<String, String> jobVariables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
    if (jobContentXmlString == null || jobContentXmlString.size() != 1) {
        throw new JobCreationRestException("Cannot find job body: code " + HttpURLConnection.HTTP_BAD_REQUEST);
    }
    Map<String, Object> requestBody = new HashMap<>(2);
    requestBody.put(VARIABLES_KEY, jobVariables);
    requestBody.put("xmlContentString", jobContentXmlString.entrySet().iterator().next().getValue());
    Response response = null;
    try {
        ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
        SchedulerRestClient.registerGzipEncoding(providerFactory);
        ResteasyClient client = new ResteasyClientBuilder().providerFactory(providerFactory).build();
        ResteasyWebTarget target = client.target(PortalConfiguration.JOBPLANNER_URL.getValueAsString());
        response = target.request().header("sessionid", sessionId).post(Entity.entity(requestBody, "application/json"));
        if (HttpURLConnection.HTTP_OK != response.getStatus()) {
            throw new IOException(String.format("Cannot access resource %s: code %d", PortalConfiguration.JOBPLANNER_URL.getValueAsString(), response.getStatus()));
        }
        return response.readEntity(String.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) FileObject(org.apache.commons.vfs2.FileObject) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Example 9 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project kie-wb-common by kiegroup.

the class MavenRestHandlerTest method post.

@Test
public void post() {
    // Start preparation FS
    try {
        fileSystemTestingUtils.setup();
        ioService = fileSystemTestingUtils.getIoService();
        final String repoName = "myrepo";
        final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), new HashMap<String, Object>() {

            {
                put("init", Boolean.TRUE);
                put("internal", Boolean.TRUE);
            }
        });
        ioService.startBatch(fs);
        String pom = "target/test-classes/kjar-2-single-resources/pom.xml";
        if (!runIntoMavenCLI) {
            pom = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/pom.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File(pom).toPath())));
        String personDotJava = "target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        if (!runIntoMavenCLI) {
            personDotJava = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File(personDotJava).toPath())));
        String simpleRulesDotDRL = "target/test-classes/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl";
        if (!runIntoMavenCLI) {
            simpleRulesDotDRL = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File(simpleRulesDotDRL).toPath())));
        String kmodule = "target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        if (!runIntoMavenCLI) {
            kmodule = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File(kmodule).toPath())));
        ioService.endBatch();
        java.nio.file.Path tmpRootCloned = java.nio.file.Files.createTempDirectory("cloned");
        java.nio.file.Path tmpCloned = java.nio.file.Files.createDirectories(java.nio.file.Paths.get(tmpRootCloned.toString(), "dummy"));
        final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");
        final Git cloned = Git.cloneRepository().setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(gitClonedFolder).call();
        assertThat(cloned).isNotNull();
        mavenRepoPath = java.nio.file.Paths.get(System.getProperty("user.home"), ".m2", "repository");
        tmpRoot = java.nio.file.Paths.get(gitClonedFolder + "/dummy/");
        // END preparation FS
        Dispatcher dispatcher = new AsynchronousDispatcher(new ResteasyProviderFactory());
        ResteasyProviderFactory.setInstance(dispatcher.getProviderFactory());
        RegisterBuiltin.register(dispatcher.getProviderFactory());
        POJOResourceFactory noDefaults = new POJOResourceFactory(MavenRestHandler.class);
        dispatcher.getRegistry().addResourceFactory(noDefaults);
        MockHttpRequest request = MockHttpRequest.create("POST", "build/maven/");
        request.header("project", tmpRoot.toAbsolutePath().toString() + "/dummy").header("mavenrepo", mavenRepoPath.toAbsolutePath().toString());
        MockHttpResponse response = new MockHttpResponse();
        SynchronousExecutionContext synchronousExecutionContext = new SynchronousExecutionContext((SynchronousDispatcher) dispatcher, request, response);
        request.setAsynchronousContext(synchronousExecutionContext);
        dispatcher.invoke(request, response);
        assertThat(response.getStatus()).isEqualTo(200);
        byte[] serializedCompilationResponse = response.getOutput();
        HttpCompilationResponse res = RestUtils.readDefaultCompilationResponseFromBytes(serializedCompilationResponse);
        assertThat(res).isNotNull();
        assertThat(res.getDependencies()).hasSize(4);
        assertThat(res.getTargetContent()).hasSize(3);
        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) HttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.HttpCompilationResponse) HashMap(java.util.HashMap) SynchronousDispatcher(org.jboss.resteasy.core.SynchronousDispatcher) AsynchronousDispatcher(org.jboss.resteasy.core.AsynchronousDispatcher) Dispatcher(org.jboss.resteasy.core.Dispatcher) SynchronousExecutionContext(org.jboss.resteasy.core.SynchronousExecutionContext) POJOResourceFactory(org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory) Git(org.eclipse.jgit.api.Git) AsynchronousDispatcher(org.jboss.resteasy.core.AsynchronousDispatcher) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) File(java.io.File) Path(java.nio.file.Path) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Test(org.junit.Test)

Example 10 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project fabric8 by jboss-fuse.

the class ResteasyGitRepoClient method createWebClient.

/**
 * Creates a JAXRS web client for the given JAXRS client
 */
protected <T> T createWebClient(Class<T> clientType) {
    String address = getAddress();
    ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
    providerFactory.register(ResteasyJackson2Provider.class);
    providerFactory.register(Jackson2JsonpInterceptor.class);
    providerFactory.register(StringTextStar.class);
    providerFactory.register(DefaultTextPlain.class);
    providerFactory.register(FileProvider.class);
    providerFactory.register(InputStreamProvider.class);
    providerFactory.register(new Authenticator());
    providerFactory.register(clientType);
    ResteasyClientBuilder builder = new ResteasyClientBuilder();
    builder.providerFactory(providerFactory);
    builder.connectionPoolSize(3);
    Client client = builder.build();
    ResteasyWebTarget target = (ResteasyWebTarget) client.target(address);
    return target.proxy(clientType);
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Client(javax.ws.rs.client.Client)

Aggregations

ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)19 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)8 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)6 HttpClient (org.apache.http.client.HttpClient)5 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)5 Client (javax.ws.rs.client.Client)4 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)4 LocalResteasyProviderFactory (org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory)4 ResteasyJackson2Provider (org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider)4 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 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GuiceRegistry (com.peterphi.std.guice.apploader.impl.GuiceRegistry)1