Search in sources :

Example 1 with RestClientBuilder

use of org.eclipse.microprofile.rest.client.RestClientBuilder in project wildfly-swarm by wildfly-swarm.

the class RestClientDelegateBean method create.

@Override
public Object create(CreationalContext<Object> creationalContext) {
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    String baseUrl = getBaseUrl();
    try {
        return builder.baseUrl(new URL(baseUrl)).build(proxyType);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("The value of URL was invalid " + baseUrl);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) URL(java.net.URL)

Example 2 with RestClientBuilder

use of org.eclipse.microprofile.rest.client.RestClientBuilder in project Payara by payara.

the class PersonControllerClientHelper method getBasicPersonControllerClient.

public static PersonControllerClient getBasicPersonControllerClient(URL deploymentUrl, String username, String password) {
    try {
        RestClientBuilder builder = RestClientBuilder.newBuilder();
        builder.register(HttpAuthenticationFeature.basic(username, password));
        PersonControllerClient client = builder.baseUrl(new URL(deploymentUrl.toURI().toString() + "resources/")).build(PersonControllerClient.class);
        return client;
    } catch (URISyntaxException | MalformedURLException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Example 3 with RestClientBuilder

use of org.eclipse.microprofile.rest.client.RestClientBuilder in project Payara by payara.

the class PersonControllerClientHelper method getPersonControllerClient.

public static PersonControllerClient getPersonControllerClient(URL deploymentUrl, String username, String password) {
    try {
        RestClientBuilder builder = RestClientBuilder.newBuilder();
        builder.register((ClientRequestFilter) context -> {
            context.getHeaders().add("username", DEFAULT_USER);
            context.getHeaders().add("password", DEFAULT_PASSWORD);
        });
        PersonControllerClient client = builder.baseUrl(new URL(deploymentUrl.toURI().toString() + "resources/")).build(PersonControllerClient.class);
        return client;
    } catch (URISyntaxException | MalformedURLException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : DEFAULT_PASSWORD(fish.payara.samples.dynamic.roles.common.AuthoritiesConstants.DEFAULT_PASSWORD) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) DEFAULT_USER(fish.payara.samples.dynamic.roles.common.AuthoritiesConstants.DEFAULT_USER) ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) MalformedURLException(java.net.MalformedURLException) RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Example 4 with RestClientBuilder

use of org.eclipse.microprofile.rest.client.RestClientBuilder in project cxf by apache.

the class CxfTypeSafeClientBuilderTest method testConfigMethods.

@Test
public void testConfigMethods() {
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    assertEquals("y", builder.property("x", "y").getConfiguration().getProperty("x"));
    assertTrue(builder.register(HighPriorityMBW.class).getConfiguration().isRegistered(HighPriorityMBW.class));
    HighPriorityMBW mbw = new HighPriorityMBW(1);
    assertTrue(builder.register(mbw).getConfiguration().isRegistered(mbw));
}
Also used : HighPriorityMBW(org.apache.cxf.microprofile.client.mock.HighPriorityMBW) RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) Test(org.junit.Test)

Example 5 with RestClientBuilder

use of org.eclipse.microprofile.rest.client.RestClientBuilder in project cxf by apache.

the class CxfTypeSafeClientBuilderTest method testConfigPriorityOverrides.

@Test
public void testConfigPriorityOverrides() throws Exception {
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    builder.property("microprofile.rest.client.disable.default.mapper", true);
    // annotation priority of 10
    builder.register(HighPriorityClientReqFilter.class);
    builder.register(LowPriorityClientReqFilter.class, 5);
    // overriding priority to be 5 (preferred)
    assertTrue(builder.getConfiguration().isRegistered(LowPriorityClientReqFilter.class));
    MyClient c = builder.baseUrl(new URL("http://localhost/null")).build(MyClient.class);
    Response r = c.get();
    assertEquals("low", r.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) LowPriorityClientReqFilter(org.apache.cxf.microprofile.client.mock.LowPriorityClientReqFilter) MyClient(org.apache.cxf.microprofile.client.mock.MyClient) RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) URL(java.net.URL) Test(org.junit.Test)

Aggregations

RestClientBuilder (org.eclipse.microprofile.rest.client.RestClientBuilder)7 URL (java.net.URL)4 Test (org.junit.Test)4 MalformedURLException (java.net.MalformedURLException)3 MyClient (org.apache.cxf.microprofile.client.mock.MyClient)3 URISyntaxException (java.net.URISyntaxException)2 TLSConfiguration (org.apache.cxf.jaxrs.client.spec.TLSConfiguration)2 TestClientRequestFilter (org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilter)2 DEFAULT_PASSWORD (fish.payara.samples.dynamic.roles.common.AuthoritiesConstants.DEFAULT_PASSWORD)1 DEFAULT_USER (fish.payara.samples.dynamic.roles.common.AuthoritiesConstants.DEFAULT_USER)1 ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)1 Response (javax.ws.rs.core.Response)1 HighPriorityMBW (org.apache.cxf.microprofile.client.mock.HighPriorityMBW)1 LowPriorityClientReqFilter (org.apache.cxf.microprofile.client.mock.LowPriorityClientReqFilter)1