Can';在Java中使用ComponentRestClient填充JIRA中的components字段

Can';在Java中使用ComponentRestClient填充JIRA中的components字段,java,jira,rest-client,restapi,Java,Jira,Rest Client,Restapi,在java中使用JiraRestClient创建JIRA时,我一直在尝试不同的方法来填充components字段,但不知怎么的,我无法做到这一点。 以下是我尝试过的方法之一- public String createIssue(String projectKey, Long issueType, String issueSummary, String description) throws URISyntaxException { IssueRestClient issueClient

在java中使用JiraRestClient创建JIRA时,我一直在尝试不同的方法来填充components字段,但不知怎么的,我无法做到这一点。 以下是我尝试过的方法之一-

public String createIssue(String projectKey, Long issueType, String issueSummary, String description) throws URISyntaxException {

    IssueRestClient issueClient = restClient.getIssueClient();
    ComponentRestClient componentClient = restClient.getComponentClient();
    String componentUrl = "https://jira.abc.com/issues/?jql=project+%3D+PROJECTKEY+AND+component+%3D+%22Comp+Name%22";
    Component component = componentClient.getComponent(new URI(componentUrl.trim())).claim();
    //BasicComponent bc = new BasicComponent();
    IssueInput newIssue = new IssueInputBuilder(projectKey, issueType, issueSummary)
            .setDescription(description).setComponents(component).build();
    return issueClient.createIssue(newIssue).claim().getKey();
}
在JSON解析步骤中,我发现了这个错误-

at org.codehaus.jettison.json.JSONTokener.syntaxError(JSONTokener.java:439) ~[jettison-1.1.jar:1.1]
at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:169) ~[jettison-1.1.jar:1.1]
at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:266) ~[jettison-1.1.jar:1.1]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$1.handle(AbstractAsynchronousRestClient.java:147) ~[jira-rest-java-client-core-4.0.0.jar:?]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:189) ~[jira-rest-java-client-core-4.0.0.jar:?]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:185) ~[jira-rest-java-client-core-4.0.0.jar:?]
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:81) ~[atlassian-httpclient-api-0.23.0.jar:?]
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:11) ~[atlassian-httpclient-api-0.23.0.jar:?]
at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:268) ~[atlassian-util-concurrent-2.4.2.jar:?]
at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:158) ~[atlassian-util-concurrent-2.4.2.jar:?]
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1132) ~[guava-20.0.jar:?]
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435) ~[guava-20.0.jar:?]
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:900) ~[guava-20.0.jar:?]
位于org.codehaus.jettison.json.JSONTokener.syntaxError(JSONTokener.java:439)~[jettison-1.1.jar:1.1]
在org.codehaus.jettison.json.JSONObject.(JSONObject.java:169)~[jettison-1.1.jar:1.1]
在org.codehaus.jettison.json.JSONObject.(JSONObject.java:266)~[jettison-1.1.jar:1.1]
在com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$1.handle(AbstractAsynchronousRestClient.java:147)~[jira-rest-java-client-core-4.0.0.jar:?]
在com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:189)~[jira-rest-java-client-core-4.0.0.jar:?]
在com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:185)~[jira-rest-java-client-core-4.0.0.jar:?]
在com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:81)~[atlassian-httpclient-api-0.23.0.jar:?]
在com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:11)~[atlassian-httpclient-api-0.23.0.jar:?]
在com.atlassian.util.concurrent.Promissions$3.apply(promissions.java:268)~[atlassian-util-concurrent-2.4.2.jar:?]
在com.atlassian.util.concurrent.Promissions$2.onSuccess(promissions.java:158)~[atlassian-util-concurrent-2.4.2.jar:?]
在com.google.common.util.concurrent.Futures$4.run(Futures.java:1132)~[guava-20.0.jar:?]
在com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435)~[guava-20.0.jar:?]
在com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:900)~[guava-20.0.jar:?]
任何帮助或建议将不胜感激

这应该有效:

    IssueInputBuilder builder = new IssueInputBuilder( projectKey, issueType, issueSummary );

    Iterable<BasicComponent> components = restClient
            .getProject( projectKey )
            .getComponents( );
    
    for ( BasicComponent c : components ) {
        if ( c.getName().equals( "your component name" ) ) {
            builder.setComponents( c ); // assuming you want only one component
        }
    }

    IssueInput newIssue = builder.setDescription(description).build(); // etc...


IssueInputBuilder=新的IssueInputBuilder(项目键、issueType、issueSummary);
Iterable components=restClient
.getProject(projectKey)
.getComponents();
对于(基本组件c:组件){
if(c.getName().equals(“您的组件名称”)){
setComponents(c);//假设您只需要一个组件
}
}
IssueInput newIssue=builder.setDescription(description).build();//等

谢谢Timon,它以这种方式工作,只做了一些修改,但我正在寻找一种更优化的方式,比如我们不需要处理组件,而是希望通过使用ComponentRestClient从JIRA api本身获得此细节。