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

The following examples show how to use org.eclipse.microprofile.rest.client.RestClientBuilder#register() . 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: 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 3
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 4
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 5
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);
    }
}
 
Example 6
Source File: CxfTypeSafeClientBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigPriorityOverrides() throws Exception {
    RestClientBuilder builder = RestClientBuilder.newBuilder();
    builder.property("microprofile.rest.client.disable.default.mapper", true);
    builder.register(HighPriorityClientReqFilter.class); // annotation priority of 10
    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));
}
 
Example 7
Source File: RestClientBase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private void registerProviders(RestClientBuilder builder, String providersAsString) {
    for (String s : providersAsString.split(",")) {
        builder.register(providerClassForName(s.trim()));
    }
}
 
Example 8
Source File: SimpleRestClientBuilderListenerImpl.java    From microprofile-rest-client with Apache License 2.0 4 votes vote down vote up
@Override
public void onNewBuilder(RestClientBuilder builder) {
    builder.register(ReturnWith200RequestFilter.class, 1);
}
 
Example 9
Source File: SimpleRestClientListenerImpl.java    From microprofile-rest-client with Apache License 2.0 4 votes vote down vote up
@Override
public void onNewClient(Class<?> serviceInterface, RestClientBuilder builder) {
    SimpleRestClientListenerImpl.serviceInterface = serviceInterface;
    builder.register(ReturnWith500RequestFilter.class, 1);
}