Java 类retrofit.client.Client 实例源码

项目:influxdb-inflow    文件:DriverHTTP.java   
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);
}
项目:lmis-moz-mobile    文件:LMISRestManagerTest.java   
@Test
public void shouldVerify() throws Exception {
    SSLSession sslSession = mock(SSLSession.class);
    X509Certificate certificate = mock(X509Certificate.class);
    Principal principal = new Principal() {
        @Override
        public String getName() {
            return "CN=lmis.cmam.gov.mz";
        }
    };
    when(sslSession.getPeerCertificates()).thenReturn(new Certificate[]{certificate});
    when(certificate.getSubjectDN()).thenReturn(principal);

    LMISRestManagerMock.mockClient = mock(Client.class);
    LMISRestManagerMock lmisRestManagerMock = new LMISRestManagerMock(RuntimeEnvironment.application);
    lmisRestManagerMock.superGetSSLClient();
    assertTrue(lmisRestManagerMock.okHttpClient.getHostnameVerifier().verify("whateverName", sslSession));
}
项目:drupalfit    文件:DrupalOAuth2Manager.java   
public DrupalOAuth2Manager(Context context, String endpoint, String clientId, String clientSecret) {
    setContext(context);
    setEndpoint(endpoint);
    setClientId(clientId);
    setClientSecret(clientSecret);

    Client client = new OkClient(getOkHttpClient());

    if (mRequestInterceptor == null) {
        mRequestInterceptor = new SimpleRequestInterceptor();
    }
    mRequestInterceptor.cookie = cookie;

    RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint(endpoint)
        .setRequestInterceptor(mRequestInterceptor)
        .setErrorHandler(new ErrorHandler())
        .setClient(client)
        .setConverter(new retrofit.converter.JacksonConverter())
        .build();

    mService = restAdapter.create(DrupalOAuth2.class);
}
项目:drupalfit    文件:DrupalManager.java   
public DrupalService getService(String endpoint) {
    if (endpoint == null) return mService;

    if (mService == null) {
        this.endpoint = endpoint;
        Client client = new OkClient(getOkHttpClient());

        if (mRequestInterceptor == null) {
            mRequestInterceptor = new SimpleRequestInterceptor();
        }
        mRequestInterceptor.cookie = cookie;
        mRequestInterceptor.accessToken = accessToken;
        mRequestInterceptor.xcsrfToken = xcsrfToken;

        mService = new RestAdapter.Builder()
            .setEndpoint(endpoint)
            .setRequestInterceptor(mRequestInterceptor)
            .setErrorHandler(new ErrorHandler())
            .setClient(client)
            .setConverter(new retrofit.converter.JacksonConverter())
            .setLogLevel(RestAdapter.LogLevel.FULL)  // Do this for development too.
            .build().create(DrupalService.class);
    }

    return mService;
}
项目:TruckMuncher-Android    文件:ApiErrorHandlerTest.java   
@Test
public void errorWithEmptyBodyDoesNotCrash() {

    TestClient client = new RestAdapter.Builder()
            .setEndpoint("http://example.com")
            .setClient(new Client() {
                @Override
                public Response execute(Request request) throws IOException {
                    return new Response("", 400, "invalid request", Collections.<Header>emptyList(), null);
                }
            })
            .setErrorHandler(errorHandler)
            .setExecutors(new SynchronousExecutor(), new SynchronousExecutor())
            .build()
            .create(TestClient.class);

    try {
        client.getFullMenus();
        failBecauseExceptionWasNotThrown(ApiException.class);
    } catch (ApiException e) {
        assertThat(e.getMessage()).isNull();
        assertThat(e.getCause()).isNotNull();
    }
}
项目:TruckMuncher-Android    文件:ApiErrorHandlerTest.java   
@Test
public void UnauthorizedOnNonAuthRouteThrowsCorrectException() {
    TestClient client = new RestAdapter.Builder()
            .setEndpoint("http://example.com")
            .setClient(new Client() {
                @Override
                public Response execute(Request request) throws IOException {
                    Error apiError = new Error("1234", "Invalid social credentials");
                    TypedInput input = new TypedByteArray("application/x-protobuf", apiError.toByteArray());
                    return new Response("", 401, "invalid request", Collections.<Header>emptyList(), input);
                }
            })
            .setErrorHandler(errorHandler)
            .setExecutors(new SynchronousExecutor(), new SynchronousExecutor())
            .setConverter(new WireConverter())
            .build()
            .create(TestClient.class);

    try {
        client.getFullMenus();
        failBecauseExceptionWasNotThrown(ExpiredSessionException.class);
    } catch (ExpiredSessionException e) {
        // No-op
    }
}
项目:TruckMuncher-Android    文件:AuthErrorHandlerTest.java   
@Test
public void errorWithEmptyBodyDoesNotCrash() {

    TestClient client = new RestAdapter.Builder()
            .setEndpoint("http://example.com")
            .setClient(new Client() {
                @Override
                public Response execute(Request request) throws IOException {
                    return new Response("", 400, "invalid request", Collections.<Header>emptyList(), null);
                }
            })
            .setErrorHandler(errorHandler)
            .setExecutors(new SynchronousExecutor(), new SynchronousExecutor())
            .build()
            .create(TestClient.class);

    try {
        client.getFullMenus();
        failBecauseExceptionWasNotThrown(ApiException.class);
    } catch (ApiException e) {
        assertThat(e.getMessage()).isNull();
        assertThat(e.getCause()).isNotNull();
    }
}
项目:TruckMuncher-Android    文件:AuthErrorHandlerTest.java   
@Test
public void unauthorizedOnAuthRouteThrowsCorrectException() {
    AuthService service = new RestAdapter.Builder()
            .setEndpoint("http://example.com")
            .setClient(new Client() {
                @Override
                public Response execute(Request request) throws IOException {
                    Error apiError = new Error("1234", "Invalid social credentials");
                    TypedInput input = new TypedByteArray("application/x-protobuf", apiError.toByteArray());
                    return new Response("", 401, "invalid request", Collections.<Header>emptyList(), input);
                }
            })
            .setErrorHandler(errorHandler)
            .setExecutors(new SynchronousExecutor(), new SynchronousExecutor())
            .setConverter(new WireConverter())
            .build()
            .create(AuthService.class);

    try {
        service.getAuth(new AuthRequest());
        failBecauseExceptionWasNotThrown(SocialCredentialsException.class);
    } catch (SocialCredentialsException e) {
        // No-op
    }
}
项目:retrofit-jaxrs    文件:RestAdapter.java   
private RestAdapter(Server server, Client.Provider clientProvider, Executor httpExecutor,
                    Executor callbackExecutor, RequestInterceptor requestInterceptor, Converter converter,
                    Profiler profiler, ErrorHandler errorHandler, Log log, LogLevel logLevel)
{
  this.server = server;
  this.clientProvider = clientProvider;
  this.httpExecutor = httpExecutor;
  if (Platform.HAS_RX_JAVA && httpExecutor != null)
  {
    this.rxSupport = new RxSupport(httpExecutor);
  }
  else
  {
    this.rxSupport = null;
  }
  this.callbackExecutor = callbackExecutor;
  this.requestInterceptor = requestInterceptor;
  this.converter = converter;
  this.profiler = profiler;
  this.errorHandler = errorHandler;
  this.log = log;
  this.logLevel = logLevel;
}
项目:retrofit-jaxrs    文件:RestAdapter.java   
/**
 * The HTTP client used for requests.
 */
public Builder setClient(final Client client)
{
  if (client == null)
  {
    throw new NullPointerException("Client may not be null.");
  }
  return setClient(new Client.Provider()
  {
    @Override
    public Client get()
    {
      return client;
    }
  });
}
项目:retrofit-jaxrs    文件:RestAdapterTest.java   
@SuppressWarnings("unchecked") // Mock profiler type erasure.
@Before
public void setUp() throws Exception
{
  mockClient = mock(Client.class);
  mockRequestExecutor = spy(new SynchronousExecutor());
  mockCallbackExecutor = spy(new SynchronousExecutor());
  mockProfiler = mock(Profiler.class);

  example = new RestAdapter.Builder() //
      .setClient(mockClient)
      .setExecutors(mockRequestExecutor, mockCallbackExecutor)
      .setServer("http://example.com")
      .setProfiler(mockProfiler)
      .build()
      .create(Example.class);
}
项目:retrofit-jaxrs    文件:MockRestAdapterTest.java   
@Before
public void setUp() throws IOException
{
  Client client = mock(Client.class);
  doThrow(new AssertionError()).when(client).execute(any(Request.class));

  httpExecutor = spy(new SynchronousExecutor());
  callbackExecutor = spy(new SynchronousExecutor());

  RestAdapter restAdapter = new RestAdapter.Builder() //
      .setClient(client)
      .setExecutors(httpExecutor, callbackExecutor)
      .setServer("http://example.com")
      .setLogLevel(RestAdapter.LogLevel.NONE)
      .build();

  valueChangeListener = mock(ValueChangeListener.class);

  mockRestAdapter = MockRestAdapter.from(restAdapter);
  mockRestAdapter.setValueChangeListener(valueChangeListener);

  // Seed the random with a value so the tests are deterministic.
  mockRestAdapter.random.setSeed(2847);
}
项目:robin-java-sdk    文件:RobinServiceFactoryTest.java   
@Test
public void testCreate4() {
    RobinServiceFactory factory = mock(RobinServiceFactory.class, Mockito.CALLS_REAL_METHODS);
    Credential credential = mock(Credential.class);
    Client client = mock(Client.class);
    HttpUrl endpoint = HttpUrl.parse("http://example.com");

    RestAdapter.Builder builder = mock(RestAdapter.Builder.class, Mockito.CALLS_REAL_METHODS);
    doReturn(builder).when(factory).getRestAdapterBuilder();

    MockService service = factory.create(MockService.class, credential, client, endpoint);
    assertThat(service).isNotNull();

    verify(builder, times(1)).setRequestInterceptor(any(RequestInterceptor.class));
    verify(builder, times(1)).setEndpoint(endpoint.toString());
}
项目:Android_watch_magpie    文件:SecuredRestBuilder.java   
public OAuthHandler(Client client, String tokenIssuingEndpoint, String username,
                    String password, String clientId, String clientSecret) {
    super();
    this.client = client;
    this.tokenIssuingEndpoint = tokenIssuingEndpoint;
    this.username = username;
    this.password = password;
    this.clientId = clientId;
    this.clientSecret = clientSecret;
}
项目:mobile_app_android    文件:RestServiceGenerator.java   
private static Client getClient() {

        return new UrlConnectionClient();
//    OkHttpClient client = new OkHttpClient();
//    client.setConnectTimeout(60, TimeUnit.SECONDS);
//    client.setWriteTimeout(60, TimeUnit.SECONDS);
//    client.setReadTimeout(60, TimeUnit.SECONDS);
//    return new OkClient(client);

    }
项目:Pioneer    文件:ApiModule.java   
@Provides @Singleton
RestAdapter provideRestAdapter(Endpoint endpoint, Client client, ErrorHandler errorHandler) {
    return new RestAdapter.Builder() //
            .setClient(client) //
            .setEndpoint(endpoint) //
            .setErrorHandler(errorHandler)
            .build();
}
项目:uphold-sdk-android    文件:MockRestAdapter.java   
public MockRestAdapter(final String responseString, final HashMap<String, String> headers) {
    this.exceptionReference = new AtomicReference<>();
    this.requestReference = new AtomicReference<>();
    this.resultReference = new AtomicReference<>();
    this.mockRestAdapter = new UpholdRestAdapter();
    this.restAdapter = new RestAdapter.Builder().setEndpoint(BuildConfig.API_SERVER_URL)
        .setRequestInterceptor(this.mockRestAdapter.getUpholdRequestInterceptor())
        .setClient(new Client() {
            @Override
            public Response execute(Request request) throws IOException {
                requestReference.set(request);

                return new Response("some/url", 200, "reason", new ArrayList<Header>() {{
                    if (headers != null) {
                        for (Map.Entry<String, String> entry : headers.entrySet()) {
                            String key = entry.getKey();
                            String value = entry.getValue();

                            add(new retrofit.client.Header(key, value));
                        }
                    }
                }}, new TypedByteArray("application/json", responseString == null ? new byte[0] : responseString.getBytes()));
            }
    }).build();

    this.mockRestAdapter.setAdapter(this.restAdapter);
}
项目:Bakery    文件:ApiModule.java   
@Provides
Client provideApiClient() {
    OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);

    return new OkClient(okHttpClient);
}
项目:dagger2-scopes    文件:AuthModule.java   
@Provides @ApplicationScope AuthService provideAuthRestAdapter(Client client, Converter converter) {
    MockRestAdapter mockRestAdapter = MockRestAdapter.from(
            new RestAdapter.Builder().setClient(client).setConverter(converter).setLogLevel(RestAdapter.LogLevel.BASIC).setLog(new RestAdapter.Log() {
                @Override public void log(String message) {
                    Timber.d(message);
                }
            }).setEndpoint("https://alexrwegener.com/").build());
    mockRestAdapter.setDelay(100);
    return mockRestAdapter.create(AuthService.class, new MockAuthService());
}
项目:sendtopulsar    文件:ApiModule.java   
public static RestAdapter buildBasicRestAdapter(PulsarEndpoint endpoint, Client client, RestErrorHandler errorHandler) {
    String endpointString = endpoint.get();
    System.out.println("setting endpoint as " + endpointString);
    return new RestAdapter.Builder()
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setClient(client)
            .setEndpoint(endpointString)
            .setConverter(new JacksonConverter(JsonUtils.objectMapper))
            .setErrorHandler(errorHandler)
            .build();
}
项目:infobip-api-java-client    文件:TimeoutClientProvider.java   
@Override
public Client get() {
    final OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.setReadTimeout(configuration.getReadTimeout(), TimeUnit.MILLISECONDS);
    okHttpClient.setConnectTimeout(configuration.getConnectionTimeout(), TimeUnit.MILLISECONDS);
    return new OkClient(okHttpClient);
}
项目:mobilecloud-15    文件:SecuredRestBuilder.java   
public OAuthHandler(Client client, String tokenIssuingEndpoint, String username,
        String password, String clientId, String clientSecret) {
    super();
    this.client = client;
    this.tokenIssuingEndpoint = tokenIssuingEndpoint;
    this.username = username;
    this.password = password;
    this.clientId = clientId;
    this.clientSecret = clientSecret;
}
项目:mobilecloud-15    文件:SecuredRestBuilder.java   
public OAuthHandler(Client client, String tokenIssuingEndpoint, String username,
        String password, String clientId, String clientSecret) {
    super();
    this.client = client;
    this.tokenIssuingEndpoint = tokenIssuingEndpoint;
    this.username = username;
    this.password = password;
    this.clientId = clientId;
    this.clientSecret = clientSecret;
}
项目:mobilecloud-15    文件:SecuredRestBuilder.java   
public OAuthHandler(Client client, String tokenIssuingEndpoint, String username,
        String password, String clientId, String clientSecret) {
    super();
    this.client = client;
    this.tokenIssuingEndpoint = tokenIssuingEndpoint;
    this.username = username;
    this.password = password;
    this.clientId = clientId;
    this.clientSecret = clientSecret;
}
项目:gojira    文件:ApiModule.java   
@Provides
@Singleton
RestAdapter provideRestAdapter(Endpoint endpoint, Client client, Gson gson, SharedPreferences preferences) {
    return new RestAdapter.Builder()
            .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.HEADERS : RestAdapter.LogLevel.NONE)
            .setClient(client)
            .setConverter(new GsonConverter(gson))
            .setRequestInterceptor(new ApiHeaders())
            .setEndpoint(endpoint)
            .build();
}
项目:android-discourse    文件:RestAdapter.java   
private RestAdapter(Server server, Client.Provider clientProvider, Executor httpExecutor, Executor callbackExecutor, RequestInterceptor requestInterceptor, Converter converter, Profiler profiler, ErrorHandler errorHandler, Log log, LogLevel logLevel) {
    this.server = server;
    this.clientProvider = clientProvider;
    this.httpExecutor = httpExecutor;
    this.callbackExecutor = callbackExecutor;
    this.requestInterceptor = requestInterceptor;
    this.converter = converter;
    this.profiler = profiler;
    this.errorHandler = errorHandler;
    this.log = log;
    this.logLevel = logLevel;
}
项目:android-discourse    文件:RestAdapter.java   
/**
 * The HTTP client used for requests.
 */
public Builder setClient(final Client client) {
    if (client == null) {
        throw new NullPointerException("Client may not be null.");
    }
    return setClient(new Client.Provider() {
        @Override
        public Client get() {
            return client;
        }
    });
}
项目:android-discourse    文件:RestAdapter.java   
/**
 * The HTTP client used for requests.
 */
public Builder setClient(Client.Provider clientProvider) {
    if (clientProvider == null) {
        throw new NullPointerException("Client provider may not be null.");
    }
    this.clientProvider = clientProvider;
    return this;
}
项目:Mover    文件:BaseNetworkJob.java   
public static <T> T create(String endpoint, Class<T> service, Client client){
    RestAdapter adapter = new RestAdapter.Builder()
            .setEndpoint(endpoint)
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setClient(client)
            .build();

    return adapter.create(service);
}
项目:dagger2-example    文件:ApiModule.java   
@Provides
@Singleton
RestAdapter provideRestAdapter(Endpoint endpoint, Client client) {
    return new RestAdapter.Builder()
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setEndpoint(endpoint)
            .build();
}
项目:BitcoinBlue    文件:ApiModule.java   
@Provides
@Singleton
Client provideClient(OkHttpClient client) {
    client = new OkHttpClient();
    client.setConnectTimeout(30, TimeUnit.SECONDS); // connect timeout
    client.setReadTimeout(30, TimeUnit.SECONDS);    // socket timeout
    client.setConnectionPool(new ConnectionPool(0, 5 * 60 * 1000));
    return new OkClient(client);
}
项目:BitcoinBlue    文件:ApiModule.java   
@Provides
@Singleton
BitcoinAverage provideBitcoinAverage(Client client) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setEndpoint(BITCOIN_AVERAGE_API_ENDPOINT)
            .build();
    return restAdapter.create(BitcoinAverage.class);
}
项目:BitcoinBlue    文件:ApiModule.java   
@Provides
@Singleton
CoinbaseMarket provideCoinbaseMarket(Client client) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.NONE)
            .setEndpoint(COINBASE_API_ENDPOINT)
            .build();
    return restAdapter.create(CoinbaseMarket.class);
}
项目:BitcoinBlue    文件:ApiModule.java   
@Provides
@Singleton
BitstampExchange provideBitstampExchange(Client client) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.NONE)
            .setEndpoint(BITSTAMP_API_ENDPOINT)
            .build();
    return restAdapter.create(BitstampExchange.class);
}
项目:BitcoinBlue    文件:ApiModule.java   
@Provides
@Singleton
Bluelytics provideBluelytics(Client client) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.NONE)
            .setEndpoint(BLUELYTICS_API_ENDPOINT)
            .build();
    return restAdapter.create(Bluelytics.class);
}
项目:AndroidMvp    文件:GithubModule.java   
@ApplicationScope
@Provides
protected GithubApi provideGithubApi(Client client, Gson gson) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
            .setClient(client)
            .setConverter(new GsonConverter(gson))
            .setEndpoint("https://api.github.com")
            .build();

    return restAdapter.create(GithubApi.class);
}
项目:AndroidMvp    文件:BitbucketModule.java   
@ApplicationScope
@Provides
protected BitbucketApi provideGithubApi(Client client, Gson gson) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
            .setClient(client)
            .setConverter(new GsonConverter(gson))
            .setEndpoint("https://api.bitbucket.org/2.0")
            .build();

    return restAdapter.create(BitbucketApi.class);
}
项目:sphere-android-sdk    文件:AuthServiceImpl.java   
public AuthServiceImpl(SphereAuthConfig sphereAuthConfig, Client client) {
    this.sphereAuthConfig = sphereAuthConfig;
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(client)
            .setEndpoint(sphereAuthConfig.getAuthUrl()).build();
    this.authAPIService = restAdapter.create(AuthAPIService.class);
}
项目:Pioneer    文件:ApiModule.java   
@Provides @Singleton
RestAdapter provideRestAdapter(Endpoint endpoint, Client client, ErrorHandler errorHandler) {
    return new RestAdapter.Builder() //
            .setClient(client) //
            .setEndpoint(endpoint) //
            .setErrorHandler(errorHandler)
            .build();
}
项目:chuck-norris-jokes-app    文件:ApiModule.java   
@Provides @Singleton
RestAdapter provideRestAdapter(Client client, Endpoint endpoint, Converter converter) {
    return new RestAdapter.Builder()
            .setClient(client)
            .setEndpoint(endpoint)
            .setConverter(converter)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build();
}