gpt4 book ai didi

java - 无法将附件添加到新 RT 票证中

转载 作者:行者123 更新时间:2023-12-02 04:44:20 27 4
gpt4 key购买 nike

我目前在项目中使用 RT 4.4.3,并尝试使用 Java 代码创建带有附件的新票证。

我尝试按照 this BestPractical resource 提供的说明进行操作托管在 GitHub 上并在此拉取列表中指定。

尝试执行该操作的代码片段如下:

PostMethod mPost = new PostMethod(TicketListConstants.SEGNALAZIONI_RTIR_URI + "/ticket");

mPost.setRequestHeader("Content-type", "application/json");
mPost.setRequestHeader("Authorization", TicketListConstants.SEGNALAZIONI_RTIR_TOKEN);

/*String json = ;
NameValuePair[] data = {
new NameValuePair("content", json)
};*/
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
File file = uploadRequest.getFile("fileName");
String filename = uploadRequest.getFileName("fileName");

byte[] filecontent = this.encodeBase64(file);

mPost.setRequestBody("{ \"Queue\": \"Infosharing\", \"Subject\": \""+subject+"\",\"From\":\""+currentUser.getEmailAddress()+"\",\"To\":\"test@liferay.com\",\"Owner\":\""
+currentUser.getEmailAddress()+"\",\"Requestor\":\""+currentUser.getEmailAddress()+"\",\"Content\":\""+description+"\",\"AttachmentsContents\":[{\"FileName\":\""+filename+"\",\"FileType\":\"application/pdf\",\"FileContent\":\""+filecontent+"\"}]}");
HttpClient cl = new HttpClient();
String result = "";
String newId = "";
try {
cl.executeMethod(mPost);
result = mPost.getResponseBodyAsString();

if (result != null) {
JSONObject json = null;
try {
json = JSONFactoryUtil.createJSONObject(result);
} catch (JSONException e) {
_log.error("Error extracting ticket info: "+e.getMessage());
}
newId = json.getString("id");
}
} catch (UnsupportedEncodingException e){
_log.error("Error in searching tickets: "+e.getMessage());
} catch (IOException io) {
_log.error("Error in searching tickets: "+io.getMessage());
}

所以我发送到 RT 的 JSON 如下:

{ "Queue": "Infosharing", "Subject": "Tutto in uno","From":"test@liferay.com","To":"test@liferay.com","Owner":"test@liferay.com","Requestor":"test@liferay.com","Content":"Aggiungo tutto in un solo passaggio","AttachmentsContents":[{"FileName":"prova.txt","FileType":"plain/text","FileContent":""}]}

问题在于票证已正确创建,但未添加附件。

我也尝试使用 SOAPUI 执行相同的操作,但即使响应没有任何错误,也不会将附件添加到票证中。

有人可以帮我解决我做错的事情吗?

编辑 2019-06-10: 因为据报道 here ,至少到 2018 年 12 月底为止:

CREATING ATTACHMENTS Currently RT does not allow creating attachments via their API.

See https://rt-wiki.bestpractical.com/wiki/REST#Ticket_Attachment

但作为临时解决方法,应该可以将附件发布到票证评论中,任何人都可以帮助找到此问题的解决方案吗?

最佳答案

由于我无法测试您的代码,我建议您使用 HttpClient 4,我在下面提供了示例代码片段。根据您的要求修改代码并尝试检查。

HttpPost post = new HttpPost("http://rtserver.com");
FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
StringBody stringBody1 = new StringBody("Message 1", ContentType.MULTIPART_FORM_DATA);

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart("upfile", fileBody);
builder.addPart("text1", stringBody1);

HttpEntity entity = builder.build();

post.setEntity(entity);

HttpResponse response = client.execute(post);

关于java - 无法将附件添加到新 RT 票证中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56496445/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com