Java Code Examples for org.eclipse.microprofile.rest.client.RestClientBuilder#build()

The following examples show how to use org.eclipse.microprofile.rest.client.RestClientBuilder#build() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProvidesRestClientBuilderTest.java    From microprofile-rest-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testLastBaseUriOrBaseUrlCallWins() throws Exception {
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    builder = builder.register(ReturnWithURLRequestFilter.class);

    builder = builder.baseUri(new URI("http://localhost:8080/wrong1"));
    builder = builder.baseUrl(new URL("http://localhost:8080/right1"));
    SimpleGetApi client = builder.build(SimpleGetApi.class);
    assertEquals(client.executeGet().readEntity(String.class), "GET http://localhost:8080/right1");

    builder = builder.baseUrl(new URL("http://localhost:8080/wrong2"));
    builder = builder.baseUri(new URI("http://localhost:8080/wrong2b"));
    builder = builder.baseUri(new URI("http://localhost:8080/right2"));
    client = builder.build(SimpleGetApi.class);
    assertEquals(client.executeGet().readEntity(String.class), "GET http://localhost:8080/right2");
}
 
Example 2
Source File: RestClientBase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public Object create() {
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    configureBaseUrl(builder);
    configureTimeouts(builder);
    configureProviders(builder);
    configureSsl(builder);
    // If we have context propagation, then propagate context to the async client threads
    InstanceHandle<ManagedExecutor> managedExecutor = Arc.container().instance(ManagedExecutor.class);
    if (managedExecutor.isAvailable()) {
        builder.executorService(managedExecutor.get());
    }

    Object result = builder.build(proxyType);
    return result;
}
 
Example 3
Source File: ClientHeaderParamTest.java    From microprofile-rest-client with Apache License 2.0 5 votes vote down vote up
private static ClientHeaderParamClient client(Class<?>... providers) {
    try {
    RestClientBuilder builder = RestClientBuilder.newBuilder().baseUri(getServerURI());
    for (Class<?> provider : providers) {
        builder.register(provider);
    }
    return builder.build(ClientHeaderParamClient.class);
}
catch (Throwable t) {
    t.printStackTrace();
    return null;
}
}
 
Example 4
Source File: CDIClientHeadersFactoryTest.java    From microprofile-rest-client with Apache License 2.0 5 votes vote down vote up
private static CdiClientHeadersFactoryClient client(Class<?>... providers) {
    try {
        RestClientBuilder builder = RestClientBuilder.newBuilder().baseUri(URI.create("http://localhost:9080/notused"));
        for (Class<?> provider : providers) {
            builder.register(provider);
        }
        return builder.build(CdiClientHeadersFactoryClient.class);
    }
    catch (Throwable t) {
        t.printStackTrace();
        return null;
    }
}
 
Example 5
Source File: ClientHeadersFactoryTest.java    From microprofile-rest-client with Apache License 2.0 5 votes vote down vote up
private static ClientHeadersFactoryClient client(Class<?>... providers) {
    try {
        RestClientBuilder builder = RestClientBuilder.newBuilder().baseUri(URI.create("http://localhost:9080/notused"));
        for (Class<?> provider : providers) {
            builder.register(provider);
        }
        return builder.build(ClientHeadersFactoryClient.class);
    }
    catch (Throwable t) {
        t.printStackTrace();
        return null;
    }
}
 
Example 6
Source File: ProvidesRestClientBuilderTest.java    From microprofile-rest-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testIllegalStateExceptionThrownWhenNoBaseUriOrUrlSpecified() {
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    builder = builder.register(ReturnWithURLRequestFilter.class);
    try {
        builder.build(SimpleGetApi.class);
        fail("Did not throw expected IllegalStateException");
    }
    catch (Throwable t) {
        assertEquals(t.getClass(), IllegalStateException.class);
    }
}