当前位置: 首页>>代码示例>>Java>>正文


Java OkClient类代码示例

本文整理汇总了Java中retrofit.client.OkClient的典型用法代码示例。如果您正苦于以下问题:Java OkClient类的具体用法?Java OkClient怎么用?Java OkClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OkClient类属于retrofit.client包,在下文中一共展示了OkClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRealTokenService

import retrofit.client.OkClient; //导入依赖的package包/类
/**
 * Return a instance of tokenService to call it
 * 
 * @param authority
 * @return TokenService return a proxy to call api
 */
private static TokenService getRealTokenService(String authority) {
	// Create a logging interceptor to log request and responses
	OkHttpClient client = new OkHttpClient();
	InetSocketAddress p = findProxy();
	if(p != null) {
		client.setProxy(new Proxy(Proxy.Type.HTTP,p));
	} else { 
		client.setProxy(Proxy.NO_PROXY); 
	}
	// Create and configure the Retrofit object
	RestAdapter retrofit = new RestAdapter.Builder().setEndpoint(authority)
			.setLogLevel(LogLevel.FULL).setLog(new RestAdapter.Log() {
				@Override
				public void log(String msg) {
					logger.debug(msg);
				}
			}).setClient(new OkClient(client)).build();

	// Generate the token service
	return retrofit.create(TokenService.class);
}
 
开发者ID:OwaNotifier,项目名称:owa-notifier,代码行数:28,代码来源:RestfullAcessProxy.java

示例2: getRestAdapter

import retrofit.client.OkClient; //导入依赖的package包/类
private static RestAdapter getRestAdapter() {

        RequestInterceptor requestInterceptor = new RequestInterceptor() {
            @Override
            public void intercept(RequestFacade request) {
                request.addHeader(Constant.TAG_TOKEN, Constant.APP_TOKEN);
            }
        };

        return new RestAdapter.Builder()
                .setLogLevel(LOG_LEVEL)
                .setEndpoint(RetroInterface.TARGET_URL)
                .setRequestInterceptor(requestInterceptor)
                .setClient(new OkClient(new OkHttpClient()))
                .build();
    }
 
开发者ID:PacktPublishing,项目名称:Expert-Android-Programming,代码行数:17,代码来源:RetroInterface.java

示例3: getImageApiAdapter

import retrofit.client.OkClient; //导入依赖的package包/类
private static RestAdapter getImageApiAdapter() {

        RequestInterceptor requestInterceptor = new RequestInterceptor() {
            @Override
            public void intercept(RequestFacade request) {
                request.addHeader(Constant.TAG_TOKEN, Constant.APP_TOKEN);
            }
        };

        return new RestAdapter.Builder()
                .setLogLevel(LOG_LEVEL)
                .setEndpoint(RetroInterface.TARGET_URL)
                .setRequestInterceptor(requestInterceptor)
                .setClient(new OkClient(new OkHttpClient()))
                .build();
    }
 
开发者ID:PacktPublishing,项目名称:Expert-Android-Programming,代码行数:17,代码来源:RetroInterface.java

示例4: create

import retrofit.client.OkClient; //导入依赖的package包/类
public static <T> T create(final Context context, String baseUrl, Class<T> clazz) {
    final OkHttpClient okHttpClient = new OkHttpClient();

    okHttpClient.setCache(new Cache(context.getApplicationContext().getCacheDir(),
            CACHE_SIZE));
    okHttpClient.setConnectTimeout(40, TimeUnit.SECONDS);

    RequestInterceptor interceptor = new RequestInterceptor() {
        @Override
        public void intercept(RequestFacade request) {
            //7-days cache
            request.addHeader("Cache-Control", String.format("max-age=%d,max-stale=%d", Integer.valueOf(60 * 60 * 24 * 7), Integer.valueOf(31536000)));
            request.addHeader("Connection", "keep-alive");
        }
    };

    RestAdapter.Builder builder = new RestAdapter.Builder()
            .setEndpoint(baseUrl)
            .setRequestInterceptor(interceptor)
            .setClient(new OkClient(okHttpClient));

    return builder
            .build()
            .create(clazz);

}
 
开发者ID:rohanoid5,项目名称:Muzesto,代码行数:27,代码来源:RestServiceFactory.java

示例5: fiatService

import retrofit.client.OkClient; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(FiatService.class) // Allows for override
public FiatService fiatService(FiatClientConfigurationProperties fiatConfigurationProperties,
                               SpinnakerRequestInterceptor interceptor,
                               OkClient okClient) {
  // New role providers break deserialization if this is not enabled.
  val objectMapper = new ObjectMapper();
  objectMapper.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL);
  objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
  return new RestAdapter.Builder()
      .setEndpoint(Endpoints.newFixedEndpoint(fiatConfigurationProperties.getBaseUrl()))
      .setRequestInterceptor(interceptor)
      .setClient(okClient)
      .setConverter(new JacksonConverter(objectMapper))
      .setLogLevel(retrofitLogLevel)
      .setLog(new Slf4jRetrofitLogger(FiatService.class))
      .build()
      .create(FiatService.class);
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:20,代码来源:FiatAuthenticationConfig.java

示例6: ServiceBaseService

import retrofit.client.OkClient; //导入依赖的package包/类
ServiceBaseService() {

        final OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setReadTimeout(30, TimeUnit.SECONDS);
        okHttpClient.setConnectTimeout(15, TimeUnit.SECONDS);
        okHttpClient.setRetryOnConnectionFailure(true);
        okHttpClient.setFollowRedirects(false);
        okHttpClient.interceptors().add(new ConnectionRetryInterceptor());

        RestAdapter mRestAdapter = new RestAdapter.Builder()
                .setEndpoint(ApiConnectionInterface.BASE_API_URL)
                .setClient(new OkClient(okHttpClient))
                .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new RestAdapter.Log() {
                    @Override
                    public void log(String msg) {
                        Log.d("SIMPLE_MAP_APP", msg);
                    }
                })
                .build();

        mServiceInterface = mRestAdapter.create(ApiConnectionInterface.class);
    }
 
开发者ID:gkaffka,项目名称:simple-map-android,代码行数:23,代码来源:ServiceBaseService.java

示例7: createRestClient

import retrofit.client.OkClient; //导入依赖的package包/类
/**
 * Creates a REST client.
 * @param url The URL of the EDD Licensing REST API endpoint.
 * @return A {@link EDDLicensingClient}.
 */
public static EDDLicensingClient createRestClient(String url) {
	
	 Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create();
	 
	RestAdapter restAdapter = new RestAdapter.Builder()
               .setEndpoint(url)
               .setConverter(new GsonConverter(gson))
               .setClient(new OkClient(new OkHttpClient()))
               .build();
	
	EDDLicensingClient client = restAdapter.create(EDDLicensingClient.class);
	
	return client;
	
}
 
开发者ID:jzonthemtn,项目名称:edd-licensing-java-client,代码行数:23,代码来源:EDDLicensingClientFactory.java

示例8: BaiduBrowserNovelSource

import retrofit.client.OkClient; //导入依赖的package包/类
public BaiduBrowserNovelSource(OkHttpClient okHttpClient) {
    /*this.mOkHttpClient = new OkHttpClient();
    this.mOkHttpClient.setConnectTimeout(20, TimeUnit.SECONDS);
    this.mOkHttpClient.setWriteTimeout(20, TimeUnit.SECONDS);
    this.mOkHttpClient.setReadTimeout(20, TimeUnit.SECONDS);*/
    this.mNovelSource = new RestAdapter.Builder()
            .setRequestInterceptor(request -> {
                request.addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19");
                request.addHeader("Accept", "application/json,text/html");
            })
            .setEndpoint(BaiduBrowserService.BAIDU_BROWSER_NOVEL_URL)
            .setClient(new OkClient(okHttpClient))
            .setConverter(new CustomGsonConverter(new Gson()))
            .build()
            .create(BaiduBrowserService.class);
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:17,代码来源:BaiduBrowserNovelSource.java

示例9: getRestAdapter

import retrofit.client.OkClient; //导入依赖的package包/类
/**
 * Initializes the adapter and returns it
 * The REST Adapter is created with Retrofit methods defined in MainApiClient
 * Injects authorization headers into request
 * Inspects status codes from response
 * @return rest adapter
 */
private MainApiClient getRestAdapter() {

    httpClient = new OkHttpClient();
    httpClient.networkInterceptors().add(new StethoInterceptor());
    httpClient.interceptors().add(new Interceptor() {
        @Override
        public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            com.squareup.okhttp.Response response = chain.proceed(request);
            statusCode = response.code();
            return response;
        }
    });

    mRestAdapter = new RestAdapter.Builder()
            .setEndpoint(URL_UAT)
            .setClient(new OkClient(httpClient))
            .setRequestInterceptor(authHeader())
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build();

    return mRestAdapter.create(MainApiClient.class);
}
 
开发者ID:iem-devs,项目名称:apna-library,代码行数:31,代码来源:ApiClient.java

示例10: getInterface

import retrofit.client.OkClient; //导入依赖的package包/类
/**
 * Function to authenticate any communication with the server.
 * @param username
 * @param password
 * @return The interface that verifies the authentication
 */
public static Interface getInterface(String username, String password) {
    String credentials = username+":"+password;
    RestAdapter.Builder builder = new RestAdapter.Builder()
            .setEndpoint(SERVER_URL)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setClient(new OkClient(clientOkHttp));
    clientOkHttp.setReadTimeout(60, TimeUnit.SECONDS);
    clientOkHttp.setConnectTimeout(60, TimeUnit.SECONDS);

    // create Base64 encode string
    final String basic =
            "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    builder.setRequestInterceptor(new RequestInterceptor() {
        @Override
        public void intercept(RequestInterceptor.RequestFacade request) {
            request.addHeader("Authorization", basic);
            request.addHeader("Accept", "application/json");
        }
    });
    RestAdapter adapter = builder.build();
    Interface communicatorInterface = adapter.create(Interface.class);
    return communicatorInterface;
}
 
开发者ID:thandile,项目名称:msf_communique,代码行数:31,代码来源:Auth.java

示例11: DriverHTTP

import retrofit.client.OkClient; //导入依赖的package包/类
public DriverHTTP(final String uri, final String username, final String password, Client client) {
  Preconditions.checkArgument(!Strings.isNullOrEmpty(uri), "URI can not be null or empty");
  Preconditions.checkArgument(!Strings.isNullOrEmpty(username), "Username can not null or empty");

  this.uri = uri;
  this.username = username;
  this.password = password;

  if (this.client == null) {
    this.client = new OkClient(new OkHttpClient());
  } else {
    this.client = client;
  }

  this.restAdapter = new RestAdapter.Builder()
          .setEndpoint(this.uri)
          .setErrorHandler(new InfluxDBHTTPErrorHandler())
          .setClient(this.client)
          .build();
  this.restService = this.restAdapter.create(InfluxDBHTTPInterface.class);
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:22,代码来源:DriverHTTP.java

示例12: Client

import retrofit.client.OkClient; //导入依赖的package包/类
public Client(String host, int port, String username, String password, boolean useHttps, boolean verifySSL, int timeout) {
  this.host = host;
  this.port = port;
  this.username = username;
  this.password = password;
  this.timeout = timeout;
  this.verifySSL = verifySSL;

  if (useHttps) {
    this.scheme = "https";
  }

  // the the base URI
  this.baseURI = String.format("%s://%s:%d", this.scheme, this.host, this.port);

  // set the default driver to HTTP
  OkHttpClient okHttpClient = new OkHttpClient();
  okHttpClient.setReadTimeout(timeout, TimeUnit.SECONDS);
  // TODO: how to enforce verifySSL with OkHttpClient ?
  OkClient okClient = new OkClient(okHttpClient);
  this.driver = new DriverHTTP(this.baseURI, this.username, this.password, okClient);

  this.admin = new Admin(this);
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:25,代码来源:Client.java

示例13: setUp

import retrofit.client.OkClient; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    ShadowLog.stream = System.out;

    mockWebServer = new MockWebServer();
    mockWebServer.start(9999);

    baseRetryHandler = BaseRetryHandler_.getInstance_(RuntimeEnvironment.application);
    connectivityAwareUrlClient = ConnectivityAwareUrlClient_.getInstance_(RuntimeEnvironment.application);
    connectivityAwareUrlClient.setWrappedClient(new OkClient(new OkHttpClient()));
    connectivityAwareUrlClient.setRetryHandler(baseRetryHandler);


    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(connectivityAwareUrlClient)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setEndpoint(mockWebServer.getUrl("/").toString()).build();

    sodaService = restAdapter.create(SodaService.class);
}
 
开发者ID:richardradics,项目名称:MVPAndroidBootstrap,代码行数:21,代码来源:ConnectivityAwereUrlClientTest.java

示例14: setUp

import retrofit.client.OkClient; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    RxSnappy.init(getContext());
    mockWebServer = new MockWebServer();
    mockWebServer.start(9812);

    OkHttpClient okHttpClient = new OkHttpClient();
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(new OkClient(okHttpClient))
            .setEndpoint(mockWebServer.getUrl("/").toString())
            .build();

    testRestAdapter = restAdapter.create(TestRestAdapter.class);

    rxSnappyClient = new RxSnappyClient();
}
 
开发者ID:team-supercharge,项目名称:rxsnappy,代码行数:18,代码来源:WorkingWithRetrofitTest.java

示例15: UpholdRestAdapter

import retrofit.client.OkClient; //导入依赖的package包/类
/**
 * Constructor.
 */

public UpholdRestAdapter() {
    OkHttpClient okHttpClient = new OkHttpClient();

    try {
        okHttpClient.setSslSocketFactory(new TLSV12SSLSocketFactory());
    } catch (NoSuchAlgorithmException | KeyManagementException exception) {
        exception.printStackTrace();
    }

    this.adapter = new RestAdapter.Builder().setEndpoint(BuildConfig.API_SERVER_URL)
        .setClient(new OkClient(okHttpClient))
        .setErrorHandler(new UpholdRetrofitErrorHandling())
        .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
        .setRequestInterceptor(getUpholdRequestInterceptor())
        .build();
}
 
开发者ID:uphold,项目名称:uphold-sdk-android,代码行数:21,代码来源:UpholdRestAdapter.java


注:本文中的retrofit.client.OkClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。