/*
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.front50.config;

import static retrofit.RestAdapter.LogLevel.BASIC;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jakewharton.retrofit.Ok3Client;
import com.netflix.spinnaker.config.DefaultServiceEndpoint;
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider;
import com.netflix.spinnaker.front50.echo.EchoService;
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit.Endpoints;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;

/** echo service configuration */
@Configuration
@ConditionalOnProperty("services.echo.enabled")
public class EchoConfiguration {
  @Bean
  EchoService echoService(
      OkHttpClientProvider okHttpClientProvider,
      @Value("${services.echo.base-url}") String baseUrl) {
    OkHttpClient okHttpClient =
        okHttpClientProvider.getClient(new DefaultServiceEndpoint("echo", baseUrl));
    ObjectMapper objectMapper = new ObjectMapper();
    JacksonConverter jacksonConverter = new JacksonConverter(objectMapper);

    return new RestAdapter.Builder()
        .setEndpoint(Endpoints.newFixedEndpoint(baseUrl))
        .setClient(new Ok3Client(okHttpClient))
        .setConverter(jacksonConverter)
        .setLogLevel(BASIC)
        .setLog(new Slf4jRetrofitLogger(EchoService.class))
        .build()
        .create(EchoService.class);
  }
}

@@ -642,60 +642,8 @@
 g;%0A%0A
-import static retrofit.RestAdapter.LogLevel.BASIC;%0A%0A
 impo
@@ -694,51 +694,8 @@
 er;%0A
-import com.jakewharton.retrofit.Ok3Client;%0A
 impo
@@ -783,186 +783,96 @@
 ker.
-config.okhttp3.OkHttpClientProvider;%0Aimport com.netflix.spinnaker.front50.echo.EchoService;%0Aimport com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger;%0Aimport okhttp3.OkHttpClient
+front50.echo.EchoService;%0Aimport com.netflix.spinnaker.kork.client.ServiceClientProvider
 ;%0Aim
@@ -1123,108 +1123,8 @@
 ion;
-%0Aimport retrofit.Endpoints;%0Aimport retrofit.RestAdapter;%0Aimport retrofit.converter.JacksonConverter;
 %0A%0A/*
@@ -1288,30 +1288,31 @@
 vice(%0A      
-OkHttp
+Service
 ClientProvid
@@ -1314,22 +1314,23 @@
 rovider 
-okHttp
+service
 ClientPr
@@ -1406,570 +1406,184 @@
    O
-kHttpClient okHttpClient =%0A        okHttpClientProvider.getClient(new DefaultServiceEndpoint(%22echo%22, baseUrl));%0A    ObjectMapper objectMapper = new ObjectMapper();%0A    JacksonConverter jacksonConverter = new JacksonConverter(objectMapper);%0A%0A    return new RestAdapter.Builder()%0A        .setEndpoint(Endpoints.newFixedEndpoint(baseUrl))%0A        .setClient(new Ok3Client(okHttpClient))%0A        .setConverter(jacksonConverter)%0A        .setLogLevel(BASIC)%0A        .setLog(new Slf4jRetrofitLogger(EchoService.class))%0A        .build()%0A        .create(EchoService.class
+bjectMapper objectMapper = new ObjectMapper();%0A    return serviceClientProvider.getService(%0A        EchoService.class, new DefaultServiceEndpoint(%22echo%22, baseUrl), objectMapper
 );%0A 

Move to retrofit service client api (#943)