本文整理汇总了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();
}
}
示例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;
}
}
示例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();
}
}
}
示例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);
}