Search in sources :

Example 6 with Header

use of com.opentext.ia.sdk.support.http.Header in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenMakingRestCalls method shouldForwardToHttpClient.

@Test
public void shouldForwardToHttpClient() throws IOException {
    String uri = randomString();
    Class<?> type = String.class;
    Collection<Header> authorizationHeader = new ArrayList<>();
    authorizationHeader.add(new Header("Authorization", "Bearer " + token));
    Collection<Header> contentAndAuthorizationHeaders = new ArrayList<>();
    contentAndAuthorizationHeaders.add(new Header("Accept", MediaTypes.HAL));
    contentAndAuthorizationHeaders.addAll(authorizationHeader);
    restClient.get(uri, type);
    verify(httpClient).get(eq(uri), eq(contentAndAuthorizationHeaders), eq(type));
    restClient.put(uri, type);
    verify(httpClient).put(eq(uri), eq(contentAndAuthorizationHeaders), eq(type));
    restClient.post(uri, type);
    verify(httpClient).post(eq(uri), eq(contentAndAuthorizationHeaders), eq(type));
    restClient.delete(uri);
    verify(httpClient).delete(eq(uri), eq(authorizationHeader));
}
Also used : Header(com.opentext.ia.sdk.support.http.Header) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with Header

use of com.opentext.ia.sdk.support.http.Header in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class JwtAuthentication method postToGateway.

private AuthenticationSuccess postToGateway(String payload) {
    AuthenticationSuccess result;
    String gatewayUrl = gatewayInfo.getGatewayUrl();
    Collection<Header> headers = new ArrayList<>(Arrays.asList(gatewayInfo.getAuthorizationHeader(), gatewayInfo.getContentTypeHeader()));
    try {
        result = httpClient.post(gatewayUrl, headers, AuthenticationSuccess.class, payload);
    } catch (IOException ex) {
        if (timer != null) {
            timer.stop();
        }
        throw new RuntimeIoException(ex);
    }
    return result;
}
Also used : Header(com.opentext.ia.sdk.support.http.Header) IOException(java.io.IOException) RuntimeIoException(com.opentext.ia.sdk.support.io.RuntimeIoException)

Aggregations

Header (com.opentext.ia.sdk.support.http.Header)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 HttpClient (com.opentext.ia.sdk.support.http.HttpClient)1 ApacheHttpClient (com.opentext.ia.sdk.support.http.apache.ApacheHttpClient)1 AuthenticationStrategy (com.opentext.ia.sdk.support.http.rest.AuthenticationStrategy)1 GatewayInfo (com.opentext.ia.sdk.support.http.rest.GatewayInfo)1 JwtAuthentication (com.opentext.ia.sdk.support.http.rest.JwtAuthentication)1 RuntimeIoException (com.opentext.ia.sdk.support.io.RuntimeIoException)1 IOException (java.io.IOException)1