3
votes

I am probably not the first person trying to add an attachment to JIRA, using JIRA REST API from Webmethods Service. So hoping someone will be able to help.

There are two issues, one with JIRA REST API, two with the Webmethods MIME services(Version 9.8).

Building a addAttachment Service, to add as an attachment a json inputStream to JIRA, using JIRA REST API.

Making use of the following services in webmethods,

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

The Mime Stream it produces, is as below, (1. Problem 1, Although, in addBodyPart, we are setting the message header to application/json, it seems to be overriding and setting to its own interpretation? 2. Problem 2, although the Boundary is set in the Header to mmmm, Webmethods seems to use its own boundary value) Please can you help resolve this. Can provide with screenshots if required.

    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--

Problem 2, with JIRA REST API, the above mime document as input throws, 415 Unsupported Media Type, from the HTTP POST CALL, to URL, Trying to add an attachment by invoking JIRA REST API.

It is a http client POST call, passing in a mime object - as a stream, the mime stream that is passed in is as ABOVE, Get a 415, Unsupported Media Type Error Message. Nothing in the JIRA Logs.

2

2 Answers

2
votes

Try to invoke the service "pub.mime:createMimeHeader" by only setting the input document for the mimeHeader with the following values:

Name=Content-Type Value=multipart/form-data; boundary=mmm

Add your "application/json" header to the "pub.mime:addBodyPart" service with the "contenttype" input-field. Do not set the header in the pub.client:http service.

Take care that you really create a multipart message (at least two parts), else the content-type of the entire message is set to content type of your mime body, as defined in the documentation:

contentype String Optional. The value of the Content-Type header for this body part. For single-part messages, this value overrides the Content-Type value in mimeHeader , if one is present. Defaults to text/plain.

Doing it like this I get the following output:

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 ---

I am using wM 9.7 btw.

0
votes

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--------`