本文整理汇总了Java中org.kohsuke.stapler.StaplerResponse.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Java StaplerResponse.setStatus方法的具体用法?Java StaplerResponse.setStatus怎么用?Java StaplerResponse.setStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kohsuke.stapler.StaplerResponse
的用法示例。
在下文中一共展示了StaplerResponse.setStatus方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* TO DO
* @param req
* @param rsp
* @param node
* @throws IOException
* @throws ServletException
*/
@Override
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
// Check if the latest badge is already cached
String v = req.getHeader("If-None-Match");
if (etag.equals(v)) {
rsp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
rsp.setHeader("ETag", etag);
rsp.setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
rsp.setHeader("Cache-Control", "no-cache, private");
rsp.setHeader("Content-Type", "image/svg+xml;charset=utf-8");
rsp.setHeader("Content-Length", length);
rsp.getOutputStream().write(payload);
}
示例2: cors
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的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);
}
};
}
示例3: generateResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
@Override
public void generateResponse( StaplerRequest req, StaplerResponse rsp, Object node )
throws IOException, ServletException
{
String v = req.getHeader( "If-None-Match" );
if ( etag.equals( v ) )
{
rsp.setStatus( SC_NOT_MODIFIED );
return;
}
rsp.setHeader( "ETag", etag );
rsp.setHeader( "Expires", "Fri, 01 Jan 1984 00:00:00 GMT" );
rsp.setHeader( "Cache-Control", "no-cache, private" );
rsp.setHeader( "Content-Type", "image/svg+xml;charset=utf-8" );
rsp.setHeader( "Content-Length", length );
rsp.getOutputStream().write( payload.getBytes() );
}
示例4: exitWebHook
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* Exit the WebHook
*
* @param result GogsResults
*/
private void exitWebHook(GogsResults result, StaplerResponse resp) throws IOException {
if (result.getStatus() != 200) {
LOGGER.warning(result.getMessage());
}
JSONObject json = new JSONObject();
json.element("result", result.getStatus() == 200 ? "OK" : "ERROR");
json.element("message", result.getMessage());
resp.setStatus(result.getStatus());
resp.addHeader("Content-Type", "application/json");
PrintWriter printer = resp.getWriter();
printer.print(json.toString());
}
示例5: doProgressText
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* Implements the progressive text handling.
* This method is used as a "web method" with progressiveText.jelly.
*/
public void doProgressText(StaplerRequest req, StaplerResponse rsp) throws IOException {
setContentType(rsp);
rsp.setStatus(HttpServletResponse.SC_OK);
if(!source.exists()) {
// file doesn't exist yet
rsp.addHeader("X-Text-Size","0");
rsp.addHeader("X-More-Data","true");
return;
}
long start = 0;
String s = req.getParameter("start");
if(s!=null)
start = Long.parseLong(s);
if(source.length() < start )
start = 0; // text rolled over
CharSpool spool = new CharSpool();
long r = writeLogTo(start,spool);
rsp.addHeader("X-Text-Size",String.valueOf(r));
if(!completed)
rsp.addHeader("X-More-Data","true");
Writer w = createWriter(req, rsp, r - start);
spool.writeTo(new LineEndNormalizingWriter(w));
w.close();
}
示例6: jsonResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public static HttpResponse jsonResponse(final CollectorRegistry collectorRegistry) {
return new HttpResponse() {
@Override
public void generateResponse(StaplerRequest request, StaplerResponse response, Object node) throws IOException, ServletException {
response.setStatus(StaplerResponse.SC_OK);
response.setContentType(TextFormat.CONTENT_TYPE_004);
StringWriter buffer = new StringWriter();
TextFormat.write004(buffer, collectorRegistry.metricFamilySamples());
buffer.close();
response.getWriter().write(buffer.toString());
}
};
}
示例7: generateResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
@Override
public void generateResponse(StaplerRequest req,
StaplerResponse rsp,
Object o) throws IOException, ServletException {
rsp.setStatus(status);
rsp.setContentType("application/json");
rsp.getWriter().println(json);
}
示例8: doIndex
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
@RequirePOST
public void doIndex(StaplerRequest request, StaplerResponse response) {
if (isJenkinsValidation(request)) {
response.setHeader(X_INSTANCE_IDENTITY, Identity.getValueOrDefault(this.identity));
response.setStatus(HTTP_OK);
return;
}
String payload = getPayload(request);
checkState(payload != null, "Not intended to be browsed interactively (must specify payload parameter)."
+ " Ensure that the web hook Content-Type header is application/x-www-form-urlencoded");
String eventName = getEventType(request);
GitHubEvent event = GitHubEvent.from(eventName);
switch (event) {
case PING:
case SUPPORT:
response.setStatus(HTTP_OK);
break;
case PUSH:
PushCause cause = createCause(payload);
this.triggerBuilds(Jenkins.getInstance(), cause);
break;
case UNKNOWN:
String msg = String.format("Spoon WebHook event type (%s) is not supported. Only push and support events are supported", eventName);
throw new IllegalArgumentException(msg);
}
}
示例9: generateResponse
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void generateResponse(StaplerRequest req, StaplerResponse resp, Object node) throws IOException,
ServletException {
resp.setStatus(HttpServletResponse.SC_OK);
resp.setHeader(MetricsRootAction.CACHE_CONTROL, MetricsRootAction.NO_CACHE);
resp.setContentType(PLAIN_TEXT_CONTENT_TYPE);
final PrintWriter writer = resp.getWriter();
try {
writer.println(CONTENT);
} finally {
writer.close();
}
}
示例10: doDynamic
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void doDynamic(StaplerRequest request, StaplerResponse response) {
String token = request.getOriginalRestOfPath().substring(1); //Strip leading slash
CharBuffer dest = CharBuffer.allocate(request.getContentLength());
try {
BufferedReader reader = request.getReader();
while (reader.read(dest) > 0) {
//Intentionally blank
}
} catch (IOException e) {
response.setStatus(400);
return;
}
dest.rewind();
String content = dest.toString();
Logger.getLogger(WebhookRootAction.class.getName())
.info("Webhook called with " + token);
WaitForWebhookExecution exec;
synchronized (webhooks) {
exec = webhooks.remove(token);
if (exec == null) {
//pipeline has not yet waited on webhook, add an entry to track
//that it was already triggered
alreadyPosted.put(token, content);
}
}
if (exec != null) {
exec.onTriggered(content);
response.setHeader("Result", "WebhookTriggered");
response.setStatus(200);
} else {
response.setStatus(202);
}
}
示例11: writeStatus
import org.kohsuke.stapler.StaplerResponse; //导入方法依赖的package包/类
public void writeStatus(StaplerResponse rsp, JSReturnCollection status) throws IOException {
Writer compressedWriter = rsp.getWriter();
JSONSerializer.toJSON(status).write(compressedWriter);
rsp.setStatus(200);
compressedWriter.flush();
}