Search in sources :

Example 1 with IHttpRequest

use of com.microsoft.graph.http.IHttpRequest in project msgraph-sdk-java by microsoftgraph.

the class TestBase method GetAuthenticatedClient.

private void GetAuthenticatedClient() {
    if (graphClient == null) {
        try {
            accessToken = GetAccessToken().replace("\"", "");
            IAuthenticationProvider mAuthenticationProvider = new IAuthenticationProvider() {

                @Override
                public void authenticateRequest(final IHttpRequest request) {
                    request.addHeader("Authorization", "Bearer " + accessToken);
                }
            };
            IClientConfig mClientConfig = DefaultClientConfig.createWithAuthenticationProvider(mAuthenticationProvider);
            graphClient = GraphServiceClient.fromConfig(mClientConfig);
        } catch (Exception e) {
            throw new Error("Could not create a graph client: " + e.getLocalizedMessage());
        }
    }
}
Also used : IHttpRequest(com.microsoft.graph.http.IHttpRequest) IAuthenticationProvider(com.microsoft.graph.authentication.IAuthenticationProvider) IClientConfig(com.microsoft.graph.core.IClientConfig)

Example 2 with IHttpRequest

use of com.microsoft.graph.http.IHttpRequest in project msgraph-sdk-java by microsoftgraph.

the class GraphServiceClientTest method testOverrideOfHttpSerializer.

@Test
public void testOverrideOfHttpSerializer() {
    IHttpProvider hp = new IHttpProvider() {

        @Override
        public ISerializer getSerializer() {
            return null;
        }

        @Override
        public <Result, BodyType> void send(IHttpRequest request, ICallback<Result> callback, Class<Result> resultClass, BodyType serializable) {
        // do nothing
        }

        @Override
        public <Result, BodyType> Result send(IHttpRequest request, Class<Result> resultClass, BodyType serializable) throws ClientException {
            return null;
        }

        @Override
        public <Result, BodyType, DeserializeType> Result send(IHttpRequest request, Class<Result> resultClass, BodyType serializable, IStatefulResponseHandler<Result, DeserializeType> handler) throws ClientException {
            return null;
        }
    };
    IGraphServiceClient client = // 
    GraphServiceClient.builder().authenticationProvider(// 
    auth).httpProvider(// 
    hp).buildClient();
    assertEquals(hp, client.getHttpProvider());
    assertEquals(auth, client.getAuthenticationProvider());
    assertNotNull(client.getSerializer());
    assertNotNull(client.getLogger());
    assertNotNull(client.getExecutors());
}
Also used : IHttpRequest(com.microsoft.graph.http.IHttpRequest) ICallback(com.microsoft.graph.concurrency.ICallback) IHttpProvider(com.microsoft.graph.http.IHttpProvider) IStatefulResponseHandler(com.microsoft.graph.http.IStatefulResponseHandler) IGraphServiceClient(com.microsoft.graph.models.extensions.IGraphServiceClient) Test(org.junit.Test)

Example 3 with IHttpRequest

use of com.microsoft.graph.http.IHttpRequest in project msgraph-sdk-java by microsoftgraph.

the class GraphServiceClientTest method testOverrideOfDefaultAuthenticationProvider.

@Test
public void testOverrideOfDefaultAuthenticationProvider() {
    IAuthenticationProvider ap = new IAuthenticationProvider() {

        @Override
        public void authenticateRequest(IHttpRequest request) {
        // do nothing
        }
    };
    IGraphServiceClient client = // 
    GraphServiceClient.builder().authenticationProvider(// 
    ap).buildClient();
    assertEquals(ap, client.getAuthenticationProvider());
    assertNotNull(client.getExecutors());
    assertNotNull(client.getHttpProvider());
    assertNotNull(client.getLogger());
    assertNotNull(client.getSerializer());
    assertEquals(ap, ((DefaultHttpProvider) client.getHttpProvider()).getAuthenticationProvider());
}
Also used : IHttpRequest(com.microsoft.graph.http.IHttpRequest) IAuthenticationProvider(com.microsoft.graph.authentication.IAuthenticationProvider) IGraphServiceClient(com.microsoft.graph.models.extensions.IGraphServiceClient) Test(org.junit.Test)

Aggregations

IHttpRequest (com.microsoft.graph.http.IHttpRequest)3 IAuthenticationProvider (com.microsoft.graph.authentication.IAuthenticationProvider)2 IGraphServiceClient (com.microsoft.graph.models.extensions.IGraphServiceClient)2 Test (org.junit.Test)2 ICallback (com.microsoft.graph.concurrency.ICallback)1 IClientConfig (com.microsoft.graph.core.IClientConfig)1 IHttpProvider (com.microsoft.graph.http.IHttpProvider)1 IStatefulResponseHandler (com.microsoft.graph.http.IStatefulResponseHandler)1