web stats
accessing a RESTful web service? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 11-01-2011, 10:45 AM
DavidL DavidL is offline
OBX.1 Kenobi
Join Date: Sep 2011
Location: Dayton Ohio
Posts: 43
DavidL is on a distinguished road
Unhappy accessing a RESTful web service?

I guess I should note that not only am I new to Mirth, but I've been stuck mostly supporting thick client applications for a few years, so I'm somewhat new to web services as well.

I'm trying to set up a destination for an external partner. They've given us a (RESTful) web service URL and some sample Java code which uses the Apache Commons HttpClient (I note this only because that's what Mirth seems to be using internally).
The service expects data in JSON format, which I suppose is somewhat unusual.

I know that, since it's a REST web service, I need to use the HTTP sender rather than the Web Service (SOAP) sender.

I can send just fine using the sample Java code they sent us; but in Mirth I invariably get an error 415 (unsupported media type). I've tried:
+ changing the content type to "application/json",
+ setting Multipart to true;
+ enabling response headers;
... but nothing is working.

I performed a packet capture using Wireshark, and I noticed the following.
It appears that Mirth is appending a question mark to the URL -- which would make sense if I had query parameters, but I don't.
The Java snippet is *not* sending a Content-Type header.
The Java sample results in the data being sent as a separate packet.

Any help would be much appreciated. Thanks in advance.
Reply With Quote
Old 11-01-2011, 11:49 AM
ironbridge ironbridge is offline
OBX.1 Kenobi
Join Date: Jul 2011
Location: Pittsburgh, Pa
Posts: 33
ironbridge is on a distinguished road

Hi David. When the resful services I need to call from Mirth become too complicated, I often use custom code in a transformer step to make the call.

Here's a post that describes how to call a secure https service, but the same method could be used for a custom json web service I suppose. Json would be nice because you could eval the json string that you receive back from the web service.

Reply With Quote
Old 03-16-2012, 12:54 PM
joshillian joshillian is offline
Mirth Newb
Join Date: May 2010
Location: Temple, TX
Posts: 9
joshillian is on a distinguished road

We've been able to do this using an HTTP Sender.

Just set the Content Type to:
And then in the Content itself put something like:
{  "name1":"${value1}", "name2":"{value2}" }
where in this case value1 and value2 are variables that are available in your Destination Mappings. In my case, I assign these variables to the connectorMap in the transformer.
Reply With Quote
Old 03-16-2012, 01:03 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
Join Date: Oct 2010
Posts: 7,125
narupley is on a distinguished road

Also, be aware that the HTTP Sender behaviour changed from 2.1.1 to 2.2. I was using an HTTP Sender in 2.1.1 to send HTTP POST requests and it was working great; I was sending the POST data by including the encoded URL in the payload (template), with a type of application/x-www-form-urlencoded. Then I upgraded to 2.2 and my HTTP Sender wasn't working anymore. To get it work I just included all the variables as query parameters instead of encoding them as a URL in the payload.
Reply With Quote
Old 03-25-2012, 03:44 PM
rwhelan rwhelan is offline
Mirth Newb
Join Date: Sep 2011
Posts: 15
rwhelan is on a distinguished road

Quick note: narupley's response is correct and helpful for anyone who wants to do a normal POST, but won't help with what you're doing.

I've recently been digging through the Java source for HTTP connector, or I wouldn't know this either... but you'll find the relevant handling in HttpMessageDispatcher.java:

if (isMultipart) {
    logger.debug("setting multipart file content");
    File tempFile = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
    FileUtils.writeStringToFile(tempFile, content, charset);
    Part[] parts = new Part[] { new FilePart(tempFile.getName(), tempFile, contentType, charset) };
    postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
} else if (StringUtils.equals(contentType, "application/x-www-form-urlencoded")) {
} else {
    postMethod.setRequestEntity(new StringRequestEntity(content, contentType, charset));
So the parameters will be sent in the body (normal browser handling for a POST form), but ONLY if you explicitly set the content type field to "application/x-www-form-urlencoded". And in that case, anything you put in the "body" field is ignored.

If you take joshillian's advice and set content-type to "text/json" or anything else, you get different handling -- and any parameters you list are appended to the query string, while the body you specified is sent as the POST body.

[Edit: also note there's a minor bug in the administrator: even when using content type "application/x-www-form-urlencoded" you're still forced to put a value in the body field, even though it will be discarded.]

Rob Whelan

Last edited by rwhelan; 03-25-2012 at 03:57 PM. Reason: addendum: minor bug
Reply With Quote

http sender, rest, web service

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 09:15 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation