All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lajospolya.spotifyapiwrapper.internal.Java11HttpClient Maven / Gradle / Ivy

Go to download

This project wraps the Spotify public API in order to allow users to intuitively use it

There is a newer version: 3.0.RELEASE
Show newest version
package com.lajospolya.spotifyapiwrapper.internal;

import java.io.IOException;
import java.lang.reflect.Type;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Java11HttpClient implements ISpotifyClient
{
    private HttpClient httpClient;

    public Java11HttpClient()
    {
        this.httpClient = HttpClient.newBuilder()
                .version(HttpClient.Version.HTTP_2)
                .followRedirects(HttpClient.Redirect.NORMAL)
                .build();
    }

    @Override
    public  ISpotifyResponse send(ISpotifyRequest request, Type typeOfResponse)
    {
        try
        {
            return new Java11HttpResponse<>(httpClient.send((HttpRequest) request.get(), HttpResponse.BodyHandlers.ofString()), typeOfResponse);
        }
        catch (InterruptedException | IOException e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public  ISpotifyAsyncResponse sendAsync(ISpotifyRequest request, Type typeOfResponse)
    {
        return new CompletableFutureAsyncResponse<>(
                httpClient.sendAsync((HttpRequest) request.get(), HttpResponse.BodyHandlers.ofString()), typeOfResponse);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy