3

我可能不是第一个尝试使用 Webmethods Service 的 JIRA REST API 向 JIRA 添加附件的人。所以希望有人能提供帮助。

有两个问题,一个与 JIRA REST API 有关,两个与 Webmethods MIME 服务(版本 9.8)有关。

构建 addAttachment 服务,使用 JIRA REST API 将 json inputStream 作为附件添加到 JIRA。

在 webmethods 中使用以下服务,

pub.string:stringtoBytes.
pub.io:bytestoStream.
pub.mime:createMimeData.
pub.mime:addBodyPart.
pub.mime:getEnvelopeStream.
pub.io:streamToString.
pub.client:http.

它产生的 Mime Stream 如下,(1.问题 1,虽然在 addBodyPart 中,我们将消息头设置为 application/json,但它似乎被覆盖并设置为自己的解释?2.问题 2,虽然边界在标题中设置为mmmm,Webmethods似乎使用自己的边界值)请您帮忙解决这个问题。如果需要,可以提供屏幕截图。

    Message-ID: <786753280.135.1438880433399.JavaMail.webm@ruudwmia01>
    MIME-Version: 1.0
    Content-type: multipart/form-data
    boundary: mmmm
    name: file
    filename: test.json
            
    ------=_Part_134_59669361.1438880433399
    Message-ID: <902143670.133.1438880433399.JavaMail.webm@ruudwmia01>
    MIME-Version: 1.0
    content-type: text/plain
    content-transfer-encoding: 7bit
    {"self": "http://localhost:8090/jira/rest/api/2.0/status/10000","description": "The issue is currently being worked on.","iconUrl":"http://localhost:8090/jira/images/icons/progress.gif","name": "In Progress","id": "10000","statusCategory":{"self":"http://localhost:8090/jira/rest/api/2.0/statuscategory/1","id": 1, "key":"in-flight","colorName": "yellow","name": "In Progress" }}
            
            
    ------=_Part_134_59669361.1438880433399--

问题 2,使用 JIRA REST API,上述 mime 文档作为输入抛出 415 Unsupported Media Type,从 HTTP POST CALL 到 URL,尝试通过调用 JIRA REST API 添加附件。

它是一个http客户端POST调用,传入一个mime对象——作为流,传入的mime流为ABOVE,得到415,不支持的媒体类型错误消息。JIRA 日志中没有任何内容。

4

2 回答 2

2

尝试通过仅使用以下值设置 mimeHeader 的输入文档来调用服务“pub.mime:createMimeHeader”:

名称=内容类型值=多部分/表单数据;边界=mm

使用“contenttype”输入字段将“application/json”标头添加到“pub.mime:addBodyPart”服务。不要在 pub.client:http 服务中设置标头。

请注意您确实创建了一个多部分消息(至少两个部分),否则整个消息的内容类型将设置为您的 mime 正文的内容类型,如文档中所定义:

contenttype 字符串 可选。此正文部分的 Content-Type 标头的值。对于单部分消息,此值将覆盖 mimeHeader 中的 Content-Type 值(如果存在)。默认为文本/纯文本。

这样做我得到以下输出:

2015-08-06 22:28:10 CEST [ISP.0090.0001C] --- START tracePipeline 

[8/6/15 10:28 PM] ---
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 0 Message-ID: <7862407.17.1438892890984.JavaMail.Administrator@sagbase>
MIME-Version: 1.0
Content-Type: multipart/form-data; boundary {java.lang.String} = 'mmm

--mmm
content-type: application/json

[
    "serviceName": "wx.interceptor.test.pub.measureRuntimeGraph:tester",
    "stats": {
        "avgRuntimeNano": "74918747.333",
        "standardDeviationNano": "65542825.906",
        "minNano": "12718935",
        "maxNano": "171054910",
        "varianceNano": "4295862027740509",
        "sumNano": "674268726",
        "invocations": "9"
    }
]
--mmm
content-type: application/json

[
    "serviceName": "wx.interceptor.test.pub.measureRuntimeGraph:tester",
    "stats": {
        "avgRuntimeNano": "74918747.333",
        "standardDeviationNano": "65542825.906",
        "minNano": "12718935",
        "maxNano": "171054910",
        "varianceNano": "4295862027740509",
        "sumNano": "674268726",
        "invocations": "9"
    }
]
--mmm--
'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 0 transport {com.wm.util.Values} => 
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 1 protocol {java.lang.String} = 'http'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 1 subprotocol {java.lang.String} = 'HTTP'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 1 http {com.wm.util.Values} => 
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 2 requestUrl {java.lang.String} = '/rest/test/new_rest'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 2 method {java.lang.String} = 'POST'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 2 requestHdrs {com.wm.util.Values} => 
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 User-Agent {java.lang.String} = 'Mozilla/4.0 [en] (WinNT; I)'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 Accept {java.lang.String} = 'image/gif, */*'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 Host {java.lang.String} = 'localhost:5597'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 Content-Type {java.lang.String} = 'application/x-www-form-urlencoded'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 Content-Length {java.lang.String} = '864'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 2 ipInfo {com.wm.util.Values} => 
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 localIp {java.lang.String} = '127.0.0.1'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 localPort {java.lang.String} = '5597'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 remoteIp {java.lang.String} = '127.0.0.1'
2015-08-06 22:28:10 CEST [ISP.0090.0008C] 3 remotePort {java.lang.String} = '60228'
2015-08-06 22:28:10 CEST [ISP.0090.0002C] --- END tracePipeline ---

我正在使用 wM 9.7 顺便说一句。

于 2015-08-06T20:32:55.017 回答
0

In the pub.mime:createMimeData, Resolved this by Setting the mimeHeader, not as seperate values, but by adding only one value and within the box, seperated the header values by semi-colon, like

multipart/form-data;boundary="------defined------";name=file;filename=sample.txt

as for some reason, Webmethods adds a carriage return at end of setting Content-type, and the boundary value we set was not taken into consideration.

The generated message now looks like, `Message-ID: <1895464254.184.1439491915636.JavaMail.webm@ruudwmia01> MIME-Version: 1.0 Content-Type: multipart/form-data; boundary=------defined------; name=file; filename=sample.txt

--------defined------ Content-Type: application/text

{"self": "http://localhost:8090/jira/rest/api/2.0/status/10000", "description": "The issue is currently being worked on.", "iconUrl": "http://localhost:8090/jira/images/icons/progress.gif", "name": "In Progress", "id": "10000", "statusCategory": { "self": "http://localhost:8090/jira/rest/api/2.0/statuscategory/1", "id": 1, "key": "in-flight", "colorName": "yellow", "colorName": "yellow", "key": "in-flight", "colorName": "yellow", "key": "in-flight", "colorName": "yellow", "key": "in-flight", "colorName": "yellow", "key": "in-flight", "colorName": "yellow", "name": "In Progress" }} --------defined------ Content-Type: application/text

{"self": "http://localhost:8090/jira/rest/api/2.0/status/10000", "description": "The issue is currently being worked on.", "iconUrl": "http://localhost:8090/jira/images/icons/progress.gif", "name": "In Progress", "id": "10000", "statusCategory": { "self": "http://localhost:8090/jira/rest/api/2.0/statuscategory/1", "id": 1, "key": "in-flight", "colorName": "yellow", "key": "in-flight", "colorName": "yellow", "key": "in-flight", "colorName": "yellow", "colorName": "yellow", "name": "In Progress" }} --------defined--------`

于 2015-08-13T19:01:35.343 回答