本文整理汇总了Java中org.kohsuke.stapler.HttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse类的具体用法?Java HttpResponse怎么用?Java HttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponse类属于org.kohsuke.stapler包,在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPost
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse doPost(StaplerRequest request) throws IOException {
if (!request.getMethod().equals("POST")) {
return HttpResponses
.error(HttpServletResponse.SC_BAD_REQUEST,
"Only POST requests are supported, this was a " + request.getMethod() + " request");
}
if (!"application/json".equals(request.getContentType())) {
return HttpResponses
.error(HttpServletResponse.SC_BAD_REQUEST,
"Only application/json content is supported, this was " + request.getContentType());
}
String type = request.getHeader("X-Gitea-Event");
if (StringUtils.isBlank(type)) {
return HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST,
"Expecting a Gitea event, missing expected X-Gitea-Event header");
}
String origin = SCMEvent.originOf(request);
boolean processed = false;
for (GiteaWebhookHandler<?, ?> h : ExtensionList.lookup(GiteaWebhookHandler.class)) {
if (h.matches(type)) {
h.process(request.getInputStream(), origin);
processed = true;
}
}
return HttpResponses.plainText(processed ? "Processed" : "Ignored");
}
示例2: doTestIcon
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Serves the testCoverage badge image. TO DO
* @param req
* @param rsp
* @param job
* @return
*/
@SuppressWarnings("rawtypes")
public HttpResponse doTestIcon(StaplerRequest req, StaplerResponse rsp, @QueryParameter String job) {
Job<?, ?> project = getProject(job);
Integer testPass = null;
Integer testTotal = null;
if (project.getLastCompletedBuild() != null) {
AbstractTestResultAction testAction = project.getLastCompletedBuild().getAction(AbstractTestResultAction.class);
if(testAction != null){
int total = testAction.getTotalCount();
int pass = total - testAction.getFailCount() - testAction.getSkipCount();
testTotal = total;
testPass = pass;
}
}
return iconResolver.getTestResultImage(testPass, testTotal);
}
示例3: doBuildDescriptionIcon
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Serves the Build Description badge image.
* @param req
* @param rsp
* @param job
* @return
*/
public HttpResponse doBuildDescriptionIcon(StaplerRequest req, StaplerResponse rsp, @QueryParameter String job) {
Job<?, ?> project = getProject(job);
String buildDescription = null;
/*if (project.getLastSuccessfulBuild() != null) {
buildDescription = project.getLastSuccessfulBuild().getDescription();
}*/
/*if (project.getLastBuild() != null) {
buildDescription = project.getLastBuild().getDescription();
}*/
if (project.getLastCompletedBuild() != null) {
buildDescription = project.getLastCompletedBuild().getDescription();
}
return iconResolver.getBuildDescriptionImage(buildDescription);
}
示例4: doImpersonate
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
@RequirePOST
public HttpResponse doImpersonate(StaplerRequest req, @QueryParameter String name) {
Authentication auth = Jenkins.getAuthentication();
GrantedAuthority[] authorities = auth.getAuthorities();
if (authorities == null || StringUtils.isBlank(name)) {
return HttpResponses.redirectToContextRoot();
}
GrantedAuthority authority = null;
for (GrantedAuthority a : authorities) {
if (a.getAuthority().equals(name)) {
authority = a;
break;
}
}
if (authority == null) {
return HttpResponses.redirectToContextRoot();
}
if (!SecurityRealm.AUTHENTICATED_AUTHORITY.equals(authority)) {
ACL.impersonate(new ImpersonationAuthentication(auth, authority, SecurityRealm.AUTHENTICATED_AUTHORITY));
} else {
ACL.impersonate(new ImpersonationAuthentication(auth, SecurityRealm.AUTHENTICATED_AUTHORITY));
}
return HttpResponses.redirectToContextRoot();
}
示例5: doQueryJiraFields
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse doQueryJiraFields(@QueryParameter String issueKey)
{
try
{
if (!Config.getGlobalConfig().isJiraConfigComplete())
{
return FormValidation.error("JIRA settings are not set in global config");
}
final Map<String, String> jiraFields = getJiraClientSvc().getJiraFields(issueKey);
return new ForwardToView(this, "/org/jenkinsci/plugins/jiraext/view/UpdateField/jiraFields.jelly")
.with("jiraFieldMap", jiraFields);
}
catch (Throwable t)
{
String message = "Error finding FieldIds for issueKey: " + issueKey;
logger.log(Level.WARNING, message, t);
return FormValidation.error(t, message);
}
}
示例6: doProvision
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse doProvision(@QueryParameter String template) throws ServletException, IOException {
checkPermission(PROVISION);
if (template == null) {
throw HttpResponses.error(SC_BAD_REQUEST, "The 'template' query parameter is missing");
}
SlaveTemplate t = getTemplate(template);
if (t == null) {
throw HttpResponses.error(SC_BAD_REQUEST, "No such template: " + template);
}
StringWriter sw = new StringWriter();
StreamTaskListener listener = new StreamTaskListener(sw);
try {
EC2AbstractSlave node = t.provision(listener);
Hudson.getInstance().addNode(node);
return HttpResponses.redirectViaContextPath("/computer/" + node.getNodeName());
} catch (AmazonClientException e) {
throw HttpResponses.error(SC_INTERNAL_SERVER_ERROR, e);
}
}
示例7: doRawContainerInfo
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Retrieves the latest container status via API.
* The output will be retrieved in JSON. Supports filers. Missing
* "since" and "until"
* @param id ID of the container, for which the info should be retrieved.
* Short container IDs are not supported.
* @throws IOException Processing error
* @throws ServletException Servlet error
* @return Raw JSON output compatible with docker inspect
*/
public HttpResponse doRawContainerInfo(@QueryParameter(required = true) String id)
throws IOException, ServletException {
checkPermission(DockerTraceabilityPlugin.READ_DETAILS);
//TODO: check containerID format
final DockerTraceabilityReport report = DockerTraceabilityHelper.getLastReport(id);
if (report == null) {
return HttpResponses.error(404, "No info available for the containerId=" + id);
}
final InspectContainerResponse inspectInfo = report.getContainer();
if (inspectInfo == null) {
assert false : "Input logic should reject such cases";
return HttpResponses.error(500, "Cannot retrieve the container's status");
}
// Return raw JSON in the response
InspectContainerResponse[] out = {inspectInfo};
return toJSONResponse(out);
}
示例8: do_perform
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Performs the notification on 'POST' action named "perform"
*
* @param req StaplerRequest
* @param rsp StaplerResponse
* @return HttpResponse
*/
public HttpResponse do_perform(final StaplerRequest req, final StaplerResponse rsp) {
// Only administrator can create a new site.
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
// TODO: display the progression
for(ResendProjectAction resendProjectAction: resendActions){
try {
final NotificationHandler notifHandler = new NotificationHandler(resendProjectAction.getConfig());
for(Map.Entry<AbstractBuild<?,?>, List<ResendBuildAction>> resendBuildAction: resendProjectAction.getResendActionPerBuild().entrySet()){
notifHandler.send(resendBuildAction.getKey(), resendBuildAction.getValue());
}
} catch (Exception e ){
GrapesPlugin.getLogger().log(Level.SEVERE, "[GRAPES] Failed to re-send notification: ", e);
}
}
refresh();
return HttpRedirect.DOT;
}
示例9: cors
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse cors(@CheckForNull String accessKey, final HttpResponse resp) {
final MetricsAccessKey key = getAccessKey(accessKey);
return key == null ? resp : new HttpResponse() {
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node)
throws IOException, ServletException {
String origin = req.getHeader("Origin");
if (StringUtils.isNotBlank(origin) && key.isOriginAllowed(origin)) {
rsp.addHeader("Access-Control-Allow-Origin", origin);
rsp.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
rsp.addHeader("Access-Control-Allow-Headers", "Accept, Authorization");
if ("OPTIONS".equals(req.getMethod())) {
rsp.setStatus(200);
return;
}
}
resp.generateResponse(req, rsp, node);
}
};
}
示例10: doHealthcheck
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Binds the health checks to the CORS aware URL {@code /metrics/healthcheck} where the metrics access key is
* provided in the form field {@code key} or an {@code Authorization: Jenkins-Metrics-Key {key}} header
*
* @param req the request
* @param key the key from the form field.
* @return the {@link HttpResponse}
* @throws IllegalAccessException if the access attempt is invalid.
*/
@SuppressWarnings("unused") // stapler binding
@Restricted(NoExternalUse.class) // stapler binding
public HttpResponse doHealthcheck(StaplerRequest req, @QueryParameter("key") String key)
throws IllegalAccessException {
requireCorrectMethod(req);
if (StringUtils.isBlank(key)) {
key = getKeyFromAuthorizationHeader(req);
}
Metrics.checkAccessKeyHealthCheck(key);
long ifModifiedSince = req.getDateHeader("If-Modified-Since");
long maxAge = getCacheControlMaxAge(req);
Metrics.HealthCheckData data = Metrics.getHealthCheckData();
if (data == null || (maxAge != -1 && data.getLastModified() + maxAge < System.currentTimeMillis())) {
data = new Metrics.HealthCheckData(Metrics.healthCheckRegistry().runHealthChecks());
} else if (ifModifiedSince != -1 && data.getLastModified() < ifModifiedSince) {
return Metrics.cors(key, HttpResponses.status(HttpServletResponse.SC_NOT_MODIFIED));
}
return Metrics.cors(key, new HealthCheckResponse(data));
}
示例11: doHealthcheckOk
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Condense the health check into one bit of information
* for frontend reverse proxies like haproxy.
*
* Other health check calls requires authentication, which
* is not suitable for the haproxy use. But this endpoint
* only exposes one bit information, it's deemed OK to be exposed
* unsecurely.
*
* return status 200 if everything is OK, 503 (service unavailable) otherwise
*
* @param req the request
* @return the HTTP response
*/
@SuppressWarnings("unused") // stapler binding
@Restricted(NoExternalUse.class) // stapler binding
public HttpResponse doHealthcheckOk(StaplerRequest req) {
long ifModifiedSince = req.getDateHeader("If-Modified-Since");
long maxAge = getCacheControlMaxAge(req);
Metrics.HealthCheckData data = Metrics.getHealthCheckData();
if (data == null || (maxAge != -1 && data.getLastModified() + maxAge < System.currentTimeMillis())) {
data = new Metrics.HealthCheckData(Metrics.healthCheckRegistry().runHealthChecks());
} else if (ifModifiedSince != -1 && data.getLastModified() < ifModifiedSince) {
return HttpResponses.status(HttpServletResponse.SC_NOT_MODIFIED);
}
for (HealthCheck.Result result : data.getResults().values()) {
if (!result.isHealthy()) {
return new StatusResponse(HttpServletResponse.SC_SERVICE_UNAVAILABLE, data.getLastModified(),
data.getExpires());
}
}
return new StatusResponse(HttpServletResponse.SC_OK, data.getLastModified(), data.getExpires());
}
示例12: doIndex
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Web binding for {@literal /}
*
* @return the response
*/
@Restricted(NoExternalUse.class) // only for use by stapler web binding
public HttpResponse doIndex() {
return HttpResponses
.html("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" +
" \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
"<html>\n" +
"<head>\n" +
" <title>Metrics</title>\n" +
"</head>\n" +
"<body>\n" +
" <h1>Operational Menu</h1>\n" +
" <ul>\n" +
" <li><a href=\"./metrics?pretty=true\">Metrics</a></li>\n" +
" <li><a href=\"./ping\">Ping</a></li>\n" +
" <li><a href=\"./threads\">Threads</a></li>\n" +
" <li><a href=\"./healthcheck?pretty=true\">Healthcheck</a></li>\n" +
" </ul>\n" +
"</body>\n" +
"</html>");
}
示例13: doFinishLogin
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
public HttpResponse doFinishLogin(StaplerRequest request, StaplerResponse rsp) throws IOException {
String code = request.getParameter("code");
if (code == null || code.trim().length() == 0) {
Log.info("doFinishLogin: missing code.");
return HttpResponses.redirectToContextRoot();
}
String content = postForAccessToken(code);
String accessToken = extractToken(content);
updateOfflineAccessTokenForUser(accessToken);
request.getSession().setAttribute("access_token", accessToken);
String newProjectSetupUrl = getJenkinsRootUrl() + "/" + GithubReposController.URL;
return HttpResponses.redirectTo(newProjectSetupUrl);
}
示例14: doIssue
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Generates a response containing issue data, but first logs in to YouTrack.
*
* @return the response.
*/
public HttpResponse doIssue() {
return new HttpResponse() {
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
String id = req.getParameter("id");
YouTrackSite youTrackSite = YouTrackSite.get(project);
if (youTrackSite == null) {
rsp.getWriter().write("YouTrack integration not set up for this project");
return;
}
YouTrackServer youTrackServer = new YouTrackServer(youTrackSite.getUrl());
User user = youTrackServer.login(youTrackSite.getUsername(), youTrackSite.getPassword());
Issue issue = youTrackServer.getIssue(user, id);
Gson gson = new Gson();
String json = gson.toJson(issue);
rsp.getWriter().write(json);
}
};
}
示例15: doPostCredential
import org.kohsuke.stapler.HttpResponse; //导入依赖的package包/类
/**
* Submits the Oracle account username/password.
*/
@RequirePOST
public HttpResponse doPostCredential(@QueryParameter String username, @QueryParameter String password) throws IOException, ServletException {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
this.username = username;
this.password = Secret.fromString(password);
save();
return HttpResponses.redirectTo("credentialOK");
}
开发者ID:jenkinsci,项目名称:apache-httpcomponents-client-4-api-plugin,代码行数:12,代码来源:Client4JDKInstaller.java