org.kohsuke.stapler.verb.POST Java Examples

The following examples show how to use org.kohsuke.stapler.verb.POST. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BluePipelineContainer.java    From blueocean-plugin with MIT License 6 votes vote down vote up
/**
 * Create new pipeline.
 *
 * @param body {@link BluePipelineCreateRequest} request object
 * @return {@link CreateResponse} response
 */
@POST
@WebMethod(name = "")
public  CreateResponse create(@JsonBody JSONObject body, StaplerRequest staplerRequest) throws IOException{
    ErrorMessage err = new ErrorMessage(400, "Failed to create Git pipeline");

    if(body.get("name") == null){
        err.add(new ErrorMessage.Error("name", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "name is required"));
    }

    if(body.get("$class") == null){
        err.add(new ErrorMessage.Error("$class", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "$class is required"));
    }

    if(!err.getErrors().isEmpty()){
        throw new ServiceException.BadRequestException(err);
    }

    BluePipelineCreateRequest request = staplerRequest.bindJSON(BluePipelineCreateRequest.class, body);
    return create(request);
}
 
Example #2
Source File: GitHubAppCredentials.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@POST
@SuppressWarnings("unused") // stapler
@Restricted(NoExternalUse.class) // stapler
public FormValidation doTestConnection(
        @QueryParameter("appID") final String appID,
        @QueryParameter("privateKey") final String privateKey,
        @QueryParameter("apiUri") final String apiUri,
        @QueryParameter("owner") final String owner

) {
    GitHubAppCredentials gitHubAppCredential = new GitHubAppCredentials(
            CredentialsScope.GLOBAL, "test-id-not-being-saved", null,
            appID, Secret.fromString(privateKey)
    );
    gitHubAppCredential.setApiUri(apiUri);
    gitHubAppCredential.setOwner(owner);

    try {
        GitHub connect = Connector.connect(apiUri, gitHubAppCredential);
        return FormValidation.ok("Success, Remaining rate limit: " + connect.getRateLimit().getRemaining());
    } catch (Exception e) {
        return FormValidation.error(e, String.format(ERROR_AUTHENTICATING_GITHUB_APP, appID));
    }
}
 
Example #3
Source File: ConfigurationAsCode.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@POST
@Restricted(NoExternalUse.class)
public FormValidation doCheckNewSource(@QueryParameter String newSource) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    String normalizedSource = Util.fixEmptyAndTrim(newSource);
    File file = new File(Util.fixNull(normalizedSource));
    if (normalizedSource == null) {
        return FormValidation.ok(); // empty, do nothing
    }
    if (!file.exists() && !ConfigurationAsCode.isSupportedURI(normalizedSource)) {
        return FormValidation.error("Configuration cannot be applied. File or URL cannot be parsed or do not exist.");
    }

    List<YamlSource> yamlSources = Collections.emptyList();
    try {
        List<String> sources = Collections.singletonList(normalizedSource);
        yamlSources = getConfigFromSources(sources);
        final Map<Source, String> issues = checkWith(yamlSources);
        final JSONArray errors = collectProblems(issues, "error");
        if (!errors.isEmpty()) {
            return FormValidation.error(errors.toString());
        }
        final JSONArray warnings = collectProblems(issues, "warning");
        if (!warnings.isEmpty()) {
            return FormValidation.warning(warnings.toString());
        }
        return FormValidation.okWithMarkup("The configuration can be applied");
    } catch (ConfiguratorException | IllegalArgumentException e) {
        return FormValidation.error(e, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    }
}
 
Example #4
Source File: AnalyticsRoute.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@POST
@WebMethod(name = "track")
public void track(StaplerRequest staplerRequest) throws IOException {
    Analytics analytics = Analytics.get();
    if (analytics == null) {
        return;
    }
    TrackRequest req;
    try (InputStream is = staplerRequest.getInputStream()) {
        req = JsonConverter.toJava(is, TrackRequest.class);
    }
    analytics.track(req);
}
 
Example #5
Source File: CredentialApi.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@POST
@WebMethod(name = "")
public CreateResponse create(@JsonBody JSONObject body, StaplerRequest request) throws IOException {

    User authenticatedUser =  User.current();
    if(authenticatedUser == null){
        throw new ServiceException.UnauthorizedException("No authenticated user found");
    }

    JSONObject jsonObject = body.getJSONObject("credentials");
    final IdCredentials credentials = request.bindJSON(IdCredentials.class, jsonObject);

    String domainName = DOMAIN_NAME;

    if(jsonObject.get("domain") != null && jsonObject.get("domain") instanceof String){
        domainName = (String) jsonObject.get("domain");
    }

    CredentialsUtils.createCredentialsInUserStore(credentials, authenticatedUser, domainName,
            ImmutableList.of(new BlueOceanDomainSpecification()));

    CredentialsStoreAction.DomainWrapper domainWrapper = credentialStoreAction.getDomain(domainName);


    if(domainWrapper != null) {
        CredentialsStoreAction.CredentialsWrapper credentialsWrapper = domainWrapper.getCredential(credentials.getId());
        if (credentialsWrapper != null){
            return new CreateResponse(
                    new CredentialApi.Credential(
                            credentialsWrapper,
                            getLink().rel("domains").rel(domainName).rel("credentials")));
        }
    }

    //this should never happen
    throw new ServiceException.UnexpectedErrorException("Unexpected error, failed to create credential");
}
 
Example #6
Source File: CredentialApi.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@POST
@WebMethod(name = "")
@Deprecated
public CreateResponse create(@JsonBody JSONObject body, StaplerRequest request) throws IOException {

    final IdCredentials credentials = request.bindJSON(IdCredentials.class, body.getJSONObject("credentials"));
    domainWrapper.getStore().addCredentials(domainWrapper.getDomain(), credentials);


    final Domain domain = domainWrapper.getDomain();
    domainWrapper.getStore().addCredentials(domain, credentials);

    return new CreateResponse(new Credential(domainWrapper.getCredentials().get(credentials.getId()), getLink()));
}
 
Example #7
Source File: BlueRunContainer.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@POST
@WebMethod(name = "")
@TreeResponse
public abstract BlueRun create(StaplerRequest request);
 
Example #8
Source File: MattermostNotifier.java    From jenkins-mattermost-plugin with MIT License 4 votes vote down vote up
@POST
 public FormValidation doTestConnection(
     @QueryParameter("endpoint") final String endpoint,
     @QueryParameter("room") final String room,
     @QueryParameter("icon") final String icon,
     @QueryParameter("buildServerUrl") final String buildServerUrl)
     throws FormException {
   if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER))
   {
     return FormValidation.error("Insufficient permission.");
   }
   try {
     String targetEndpoint = endpoint;
     if (StringUtils.isEmpty(targetEndpoint)) {
targetEndpoint = this.getEndpoint().getPlainText();
     }
     String targetRoom = room;
     if (StringUtils.isEmpty(targetRoom)) {
       targetRoom = this.room;
     }
     String targetIcon = icon;
     if (StringUtils.isEmpty(targetIcon)) {
       targetIcon = this.icon;
     }
     String targetBuildServerUrl = buildServerUrl;
     if (StringUtils.isEmpty(targetBuildServerUrl)) {
       targetBuildServerUrl = this.buildServerUrl;
     }
     MattermostService testMattermostService =
         getMattermostService(targetEndpoint, targetRoom, targetIcon);
     String message =
         "Mattermost/Jenkins plugin: you're all set! (parameters: "
             + "room='"
             + targetRoom
             + "', "
             + "icon='"
             + targetIcon
             + "', "
             + "buildServerUrl='"
             + targetBuildServerUrl
             + "'"
             + ")";
     boolean success = testMattermostService.publish(message, "good");
     return success ? FormValidation.ok("Success") : FormValidation.error("Failure");
   } catch (Exception e) {
     return FormValidation.error("Client error : " + e.getMessage());
   }
 }
 
Example #9
Source File: BluePipelineStep.java    From blueocean-plugin with MIT License 2 votes vote down vote up
/**
 * Processes submitted input step via POST request
 * @param request stapler request
 * @return http response
 */
@POST
@WebMethod(name = "")
public abstract HttpResponse submitInputStep(StaplerRequest request);
 
Example #10
Source File: BlueExtensionClassContainer.java    From blueocean-plugin with MIT License 2 votes vote down vote up
/**
 * Gives Map of given class in the query to {@link BlueExtensionClass}
 *
 * @param request POST body with query element with value as list of classes e.g.
 *                {'q':['class1', 'class2', 'class3']}
 *
 *
 * @return Map of given class in the query to {@link BlueExtensionClass}. If given class in the parameter is not
 *         known then 400, BadRequest should be returned
 */
@POST
@WebMethod(name= "")
@TreeResponse
public abstract BlueExtensionClassMap getMap(@JsonBody Map<String,List<String>> request);
 
Example #11
Source File: BluePipelineNode.java    From blueocean-plugin with MIT License 2 votes vote down vote up
/**
 *
 * @param request To restart the content must be simple json body with a field <code>restart</code> will value <code>true</code>
 * @return the response content will be {@link BlueRun}
 */
@POST
@WebMethod(name = "restart")
public abstract HttpResponse restart( StaplerRequest request);
 
Example #12
Source File: BlueRun.java    From blueocean-plugin with MIT License 2 votes vote down vote up
/**
 * Replays a pipeline. The SCM commit/revision used in the existing and new runs should match.
 *
 * @return The queued item.
 */
@POST @TreeResponse @WebMethod(name = "replay")
public abstract BlueRun replay();
 
Example #13
Source File: ScmServerEndpointContainer.java    From blueocean-plugin with MIT License 2 votes vote down vote up
/**
 * Create {@link ScmServerEndpoint} instance
 *
 * @param request SCM endpoint request
 * @return instance of ScmEndpoint
 */
@POST
@WebMethod(name="")
@TreeResponse
public abstract ScmServerEndpoint create(@JsonBody JSONObject request);