web stats
How to consume simple SOAP webservice through MirthConnect? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-09-2014, 04:19 AM
farid farid is offline
What's HL7?
 
Join Date: Aug 2014
Location: India
Posts: 3
farid is on a distinguished road
Send a message via Skype™ to farid
Default How to consume simple SOAP webservice through MirthConnect?

Hi all

This forum has been extremely helpful to me in understanding Mirth Connect.

I am trying to consume a very simple SOAP based web service through Mirth Connect 3.0.

However, I am getting a strange NullPointerException:
Web Service Sender error
ERROR MESSAGE: Error invoking web service
javax.xml.ws.WebServiceException: java.lang.NullPointerException
at com.sun.xml.internal.ws.client.dispatch.DispatchIm pl.doInvoke(DispatchImpl.java:196)
I am attaching the channel xml to make it easy to reproduce.



Here are the details of how I configured the Channel:

What I am trying to achieve?
Ability to consume a SOAP based webservice. I chose the freely available currency converter service: http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

How I approached the problem?


Created a channel "wsdl reader"

Source Configuration:
Configured the source to poll every 5 seconds.
In javascript reader settings, I am returning a dummy xml:
return "<dummy/>";

Destination Configuration:
Connector Type: "Web Service Sender"
Pasted the WSDL URL as http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

Clicked on "Get Operations"

Operation: "Conversion Rate"

Clicked on "Generate Envelope"

Updated the following two lines in the generated SOAP Request:

<web:FromCurrency>USD</web:FromCurrency>
<web:ToCurrency>INR</web:ToCurrency>

to
<web:FromCurrency>USD</web:FromCurrency>
<web:ToCurrency>INR</web:ToCurrency>


Saved the channel and deployed the same.

It automatically starts processing as I have configured the source to poll every 5 seconds.

But all the messages are resulting in the same Exception.
Attached Files
File Type: xml wsdl_reader.xml (8.2 KB, 85 views)
Reply With Quote
  #2  
Old 09-09-2014, 07:47 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,097
narupley is on a distinguished road
Default

This is due to MIRTH-1790. Right now when the Web Service Sender pulls down operations, it uses the first service/port it happens to find in the definition. However the one it's using in this case is the HTTP binding, not the SOAP binding (which is incorrect). That will be fixed in 3.1, and in fact you'll be able to choose between multiple services, and multiple ports/endpoints. There are actually two SOAP bindings defined in the WSDL, one for 1.1 and one for 1.2.

To get around it in 3.0.3, you can manually edit the port QName:

Code:
{http://www.webserviceX.NET/}CurrencyConvertorSoap12
Then use the correct SOAP 1.2 envelope:

Code:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET/">
   <soap:Header/>
   <soap:Body>
      <web:ConversionRate>
         <web:FromCurrency>USD</web:FromCurrency>
         <web:ToCurrency>INR</web:ToCurrency>
      </web:ConversionRate>
   </soap:Body>
</soap:Envelope>
If you don't want to use SOAP 1.2 you can just use the "Soap" port (without the "12") and leave your envelope alone.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 09-10-2014, 02:22 AM
farid farid is offline
What's HL7?
 
Join Date: Aug 2014
Location: India
Posts: 3
farid is on a distinguished road
Send a message via Skype™ to farid
Default The prefix "soap" for element "soap:Envelope" is not bound

Thanks a lot for answering my query. I appreciate your quick response.

I am now following the suggested workaround and I am able to hit the web-service and get the response.

While trying to parse the response through "Edit Response" I am facing another error.

What I added in the "Edit Response" (Response Transformer)

Code:
var soap = "http://www.w3.org/2003/05/soap-envelope";
var value1 = msg.soap::['Body']['ConversionRateResponse']['ConversionRateResult'].toString()
logger.info('message'+value1);
Error message that is occuring while processing the same.

Code:
Response Transformer error
ERROR MESSAGE: Error evaluating response transformer
com.mirth.connect.server.MirthJavascriptTransformerException: 
CHANNEL:	wsdl_reader
CONNECTOR:	currency service
SCRIPT SOURCE:	response
SOURCE CODE:	
20:         }
21:         eval('importPackage(' + Packages.java.lang.Class.forName(className).getPackage().getName() + ')');
22:     }
23: }
24: function doScript() {
25: msg = new XML(connectorMessage.getResponseTransformedData());
26: if (msg.namespace('') != undefined) { default xml namespace = msg.namespace(''); } else { default xml namespace = ''; }
27: function doTransform() {
28: 
29: 
LINE NUMBER:	25
DETAILS:	TypeError: The prefix "soap" for element "soap:Envelope" is not bound.
	at 304423fc-979c-4676-b2dd-48b7499bb9e3:25 (doScript)
	at 304423fc-979c-4676-b2dd-48b7499bb9e3:37
	at com.mirth.connect.server.transformers.JavaScriptResponseTransformer$ResponseTransformerTask.call(JavaScriptResponseTransformer.java:145)
	at com.mirth.connect.server.transformers.JavaScriptResponseTransformer$ResponseTransformerTask.call(JavaScriptResponseTransformer.java:100)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
On replacing the code from "Response transformer" with a simple one liner like:

Code:
logger.info("Hello");
I noticed that the error is still occuring. This is suggesting that Mirth Connect is not able to convert the received response properly as the error is occurring at this line within Mirth Connect.

Code:
25: msg = new XML(connectorMessage.getResponseTransformedData());
Looking forward to your response for a possible solution to this problem or any alternate way of achieving the same.

I am attaching the updated channel xml file for quick reference.
Attached Files
File Type: xml wsdl_reader.xml (9.0 KB, 54 views)

Last edited by farid; 09-10-2014 at 02:30 AM. Reason: Added some more findings
Reply With Quote
  #4  
Old 09-10-2014, 06:47 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,097
narupley is on a distinguished road
Default

First, uncheck Strip Namespaces from the response inbound data type (XML).

Next, there's not only the "soap" namespace prefix, but also the ConversionRateResponse node defines its own namespace. So do this instead:

Code:
var soap = new Namespace('http://www.w3.org/2003/05/soap-envelope');
var ns1 = new Namespace('http://www.webserviceX.NET/');
var result = msg.soap::Body.ns1::ConversionRateResponse.ns1::ConversionRateResult.toString();
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #5  
Old 09-11-2014, 03:17 AM
farid farid is offline
What's HL7?
 
Join Date: Aug 2014
Location: India
Posts: 3
farid is on a distinguished road
Send a message via Skype™ to farid
Default

Many thanks !!!

This worked like a charm.

So, for anyone looking out to consume a SOAP based WebService, I am attaching a channel that worked for me.

In order to test this channel, Import this channel xml file in MirthConnect.
Deploy the channel
Send a Message from dashboard UI to this channel.
This channel will hit the WebService to convert USD into INR.

Hope it helps someone like me.

Thanks & Regards
Mohd Farid
Attached Files
File Type: xml wsdl_reader.xml (8.8 KB, 573 views)

Last edited by farid; 09-11-2014 at 03:51 AM. Reason: Added a sample that worked for me
Reply With Quote
Reply

Tags
exception, polling, soap, webservice

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 06:02 PM.


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