Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用JavaRESTAPI在jira中创建问题_Java_Rest_Jira Rest Api - Fatal编程技术网

如何使用JavaRESTAPI在jira中创建问题

如何使用JavaRESTAPI在jira中创建问题,java,rest,jira-rest-api,Java,Rest,Jira Rest Api,我检查了几乎每个链接,但找不到合适的解决方案。 我需要使用JavaRESTAPI在JIRA中创建一个问题。 代码:- 检查异常后,Serverinfo类的claim()函数似乎出现了问题。 或者URL有什么问题? 有什么可以帮助我克服这个问题或任何有用的链接吗?我将与您分享一段代码,我使用IssueInputBuilder类在Jira中创建问题: JiraRestClient restClient; public boolean createIssue(IssueJiraDTO

我检查了几乎每个链接,但找不到合适的解决方案。 我需要使用JavaRESTAPI在JIRA中创建一个问题。 代码:-

检查异常后,Serverinfo类的claim()函数似乎出现了问题。 或者URL有什么问题?
有什么可以帮助我克服这个问题或任何有用的链接吗?

我将与您分享一段代码,我使用
IssueInputBuilder
类在Jira中创建问题:

    JiraRestClient restClient;

    public boolean createIssue(IssueJiraDTO issueDTO) throws IOException{

            final IssueInputBuilder builder = new IssueInputBuilder(PROJECT_KEY, issueDTO.getIssueType(), issueDTO.getSummary());
            final ComponentRestClient componentClient = restClient.getComponentClient();

            try {

                openClient();

                //completamos los datos
                Component component = componentClient.getComponent(new URI(issueDTO.getComponent())).claim();
                builder.setComponents(component);
                builder.setFieldValue(CODCESCEFIELDID, issueDTO.getCodcesce());
                builder.setFieldValue(LINKCAFIELD, issueDTO.getLinkCA().trim());
                builder.setFieldValue(SECURITYFIELD, ComplexIssueInputFieldValue.with("id",  issueDTO.getSecurityLevel()));
                builder.setPriorityId(issueDTO.getPriority());
                builder.setDescription(issueDTO.getDescription());
                final IssueInput input = builder.build();

                // create issue
                final IssueRestClient client = restClient.getIssueClient();
                final BasicIssue issue = client.createIssue(input).claim();
                logger.info("Incidencia creada correctamente: "+ issue.getId());

            }catch(Exception e){
                logger.error("Error al crear la Issue en Jira: " + issueDTO.getCodcesce(), e);
            } finally {
                closeClient();
            }

            return true;
        }
openClient的基本功能是:

restClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(new URI(JIRA_URL), JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);

希望对您有所帮助。

谢谢……但是这里定义的restClient和openClient方法是什么?谢谢……非常有用。你能分享一些关于IssueJiraDTO issueDTO的信息吗?`IssueJiraDTO只是一个自定义bean,其中包含要插入问题中的数据。如果有用的话,你可以接受我的回答@Littlebird:DI尝试了你的代码并做了一些修改,但仍然得到了相同的异常:(
404
表示没有foud,所以可能是你的url错误,或者服务在
https://vgsvdgteam.jira.com
 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" RestClientException{statusCode=Optional.of(404), errorCollections=[ErrorCollection{status=404, errors={}, errorMessages=[]}]}
    at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(DelegatingPromise.java:47)
    at com.citrix.restjira.jiratest.TestingRestAPI.main(TestingRestAPI.java:25)
Caused by: RestClientException{statusCode=Optional.of(404), errorCollections=[ErrorCollection{status=404, errors={}, errorMessages=[]}]}
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:166)
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:160)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:48)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:12)
    at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:285)
    at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:162)
    at com.google.common.util.concurrent.Futures$7.run(Futures.java:1072)
    JiraRestClient restClient;

    public boolean createIssue(IssueJiraDTO issueDTO) throws IOException{

            final IssueInputBuilder builder = new IssueInputBuilder(PROJECT_KEY, issueDTO.getIssueType(), issueDTO.getSummary());
            final ComponentRestClient componentClient = restClient.getComponentClient();

            try {

                openClient();

                //completamos los datos
                Component component = componentClient.getComponent(new URI(issueDTO.getComponent())).claim();
                builder.setComponents(component);
                builder.setFieldValue(CODCESCEFIELDID, issueDTO.getCodcesce());
                builder.setFieldValue(LINKCAFIELD, issueDTO.getLinkCA().trim());
                builder.setFieldValue(SECURITYFIELD, ComplexIssueInputFieldValue.with("id",  issueDTO.getSecurityLevel()));
                builder.setPriorityId(issueDTO.getPriority());
                builder.setDescription(issueDTO.getDescription());
                final IssueInput input = builder.build();

                // create issue
                final IssueRestClient client = restClient.getIssueClient();
                final BasicIssue issue = client.createIssue(input).claim();
                logger.info("Incidencia creada correctamente: "+ issue.getId());

            }catch(Exception e){
                logger.error("Error al crear la Issue en Jira: " + issueDTO.getCodcesce(), e);
            } finally {
                closeClient();
            }

            return true;
        }
restClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(new URI(JIRA_URL), JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);