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


Java Header类代码示例

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


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

示例1: handleNon404s

import retrofit.client.Header; //导入依赖的package包/类
private void handleNon404s(RetrofitError e) {
  String msg = "";
  if (e.getKind() == RetrofitError.Kind.NETWORK) {
    msg = String.format("Could not find the server %s", gitHubProperties.getBaseUrl());
  } else if (e.getResponse().getStatus() == 401) {
    msg = "HTTP 401 Unauthorized.";
  } else if (e.getResponse().getStatus() == 403) {
    val rateHeaders = e.getResponse()
                       .getHeaders()
                       .stream()
                       .filter(header -> RATE_LIMITING_HEADERS.contains(header.getName()))
                       .map(Header::toString)
                       .collect(Collectors.toList());

    msg = "HTTP 403 Forbidden. Rate limit info: " + StringUtils.join(rateHeaders, ", ");
  }
  log.error(msg, e);
}
 
开发者ID:spinnaker,项目名称:fiat,代码行数:19,代码来源:GithubTeamsUserRolesProvider.java

示例2: createRequest

import retrofit.client.Header; //导入依赖的package包/类
static okhttp3.Request createRequest(Request request) {
  RequestBody requestBody;
  if (requiresRequestBody(request.getMethod()) && request.getBody() == null) {
    requestBody = RequestBody.create(null, NO_BODY);
  } else {
    requestBody = createRequestBody(request.getBody());
  }

  okhttp3.Request.Builder builder = new okhttp3.Request.Builder()
      .url(request.getUrl())
      .method(request.getMethod(), requestBody);

  List<Header> headers = request.getHeaders();
  for (int i = 0, size = headers.size(); i < size; i++) {
    Header header = headers.get(i);
    String value = header.getValue();
    if (value == null) {
      value = "";
    }
    builder.addHeader(header.getName(), value);
  }

  return builder.build();
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:25,代码来源:Ok3Client.java

示例3: responseNoContentType

import retrofit.client.Header; //导入依赖的package包/类
@Test public void responseNoContentType() throws IOException {
  okhttp3.Response okResponse = new okhttp3.Response.Builder()
      .code(200).message("OK")
      .body(new TestResponseBody("hello", null))
      .addHeader("foo", "bar")
      .addHeader("kit", "kat")
      .protocol(Protocol.HTTP_1_1)
      .request(new okhttp3.Request.Builder()
          .url(HOST + "/foo/bar/")
          .get()
          .build())
      .build();
  Response response = Ok3Client.parseResponse(okResponse);

  assertThat(response.getUrl()).isEqualTo(HOST + "/foo/bar/");
  assertThat(response.getStatus()).isEqualTo(200);
  assertThat(response.getReason()).isEqualTo("OK");
  assertThat(response.getHeaders()) //
      .containsExactly(new Header("foo", "bar"), new Header("kit", "kat"));
  TypedInput responseBody = response.getBody();
  assertThat(responseBody.mimeType()).isNull();
  assertThat(buffer(source(responseBody.in())).readUtf8()).isEqualTo("hello");
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:24,代码来源:Ok3ClientTest.java

示例4: emptyResponse

import retrofit.client.Header; //导入依赖的package包/类
@Test public void emptyResponse() throws IOException {
  okhttp3.Response okResponse = new okhttp3.Response.Builder()
      .code(200)
      .message("OK")
      .body(new TestResponseBody("", null))
      .addHeader("foo", "bar")
      .addHeader("kit", "kat")
      .protocol(Protocol.HTTP_1_1)
      .request(new okhttp3.Request.Builder()
          .url(HOST + "/foo/bar/")
          .get()
          .build())
      .build();
  Response response = Ok3Client.parseResponse(okResponse);

  assertThat(response.getUrl()).isEqualTo(HOST + "/foo/bar/");
  assertThat(response.getStatus()).isEqualTo(200);
  assertThat(response.getReason()).isEqualTo("OK");
  assertThat(response.getHeaders()) //
      .containsExactly(new Header("foo", "bar"), new Header("kit", "kat"));
  assertThat(response.getBody()).isNull();
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:23,代码来源:Ok3ClientTest.java

示例5: get

import retrofit.client.Header; //导入依赖的package包/类
@Test public void get() throws InterruptedException, IOException {
  server.enqueue(new MockResponse()
      .addHeader("Hello", "World")
      .setBody("Hello!"));

  Response response = service.get();
  assertThat(response.getStatus()).isEqualTo(200);
  assertThat(response.getReason()).isEqualTo("OK");
  assertThat(response.getUrl()).isEqualTo(server.url("/").toString());
  assertThat(response.getHeaders()).contains(new Header("Hello", "World"));
  assertThat(buffer(source(response.getBody().in())).readUtf8()).isEqualTo("Hello!");

  RecordedRequest request = server.takeRequest();
  assertThat(request.getMethod()).isEqualTo("GET");
  assertThat(request.getPath()).isEqualTo("/");
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:17,代码来源:Ok3ClientIntegrationTest.java

示例6: post

import retrofit.client.Header; //导入依赖的package包/类
@Test public void post() throws IOException, InterruptedException {
  server.enqueue(new MockResponse()
      .addHeader("Hello", "World")
      .setBody("Hello!"));

  Response response = service.post(new TypedString("Hello?"));
  assertThat(response.getStatus()).isEqualTo(200);
  assertThat(response.getReason()).isEqualTo("OK");
  assertThat(response.getUrl()).isEqualTo(server.url("/").toString());
  assertThat(response.getHeaders()).contains(new Header("Hello", "World"));
  assertThat(buffer(source(response.getBody().in())).readUtf8()).isEqualTo("Hello!");

  RecordedRequest request = server.takeRequest();
  assertThat(request.getMethod()).isEqualTo("POST");
  assertThat(request.getPath()).isEqualTo("/");
  assertThat(request.getBody().readUtf8()).isEqualTo("Hello?");
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:18,代码来源:Ok3ClientIntegrationTest.java

示例7: emptyBody

import retrofit.client.Header; //导入依赖的package包/类
@Test public void emptyBody() throws IOException, InterruptedException {
  server.enqueue(new MockResponse()
                     .addHeader("Hello", "World")
                     .setBody("Hello!"));

  Response response = service.post();
  assertThat(response.getReason()).isEqualTo("OK");
  assertThat(response.getUrl()).isEqualTo(server.url("/").toString());
  assertThat(response.getHeaders()).contains(new Header("Hello", "World"));
  assertThat(buffer(source(response.getBody().in())).readUtf8()).isEqualTo("Hello!");

  RecordedRequest request = server.takeRequest();
  assertThat(request.getMethod()).isEqualTo("POST");
  assertThat(request.getPath()).isEqualTo("/");
  assertThat(request.getBody().readUtf8()).isEqualTo("");
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:17,代码来源:Ok3ClientIntegrationTest.java

示例8: usersAndUploadedBy

import retrofit.client.Header; //导入依赖的package包/类
@Override
public void usersAndUploadedBy(@Query("cursor") String cursor,
                               @Query("count") Integer count, Callback<Contacts> cb) {
    final Contacts data;

    if (cursor == null) {
        // First page:
        data = getContactsPages().get("");
    } else {
        // Subsequent pages
        data = getContactsPages().get(cursor);
    }

    final Response response = new Response("/1.1/contacts/users_and_uploaded_by.json", 200,
            "ok", Collections.<Header>emptyList(), new TypedByteArray("application/json",
            new Gson().toJson(data).getBytes()));
    cb.success(data, response);

}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:20,代码来源:MockApiInterface.java

示例9: testExecuteRequest_successAndMailRequestDisabled

import retrofit.client.Header; //导入依赖的package包/类
public void testExecuteRequest_successAndMailRequestDisabled() throws Exception {
    final DigitsCallback callback = executeRequest();
    final Response response = new Response(TWITTER_URL, HttpURLConnection.HTTP_ACCEPTED, "",
            new ArrayList<Header>(), null);
    final DigitsUser user = new DigitsUser(USER_ID, "");
    callback.success(user, response);
    verify(digitsEventCollector).signupSuccess(digitsEventDetailsArgumentCaptor.capture());
    final DigitsEventDetails digitsEventDetails = digitsEventDetailsArgumentCaptor.getValue();
    assertNotNull(digitsEventDetails.elapsedTimeInMillis);
    assertEquals(sessionManager.isSet(), true);
    verify(sendButton).showFinish();
    final ArgumentCaptor<Runnable> runnableArgumentCaptor = ArgumentCaptor.forClass
            (Runnable.class);
    verify(phoneEditText).postDelayed(runnableArgumentCaptor.capture(),
            eq(DigitsControllerImpl.POST_DELAY_MS));
    final Runnable runnable = runnableArgumentCaptor.getValue();
    runnable.run();

    final ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class);
    verify(resultReceiver).send(eq(LoginResultReceiver.RESULT_OK),
            bundleArgumentCaptor.capture());
    assertEquals(PHONE_WITH_COUNTRY_CODE, bundleArgumentCaptor.getValue().getString
            (DigitsClient.EXTRA_PHONE));
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:25,代码来源:ConfirmationCodeControllerTests.java

示例10: testExecuteRequest_successAndMailRequestEnabled

import retrofit.client.Header; //导入依赖的package包/类
public void testExecuteRequest_successAndMailRequestEnabled() throws Exception {
    controller = new DummyConfirmationCodeController(resultReceiver, sendButton, resendButton,
            callMeButton, phoneEditText, PHONE_WITH_COUNTRY_CODE, sessionManager,
            digitsClient, errors, new ActivityClassManagerImp(), digitsEventCollector, true,
            timerTextView, digitsEventDetailsBuilder);

    final Response response = new Response(TWITTER_URL, HttpURLConnection.HTTP_OK, "",
            new ArrayList<Header>(), null);
    final DigitsUser user = new DigitsUser(USER_ID, "");

    final DigitsCallback callback = executeRequest();
    callback.success(user, response);

    verify(digitsEventCollector).signupSuccess(digitsEventDetailsArgumentCaptor.capture());
    final DigitsEventDetails digitsEventDetails = digitsEventDetailsArgumentCaptor.getValue();
    assertNotNull(digitsEventDetails.elapsedTimeInMillis);
    assertEquals(sessionManager.isSet(), true);
    verify(sendButton).showFinish();
    verify(context).startActivityForResult(intentCaptor.capture(),
            eq(DigitsActivity.REQUEST_CODE));
    final Intent intent = intentCaptor.getValue();
    assertEquals(resultReceiver,
            intent.getParcelableExtra(DigitsClient.EXTRA_RESULT_RECEIVER));
    assertEquals(PHONE_WITH_COUNTRY_CODE, intent.getStringExtra(DigitsClient.EXTRA_PHONE));
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:26,代码来源:ConfirmationCodeControllerTests.java

示例11: testExecuteRequest_failure

import retrofit.client.Header; //导入依赖的package包/类
public void testExecuteRequest_failure() throws Exception {
    controller = new DummyConfirmationCodeController(resultReceiver, sendButton, resendButton,
            callMeButton, phoneEditText, PHONE_WITH_COUNTRY_CODE, sessionManager,
            digitsClient, errors, new ActivityClassManagerImp(), digitsEventCollector, true,
            timerTextView, digitsEventDetailsBuilder);

    final Response response = new Response(TWITTER_URL, HttpURLConnection.HTTP_OK, "",
            new ArrayList<Header>(), null);
    final DigitsUser user = new DigitsUser(USER_ID, "");

    final DigitsCallback callback = executeRequest();
    callback.failure(TestConstants.ANY_EXCEPTION);
    verify(callMeButton).showError();
    verify(resendButton).showError();
    verify(sendButton).showError();
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:17,代码来源:ConfirmationCodeControllerTests.java

示例12: testCreate_user

import retrofit.client.Header; //导入依赖的package包/类
@Test
public void testCreate_user() throws Exception {
    final ArrayList<Header> headers = new ArrayList<>();
    headers.add(new Header(ANY_HEADER, ANY_DATA));
    headers.add(new Header(DigitsSession.TOKEN_HEADER, TestConstants.TOKEN));
    headers.add(new Header(DigitsSession.SECRET_HEADER, TestConstants.SECRET));

    final Response response = new Response(TestConstants.TWITTER_URL,
            HttpURLConnection.HTTP_ACCEPTED, "", headers, null);
    final DigitsUser user = new DigitsUser(TestConstants.USER_ID,
            DigitsSession.DEFAULT_PHONE_NUMBER);
    final DigitsSession session = DigitsSession.create(new Result<>(user, response),
            TestConstants.PHONE);
    final DigitsSession newSession = new DigitsSession(new TwitterAuthToken(TestConstants.TOKEN,
            TestConstants.SECRET),
            TestConstants.USER_ID, TestConstants.PHONE, DigitsSession.DEFAULT_EMAIL);
    assertEquals(session, newSession);
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:19,代码来源:DigitsSessionTests.java

示例13: checkRefresh

import retrofit.client.Header; //导入依赖的package包/类
private <E extends EntityType, T extends TokenType> void checkRefresh(final TokenProxy<E, T> tokenProxy, final Response response) {
    final List<Header> headers = response.getHeaders();

    for(final Header header : headers) {
        if(TOKEN_HEADER_NAME.equals(header.getName())) {
            try {
                final AuthenticationToken.Json parsedHeader = objectMapper.readValue(header.getValue(), AuthenticationToken.Json.class);
                final AuthenticationToken<E, T> token = parsedHeader.buildToken(tokenProxy.getEntityType(), tokenProxy.getTokenType());
                tokenRepository.update(tokenProxy, token);
            } catch (final IOException e) {
                throw new TokenRepositoryException(e);
            }

            break;
        }
    }
}
 
开发者ID:hpe-idol,项目名称:java-hod-client,代码行数:18,代码来源:ResponseParser.java

示例14: postDashboard

import retrofit.client.Header; //导入依赖的package包/类
private void postDashboard(Dashboard dashboard) throws APIException {
    try {
        Response response = mDhisApi.postDashboard(dashboard);
        // also, we will need to find UUID of newly created dashboard,
        // which is contained inside of HTTP Location header
        Header header = findLocationHeader(response.getHeaders());
        // parse the value of header as URI and extract the id
        String dashboardId = Uri.parse(header.getValue()).getLastPathSegment();
        // set UUID, change state and save dashboard
        dashboard.setUId(dashboardId);
        dashboard.setState(State.SYNCED);
        dashboard.save();

        updateDashboardTimeStamp(dashboard);
    } catch (APIException apiException) {
        handleApiException(apiException);
    }
}
 
开发者ID:dhis2,项目名称:dhis2-android-dashboard,代码行数:19,代码来源:DashboardController.java

示例15: loadData

import retrofit.client.Header; //导入依赖的package包/类
@Override public void loadData(Callback<Object> callback) {

    if (!shouldFail) {
      callback.success(data, null);
    } else {
      RetrofitError error = null;
      switch (reason) {
        case NETWORK:
          error = RetrofitError.networkError("mock url", new IOException("Mock Network Exception"));
          break;
        case STATUS_CODE:
          error = RetrofitError.httpError("mock url",
              new Response("mock url", FailReason.httpcode, "Forbidden", new ArrayList<Header>(), null), null, null);
          break;

        case UNKNOWN:
        default:
          error = RetrofitError.unexpectedError("mock url", new Exception("Mock Exception"));
          break;
      }
      callback.failure(error);
    }
  }
 
开发者ID:sockeqwe,项目名称:hdlib,代码行数:24,代码来源:MockTestApi.java


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