Announcement

Collapse
No announcement yet.

How to consume simple SOAP webservice through MirthConnect?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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.

    Comment


    • #3
      The prefix &quot;soap&quot; for element &quot;soap:Envelope&quot; 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
      Last edited by farid; 09-10-2014, 02:30 AM. Reason: Added some more findings

      Comment


      • #4
        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.

        Comment


        • #5
          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
          Last edited by farid; 09-11-2014, 03:51 AM. Reason: Added a sample that worked for me

          Comment


          • #6
            hi friend

            Comment

            Working...
            X