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


Java RequestException类代码示例

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


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

示例1: getTokenUncached

import ru.bozaro.gitlfs.client.exceptions.RequestException; //导入依赖的package包/类
@NotNull
private Link getTokenUncached(@NotNull User user) throws IOException {
  final HttpPost post = new HttpPost(authUrl.toString());
  final List<NameValuePair> params = new ArrayList<>();
  addParameter(params, "token", authToken);
  if (!user.isAnonymous()) {
    addParameter(params, "username", user.getUserName());
    addParameter(params, "realname", user.getRealName());
    addParameter(params, "external", user.getExternalId());
    addParameter(params, "email", user.getEmail());
  } else {
    addParameter(params, "anonymous", "true");
  }
  post.setEntity(new UrlEncodedFormEntity(params));
  try {
    final HttpResponse response = httpClient.execute(post);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      return mapper.readValue(response.getEntity().getContent(), Link.class);
    }
    throw new RequestException(post, response);
  } finally {
    post.abort();
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:25,代码来源:LfsHttpStorage.java

示例2: getReader

import ru.bozaro.gitlfs.client.exceptions.RequestException; //导入依赖的package包/类
@Nullable
public LfsReader getReader(@NotNull String oid, @NotNull User user) throws IOException {
  try {
    if (!oid.startsWith(OID_PREFIX)) return null;
    final String hash = oid.substring(OID_PREFIX.length());
    final Client lfsClient = new Client(new UserAuthProvider(user), httpClient);
    final ObjectRes meta = lfsClient.getMeta(hash);
    if (meta == null || meta.getMeta() == null) {
      return null;
    }
    return new LfsHttpReader(this, meta.getMeta(), meta);
  } catch (RequestException e) {
    log.error("HTTP request error:" + e.getMessage() + "\n" + e.getRequestInfo());
    throw e;
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:17,代码来源:LfsHttpStorage.java

示例3: doRequest

import ru.bozaro.gitlfs.client.exceptions.RequestException; //导入依赖的package包/类
public <R> R doRequest(@Nullable Link link, @NotNull Request<R> task, @NotNull URI url) throws IOException {
  int redirectCount = 0;
  int retryCount = 0;
  while (true) {
    final HttpUriRequest request = task.createRequest(mapper, url.toString());
    addHeaders(request, link);
    final HttpResponse response = http.executeMethod(request);
    try {
      switch (response.getStatusLine().getStatusCode()) {
        case HttpStatus.SC_UNAUTHORIZED:
          throw new UnauthorizedException(request, response);
        case HttpStatus.SC_FORBIDDEN:
          throw new ForbiddenException(request, response);
        case HttpStatus.SC_MOVED_PERMANENTLY:
        case HttpStatus.SC_MOVED_TEMPORARILY:
        case HttpStatus.SC_SEE_OTHER:
        case HttpStatus.SC_TEMPORARY_REDIRECT:
          // Follow by redirect.
          final String location = response.getFirstHeader(HEADER_LOCATION).getValue();
          if (location == null || redirectCount >= MAX_REDIRECT_COUNT) {
            throw new RequestException(request, response);
          }
          ++redirectCount;
          url = url.resolve(location);
          continue;
        case HttpStatus.SC_BAD_GATEWAY:
        case HttpStatus.SC_GATEWAY_TIMEOUT:
        case HttpStatus.SC_SERVICE_UNAVAILABLE:
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
          // Temporary error. need to retry.
          if (retryCount >= MAX_RETRY_COUNT) {
            throw new RequestException(request, response);
          }
          ++retryCount;
          continue;
      }
      int[] success = task.statusCodes();
      if (success == null) {
        success = DEFAULT_HTTP_SUCCESS;
      }
      for (int item : success) {
        if (response.getStatusLine().getStatusCode() == item) {
          return task.processResponse(mapper, response);
        }
      }
      // Unexpected status code.
      throw new RequestException(request, response);
    } finally {
      request.abort();
    }
  }
}
 
开发者ID:bozaro,项目名称:git-lfs-java,代码行数:53,代码来源:Client.java

示例4: main

import ru.bozaro.gitlfs.client.exceptions.RequestException; //导入依赖的package包/类
public static void main(@NotNull String[] args) throws Exception {
  final CmdArgs cmd = new CmdArgs();
  final JCommander jc = new JCommander(cmd);
  jc.parse(args);
  if (cmd.help) {
    jc.usage();
    return;
  }
  final long time = System.currentTimeMillis();
  final Client client;
  if (cmd.lfs != null) {
    client = createClient(new BasicAuthProvider(URI.create(cmd.lfs)), cmd);
  } else if (cmd.git != null) {
    client = createClient(AuthHelper.create(cmd.git), cmd);
  } else {
    client = null;
  }
  if (!checkLfsAuthenticate(client)) {
    return;
  }
  if (cmd.checkLfs) {
    if (client == null) {
      log.error("Git LFS server is not defined.");
    }
    return;
  }
  String[] globs = cmd.globs.toArray(new String[cmd.globs.size()]);
  if (cmd.globFile != null) {
    globs = Stream.concat(Arrays.stream(globs),
        Files.lines(cmd.globFile)
            .map(String::trim)
            .filter(s -> !s.isEmpty())
    ).toArray(String[]::new);
  }
  try {
    processRepository(cmd.src, cmd.dst, cmd.cache, client, cmd.writeThreads, cmd.uploadThreads, globs);
  } catch (ExecutionException e) {
    if (e.getCause() instanceof RequestException) {
      final RequestException cause = (RequestException) e.getCause();
      log.error("HTTP request failure: {}", cause.getRequestInfo());
    }
    throw e;
  }
  log.info("Convert time: {}", System.currentTimeMillis() - time);
}
 
开发者ID:bozaro,项目名称:git-lfs-migrate,代码行数:46,代码来源:Main.java


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