本文整理汇总了Java中javax.ws.rs.core.Response.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getLocation方法的具体用法?Java Response.getLocation怎么用?Java Response.getLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response
的用法示例。
在下文中一共展示了Response.getLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: triggerJenkinsWebHook
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
* Triggers the given jenkins job via its URL.
*
* @param authHeader
* @param jobUrl the URL to the jenkins job
* @param triggerUrl can be null or empty and the default triggerUrl will be used
*/
protected void triggerJenkinsWebHook(String token, String authHeader, String jobUrl, String triggerUrl, boolean post) {
if (Strings.isNullOrBlank(triggerUrl)) {
//triggerUrl = URLUtils.pathJoin(jobUrl, "/build?token=" + token);
triggerUrl = URLUtils.pathJoin(jobUrl, "/build?delay=0");
}
// lets check if this build is already running in which case do nothing
String lastBuild = URLUtils.pathJoin(jobUrl, "/lastBuild/api/json");
JsonNode lastBuildJson = parseLastBuildJson(authHeader, lastBuild);
JsonNode building = null;
if (lastBuildJson != null && lastBuildJson.isObject()) {
building = lastBuildJson.get("building");
if (building != null && building.isBoolean()) {
if (building.booleanValue()) {
LOG.info("Build is already running so lets not trigger another one!");
return;
}
}
}
LOG.info("Got last build JSON: " + lastBuildJson + " building: " + building);
LOG.info("Triggering Jenkins build: " + triggerUrl);
Client client = WebClientHelpers.createClientWihtoutHostVerification();
try {
Response response = client.target(triggerUrl).
request().
header("Authorization", authHeader).
post(Entity.text(null), Response.class);
int status = response.getStatus();
String message = null;
Response.StatusType statusInfo = response.getStatusInfo();
if (statusInfo != null) {
message = statusInfo.getReasonPhrase();
}
String extra = "";
if (status == 302) {
extra = " Location: " + response.getLocation();
}
LOG.info("Got response code from Jenkins: " + status + " message: " + message + " from URL: " + triggerUrl + extra);
if (status <= 200 || status > 302) {
LOG.error("Failed to trigger job " + triggerUrl + ". Status: " + status + " message: " + message);
}
} finally {
closeQuietly(client);
}
}