本文整理汇总了Java中java.net.HttpURLConnection.HTTP_PRECON_FAILED属性的典型用法代码示例。如果您正苦于以下问题:Java HttpURLConnection.HTTP_PRECON_FAILED属性的具体用法?Java HttpURLConnection.HTTP_PRECON_FAILED怎么用?Java HttpURLConnection.HTTP_PRECON_FAILED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.net.HttpURLConnection
的用法示例。
在下文中一共展示了HttpURLConnection.HTTP_PRECON_FAILED属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inspect
public void inspect() throws IOException {
final BlockInfo blockInfo = info.getBlock(blockIndex);
boolean isServerCancelled = false;
ResumeFailedCause resumeFailedCause = null;
final int code = connected.getResponseCode();
final String etag = info.getEtag();
final String newEtag = connected.getResponseHeaderField("Etag");
do {
if (code == HttpURLConnection.HTTP_PRECON_FAILED) {
resumeFailedCause = RESPONSE_PRECONDITION_FAILED;
break;
}
if (!Util.isEmpty(etag) && !Util.isEmpty(newEtag) && !newEtag.equals(etag)) {
// etag changed.
// also etag changed is relate to HTTP_PRECON_FAILED
resumeFailedCause = RESPONSE_ETAG_CHANGED;
break;
}
if (code == HttpURLConnection.HTTP_CREATED && blockInfo.getCurrentOffset() != 0) {
// The request has been fulfilled and has resulted in one or more new resources
// being created.
// mark this case is precondition failed for
// 1. checkout whether accept partial
// 2. 201 means new resources so range must be from beginning otherwise it can't
// match local range.
resumeFailedCause = RESPONSE_CREATED_RANGE_NOT_FROM_0;
break;
}
if (code == HttpURLConnection.HTTP_RESET && blockInfo.getCurrentOffset() != 0) {
resumeFailedCause = RESPONSE_RESET_RANGE_NOT_FROM_0;
break;
}
if (code != HttpURLConnection.HTTP_PARTIAL && code != HttpURLConnection.HTTP_OK) {
isServerCancelled = true;
break;
}
if (code == HttpURLConnection.HTTP_OK && blockInfo.getCurrentOffset() != 0) {
isServerCancelled = true;
break;
}
} while (false);
if (resumeFailedCause != null) {
// resume failed, relaunch from beginning.
throw new ResumeFailedException(resumeFailedCause);
}
if (isServerCancelled) {
// server cancelled, end task.
throw new ServerCancelledException(code, blockInfo.getCurrentOffset());
}
}
示例2: webhook
/**
* Webhook for Github issue_comment event.
* @param issueComment Event Json payload.
* @see <a href="https://developer.github.com/v3/activity/events/types">
* Webhook Events Payloads
* </a>
* @return Http response.
*/
@POST
@Path("/github/issuecomment")
@Consumes(MediaType.APPLICATION_JSON)
public Response webhook(final JsonObject issueComment) {
final int status;
final String event = this.request.getHeader("X-Github-Event");
String userAgent = this.request.getHeader("User-Agent");
if(userAgent == null) {
userAgent = "";
}
if(userAgent.startsWith("GitHub-Hookshot/")) {
if("ping".equalsIgnoreCase(event)) {
status = HttpURLConnection.HTTP_OK;
} else {
if ("issue_comment".equalsIgnoreCase(event)) {
final boolean startedHandling = this.handleNotifications(
new WebhookNotifications(issueComment)
);
if(startedHandling) {
status = HttpURLConnection.HTTP_OK;
} else {
status = HttpURLConnection.HTTP_INTERNAL_ERROR;
}
} else {
status = HttpURLConnection.HTTP_PRECON_FAILED;
}
}
} else {
status = HttpURLConnection.HTTP_PRECON_FAILED;
}
return Response.status(status).build();
}
示例3: ResourcePreconditionException
/**
* Constructor.
*
* @param message Exception message
* @param cause reason for this exception
*/
public ResourcePreconditionException(final String message, final Throwable cause) {
super(HttpURLConnection.HTTP_PRECON_FAILED, message, cause);
}