java - 如何修复 ScriptRunner 中的错误请求 - jira
问题描述
我已经浏览了很长时间的主题,但我找不到我的问题的答案。
我正在尝试在两个 jira 之间进行集成。
当我在邮递员或 SoapUI 上尝试这个 JSON 时,没关系,但在 testRunner 中我有错误
这是我的代码:
import groovy.json.JsonSlurper;
import groovy.json.StreamingJsonBuilder;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger
import org.apache.log4j.Level
import org.apache.commons.io.IOUtils
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
log.debug "dey3"
def baseURL = "https://MYJIRA/rest/api/2/issue/";
def body_req = """
{ "fields":
{
"project": {"key": "JIRA"},
"issuetype": {"name": "Task"},
"summary": "My Issue.",
"description": "Test"
}
}
"""
def basicAuth = "ZzzzzzzzzzzZZZZZZz"
URL url = new URL(baseURL);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setRequestProperty ("Authorization","Basic "+ "ZzzzzzzzzzzZZZZZZz");
connection.requestMethod = "POST";
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();
log.debug HttpURLConnection
log.debug body_req
log.debug (connection.getResponseMessage())
log.debug "Content:"
log.debug connection.getContent()
log.debug (connection.getResponseMessage())
log.debug (connection.getRequestProperties())
log.debug "dey4"
在日志中:
at Script807.run(Script807.groovy:50)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://MYJIRA/rest/api/2/issue/
at Script807.run(Script807.groovy:52)
java.io.IOException: Server returned HTTP response code: 400 for URL: https://MYJIRA/rest/api/2/issue/
2019-06-26 09:45:58,729 http-bio-443-exec-18 ERROR jira 585x33522x1 78fcwl 10.250.112.135 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: HD-113062, actionId: 601, file: <inline script>
2019-06-26 09:45:58,729 http-bio-443-exec-18 ERROR jira 585x33522x1 78fcwl 10.250.112.135 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2019-06-26 09:45:58,727 http-bio-443-exec-18 DEBUG jira 585x33522x1 78fcwl 10.250.112.135 /secure/WorkflowUIDispatcher.jspa [com.acme.CreateSubtask] Content:
2019-06-26 09:45:58,727 http-bio-443-exec-18 DEBUG jira 585x33522x1 78fcwl 10.250.112.135 /secure/WorkflowUIDispatcher.jspa [com.acme.CreateSubtask] Bad Request
2019-06-26 09:45:58,726 http-bio-443-exec-9 DEBUG jira 585x33523x2 1g0o53j 10.250.8.21 /rest/api/2/issue/ [anguswarren.jira.RemoteUserJiraAuth] Session found; user already logged in
2019-06-26 09:45:58,725 http-bio-443-exec-9 DEBUG jira 585x33523x2 1g0o53j 10.250.8.21 /rest/api/2/issue/ [anguswarren.jira.RemoteUserJiraAuth] Session found; user already logged in
2019-06-26 09:45:58,725 http-bio-443-exec-9 DEBUG jira 585x33523x2 1g0o53j 10.250.8.21 /rest/api/2/issue/ [anguswarren.jira.RemoteUserJiraAuth] Session found; user already logged in
2019-06-26 09:45:58,725 http-bio-443-exec-9 DEBUG jira 585x33523x2 - 10.250.8.21 /rest/api/2/issue/ [anguswarren.jira.RemoteUserJiraAuth] Session found; user already logged in
}
}
"description": "Test"
"summary": "My Issue.",
"issuetype": {"name": "Task"},
"project": {"key": "JIRA"},
{
{ "fields":
body_req 的格式是否正确?我不知道这有什么问题。我在任何地方都找不到答案:(
问候
解决方案
也许以编程方式定义有效负载然后将其转换为 json 会更好。只是为了避免逃逸异常或被遗忘的护腕或其他任何东西。尝试像这样定义您的有效负载:
import groovy.json.JsonOutput
def createIssueRequest = new Expando()
createIssueRequest.fields = new Expando(summary: "My Issue.", description: "Test")
createIssueRequest.fields.project = new Expando(key: "JIRA")
createIssueRequest.fields.issuetype = new Expando(name: "Task")
def createIssueJson = JsonOutput.toJson(createIssueRequest)
...
...
...
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, createIssueJson) }
推荐阅读
- swift - 如何使用 RxAlamofire 或 Alamofire 5 及更高版本检查相同的 DataRequest 是否已经在进行中?
- vue.js - 验证错误:未找到预设 @vue/cli-plugin-unit-jest
- git - 2 分支共享一个文件夹的图像?
- c++ - 线性回归方程给出错误答案
- java - 跳过了 172 帧!应用程序可能在其主线程上做了太多工作
- c++ - 一个异常可以触发多个 catch 块吗?
- java - 将 2 个值签入 ENUM
- java - 以套接字返回的字符串作为条件的 if 语句
- javascript - 如何限制使用密码字段的 val() 获取密码?
- javascript - 字符串插值格式在 Firestore 更新功能中不起作用