Created
April 8, 2017 14:59
-
-
Save zeroows/8e8cb53e1e8f26edde09be8ed365e357 to your computer and use it in GitHub Desktop.
Retrofit Configuration for Spring Boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
import net.aalkhodiry.notifications.utils.LoggingInterceptor; | |
import okhttp3.OkHttpClient; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import retrofit2.Retrofit; | |
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; | |
import retrofit2.converter.gson.GsonConverterFactory; | |
/** | |
* Created by zeroows on 02/10/16. | |
*/ | |
@Configuration | |
public class RetrofitConfiguration { | |
@Autowired | |
private LoggingInterceptor loggingInterceptor; | |
@Value("${oneSignal.url}") | |
private String url; | |
@Bean | |
@Autowired | |
public Retrofit retrofit(OkHttpClient client, Gson gson) { | |
Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl(url) | |
.client(client) | |
.addConverterFactory(GsonConverterFactory.create(gson)) | |
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | |
.build(); | |
return retrofit; | |
} | |
@Bean | |
public OkHttpClient client() { | |
final OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder(); | |
final OkHttpClient builtClient = okHttpClientBuilder.addInterceptor(loggingInterceptor).build(); | |
return builtClient; | |
} | |
@Bean | |
public Gson gson() { | |
return new GsonBuilder().setLenient().create(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment