本文整理汇总了Java中org.kohsuke.stapler.HttpResponses类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponses类的具体用法?Java HttpResponses怎么用?Java HttpResponses使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponses类属于org.kohsuke.stapler包,在下文中一共展示了HttpResponses类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doProvision
import org.kohsuke.stapler.HttpResponses; //导入依赖的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);
}
}
示例2: build
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
@Test
public void build() throws IOException {
try {
FreeStyleProject testProject = jenkins.createFreeStyleProject();
when(trigger.getTriggerOpenMergeRequestOnPush()).thenReturn(TriggerOpenMergeRequest.never);
testProject.addTrigger(trigger);
exception.expect(HttpResponses.HttpResponseException.class);
new PushBuildAction(testProject, getJson("PushEvent.json"), null).execute(response);
} finally {
ArgumentCaptor<PushHook> pushHookArgumentCaptor = ArgumentCaptor.forClass(PushHook.class);
verify(trigger).onPost(pushHookArgumentCaptor.capture());
assertThat(pushHookArgumentCaptor.getValue().getProject(), is(notNullValue()));
assertThat(pushHookArgumentCaptor.getValue().getProject().getWebUrl(), is(notNullValue()));
}
}
示例3: testEvaluationWorksEvenThoughWeUsedEqualsInParameterValues
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
@Test
public void testEvaluationWorksEvenThoughWeUsedEqualsInParameterValues() throws IOException {
GroovyScript listScript = new GroovyScript(new SecureGroovyScript(SCRIPT_LIST, Boolean.FALSE, null),
new SecureGroovyScript(FALLBACK_SCRIPT_LIST, Boolean.FALSE, null));
GroovyScript listSelectionScript = new GroovyScript(
new SecureGroovyScript(SCRIPT_LIST_SELECTION, Boolean.FALSE, null),
new SecureGroovyScript(FALLBACK_SCRIPT_LIST_SELECTION, Boolean.FALSE, null));
ChoiceParameter listParam = new ChoiceParameter("LIST", "description...", "random-name1", listScript,
CascadeChoiceParameter.PARAMETER_TYPE_SINGLE_SELECT, true, 1);
DynamicReferenceParameter listSelectionParam = new DynamicReferenceParameter("LIST_SELECTION", "description...",
"random-name2", listSelectionScript, CascadeChoiceParameter.ELEMENT_TYPE_FORMATTED_HIDDEN_HTML, "LIST",
true);
// should be a String
String listValue = listParam.getDefaultParameterValue().getValue().toString();
try {
listSelectionParam.doUpdate(String.format(String.format("%s=%s", listParam.getName(), listValue)));
} catch (HttpResponses.HttpResponseException response) {
// ignore
}
// as this is a formatted hidden HTML...
String listSelectionValue = listSelectionParam.getChoicesAsString();
// by default, the plug-in returns the first element in the list...
assertEquals("Value returned from selection list doesn't match first element in list parameter", "A=1",
listSelectionValue);
}
示例4: doFinishLogin
import org.kohsuke.stapler.HttpResponses; //导入依赖的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);
}
示例5: extractListenerId
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
private String extractListenerId(StaplerRequest req) {
String path = req.getRestOfPath();
String id = getListenerId(path.substring(1));
if (id == null) {
throw HttpResponses.notFound();
}
return id;
}
示例6: doFinishLogin
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
public HttpResponse doFinishLogin(StaplerRequest request) throws IOException {
String code = request.getParameter("code");
if (StringUtils.isBlank(code)) {
LOGGER.log(Level.SEVERE, "doFinishLogin() code = null");
return HttpResponses.redirectToContextRoot();
}
DeepinToken token = new DeepinOAuthApiService(clientID, clientSecret).getTokenByAuthorizationCode(code);
if (!token.accessToken.isEmpty()) {
DeepinAuthenticationToken auth = new DeepinAuthenticationToken(token, clientID, clientSecret);
SecurityContextHolder.getContext().setAuthentication(auth);
User u = User.current();
u.setFullName(auth.getName());
} else {
LOGGER.log(Level.SEVERE, "doFinishLogin() accessToken = null");
}
// redirect to referer
String referer = (String) request.getSession().getAttribute(REFERER_ATTRIBUTE);
if (referer != null) {
return HttpResponses.redirectTo(referer);
} else {
return HttpResponses.redirectToContextRoot();
}
}
示例7: doSubmitContainerStatus
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
/**
* Submits a new event through Jenkins API.
* @param inspectData JSON output of docker inspect container (array of container infos)
* @param hostName Optional name of the host, which submitted the event
* "unknown" by default
* @param hostId Optional host ID.
* "unknown" by default
* @param status Optional status of the container.
* By default, an artificial {@link DockerEventType#NONE} will be used.
* @param time Optional time when the event happened.
* The time is specified in seconds since January 1, 1970, 00:00:00 GMT
* Default value - current time
* @param environment Optional field, which describes the environment
* @param imageName Optional field, which provides the name of the image
* @return {@link HttpResponse}
* @throws IOException Request processing error
* @throws ServletException Servlet error
*/
//TODO: parameters check
@RequirePOST
public HttpResponse doSubmitContainerStatus(
@QueryParameter(required = true) String inspectData,
@QueryParameter(required = false) String hostId,
@QueryParameter(required = false) String hostName,
@QueryParameter(required = false) String status,
@QueryParameter(required = false) long time,
@QueryParameter(required = false) @CheckForNull String environment,
@QueryParameter(required = false) @CheckForNull String imageName
) throws IOException, ServletException {
checkPermission(DockerTraceabilityPlugin.SUBMIT);
final ObjectMapper mapper = new ObjectMapper();
final InspectContainerResponse[] inspectContainerResponses = mapper.readValue(inspectData, InspectContainerResponse[].class);
final long eventTime = time != 0 ? time : System.currentTimeMillis()/1000;
final String effectiveHostName = StringUtils.isNotBlank(hostName) ? hostName : "unknown";
final String effectiveHostId = StringUtils.isNotBlank(hostId) ? hostId : "unknown";
final String effectiveStatus = StringUtils.isNotBlank(status)
? status.toUpperCase(Locale.ENGLISH) : DockerEventType.NONE.toString();
final String effectiveImageName = hudson.Util.fixEmpty(imageName);
final String effectiveEnvironment = hudson.Util.fixEmpty(environment);
for (InspectContainerResponse inspectContainerResponse : inspectContainerResponses) {
final Event event = new DockerEvent(effectiveStatus, inspectContainerResponse.getImageId(),
effectiveHostId, eventTime).toDockerEvent();
final Info hostInfo = new DockerInfo(effectiveHostId, effectiveHostName).toInfo();
DockerTraceabilityReport res = new DockerTraceabilityReport(event, hostInfo,
inspectContainerResponse,
inspectContainerResponse.getImageId(), effectiveImageName,
/* InspectImageResponse */ null, new LinkedList<String>(), effectiveEnvironment);
DockerTraceabilityReportListener.fire(res);
}
return HttpResponses.ok();
}
示例8: doSubmitReport
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
/**
* Submits a new {@link DockerTraceabilityReport} via API.
* @param json String representation of {@link DockerTraceabilityReport}
* @return {@link HttpResponse}
* @throws ServletException Servlet error
* @throws IOException Processing error
*/
@RequirePOST
public HttpResponse doSubmitReport(@QueryParameter(required = true) String json)
throws IOException, ServletException {
checkPermission(DockerTraceabilityPlugin.SUBMIT);
ObjectMapper mapper = new ObjectMapper();
final DockerTraceabilityReport report = mapper.readValue(json, DockerTraceabilityReport.class);
DockerTraceabilityReportListener.fire(report);
return HttpResponses.ok();
}
示例9: doDeleteContainer
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
/**
* Removes the container reference from the registry.
* @param id Container ID. Method supports full 64-char IDs only.
* @throws IOException Cannot save the updated {@link DockerTraceabilityRootAction}
* @throws ServletException Servlet exception
* @return response
*/
@RequirePOST
public HttpResponse doDeleteContainer(@QueryParameter(required = true) String id)
throws IOException, ServletException {
checkPermission(DockerTraceabilityPlugin.DELETE);
removeContainerID(id);
return HttpResponses.ok();
}
示例10: doRawImageInfo
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
/**
* Retrieves the latest raw status via API.
* The output will be retrieved in JSON.
* @param id ID of the image, for which the info should be retrieved.
* Short container IDs are not supported.
* @throws IOException Processing error
* @throws ServletException Servlet error
* @return {@link HttpResponse}
*/
public HttpResponse doRawImageInfo(@QueryParameter(required = true) String id)
throws IOException, ServletException {
checkPermission(DockerTraceabilityPlugin.READ_DETAILS);
final InspectImageResponse report = DockerTraceabilityHelper.getLastInspectImageResponse(id);
if (report == null) {
return HttpResponses.error(404, "No info available for the imageId=" + id);
}
// Return raw JSON in the response
InspectImageResponse[] out = {report};
return toJSONResponse(out);
}
示例11: doBuildJob
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
public HttpResponse doBuildJob(@QueryParameter String issueId) {
@SuppressWarnings("rawtypes")
AbstractProject project = PayLoadInterceptorAction.getMatchingJob(issueId);
if (project != null && project.isBuildable()) {
project.scheduleBuild2(0);
}
return HttpResponses.plainText("Buld triggered: "+issueId);
}
示例12: build
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
@Test
public void build() throws IOException {
FreeStyleProject testProject = jenkins.createFreeStyleProject();
testProject.addTrigger(trigger);
exception.expect(HttpResponses.HttpResponseException.class);
new NoteBuildAction(testProject, getJson("NoteEvent.json"), null).execute(response);
verify(trigger).onPost(any(NoteHook.class));
}
示例13: build_alreadyBuiltMR_alreadyBuiltMR
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
@Test
public void build_alreadyBuiltMR_alreadyBuiltMR() throws IOException, ExecutionException, InterruptedException {
FreeStyleProject testProject = jenkins.createFreeStyleProject();
testProject.addTrigger(trigger);
testProject.setScm(new GitSCM(gitRepoUrl));
QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
future.get();
exception.expect(HttpResponses.HttpResponseException.class);
new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);
verify(trigger).onPost(any(NoteHook.class));
}
示例14: build_alreadyBuiltMR_differentTargetBranch
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
@Test
public void build_alreadyBuiltMR_differentTargetBranch() throws IOException, ExecutionException, InterruptedException {
FreeStyleProject testProject = jenkins.createFreeStyleProject();
testProject.addTrigger(trigger);
testProject.setScm(new GitSCM(gitRepoUrl));
QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new GitLabWebHookCause(causeData()
.withActionType(CauseData.ActionType.NOTE)
.withSourceProjectId(1)
.withTargetProjectId(1)
.withBranch("feature")
.withSourceBranch("feature")
.withUserName("")
.withSourceRepoHomepage("https://gitlab.org/test")
.withSourceRepoName("test")
.withSourceNamespace("test-namespace")
.withSourceRepoUrl("[email protected]:test.git")
.withSourceRepoSshUrl("[email protected]:test.git")
.withSourceRepoHttpUrl("https://gitlab.org/test.git")
.withMergeRequestTitle("Test")
.withMergeRequestId(1)
.withMergeRequestIid(1)
.withTargetBranch("master")
.withTargetRepoName("test")
.withTargetNamespace("test-namespace")
.withTargetRepoSshUrl("[email protected]:test.git")
.withTargetRepoHttpUrl("https://gitlab.org/test.git")
.withTriggeredByUser("test")
.withLastCommit("123")
.withTargetProjectUrl("https://gitlab.org/test")
.build()));
future.get();
exception.expect(HttpResponses.HttpResponseException.class);
new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);
verify(trigger).onPost(any(NoteHook.class));
}
示例15: build
import org.kohsuke.stapler.HttpResponses; //导入依赖的package包/类
@Test
public void build() throws IOException {
try {
FreeStyleProject testProject = jenkins.createFreeStyleProject();
testProject.addTrigger(trigger);
exception.expect(HttpResponses.HttpResponseException.class);
new MergeRequestBuildAction(testProject, getJson("MergeRequestEvent.json"), null).execute(response);
} finally {
ArgumentCaptor<MergeRequestHook> pushHookArgumentCaptor = ArgumentCaptor.forClass(MergeRequestHook.class);
verify(trigger).onPost(pushHookArgumentCaptor.capture());
assertThat(pushHookArgumentCaptor.getValue().getProject(), is(notNullValue()));
assertThat(pushHookArgumentCaptor.getValue().getProject().getWebUrl(), is(notNullValue()));
}
}