web stats
Mirth 3.0 Web Service question - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-18-2013, 08:09 AM
mtod mtod is offline
OBX.2 Kenobi
 
Join Date: Aug 2013
Posts: 57
mtod is on a distinguished road
Default Mirth 3.0 Web Service question

I have setup a simple Web Service to test out MIRTH.
  • Data Types Set to XML.
  • Source Web Service
  • Dest. Channel

Seems the only way I can get the payload is to send it wrapped in CDATA.

Is there no way to send only XML?

I have other web services I use (not in Mirth) that accept pure XML so why does Mirth require CDATA?

Or am I doing something wrong.

Mike
Reply With Quote
  #2  
Old 11-18-2013, 10:08 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Yes that's right; currently by default the Web Service Listener can only accept in-place XML as the message if it's entity-encoded as a text element, or if it's in a CDATA tag.

However you can get around this by creating a simple web service that extends AcceptMessage:

Code:
package com.your.packagename.here;

import java.io.ByteArrayInputStream;

import javax.jws.WebMethod;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Provider;
import javax.xml.ws.WebServiceProvider;

import org.apache.log4j.Logger;
import org.w3c.dom.Element;

import com.mirth.connect.connectors.ws.AcceptMessage;
import com.mirth.connect.connectors.ws.WebServiceReceiver;
import com.mirth.connect.donkey.util.DonkeyElement;
import com.mirth.connect.donkey.util.DonkeyElement.DonkeyElementException;

@WebServiceProvider
public class AcceptXMLMessage extends AcceptMessage implements Provider<Source> {
    
    private Logger logger = Logger.getLogger(getClass());

    public AcceptXMLMessage(WebServiceReceiver webServiceReceiver) {
        super(webServiceReceiver);
    }
    
    @Override
    public Source invoke(final Source request) {
        try {
            DonkeyElement element = new DonkeyElement((Element) ((DOMSource) request).getNode());
            DonkeyElement arg0 = element.getChildElement("arg0");
            String message = "";
            
            if (arg0.getChildElements().size() > 0) {
                for (DonkeyElement child : arg0.getChildElements()) {
                    message += child.toXml();
                }
            } else {
                message = arg0.getTextContent();
            }
            
            String response = webServiceReceiver.processData(message);
            String responseXml = "<ns2:acceptMessageResponse xmlns:ns2=\"http://ws.connectors.connect.mirth.com/\"";
            
            if (response != null) {
                responseXml += "><return>" + response + "</return></ns2:acceptMessageResponse>";
            } else {
                responseXml += "/>";
            }
            
            return new StreamSource(new ByteArrayInputStream(responseXml.getBytes()));
        } catch (DonkeyElementException e) {
            logger.error("Error invoking web service.", e);
        }
        
        return null;
    }

    @WebMethod
    public String acceptMessage(String message) {
        String response = webServiceReceiver.processData(message);

        if (response != null) {
            return response;
        }
        
        return null;
    }

}
__________________
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 11-18-2013, 11:01 AM
mtod mtod is offline
OBX.2 Kenobi
 
Join Date: Aug 2013
Posts: 57
mtod is on a distinguished road
Default

Thanks for the reply.

I kind of figured that must be the answer.

I wanted to create a customer WS but I'm a C# programmer not Java but I would really like to understand the steps involved in creating a Jar file for Mirth.

I have eclipse install and tried to create something for Mirth but keep going in circles.

Is there any guidance you can provide on the steps required?

Thanks Again

Mike
Reply With Quote
  #4  
Old 11-18-2013, 01:00 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

There are a great many tutorials and examples out there on the net about starting out with Java, how to compile and create JARs, etc. Here's one:

http://ant.apache.org/manual/tutoria...ldWithAnt.html
__________________
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 11-18-2013, 08:43 PM
rohit.chawla12 rohit.chawla12 is offline
OBX.2 Kenobi
 
Join Date: Oct 2013
Location: Australia
Posts: 72
rohit.chawla12 is on a distinguished road
Default

Hi,

Follow below steps:
1. Download the FAT JAR Eclipse plugin from the URL http://sourceforge.net/projects/fjep/.

2. Unzip the zip file.

3. Copy the JAR file into the /plugin folder inside the home directory of eclipse IDE.

4. Relaunch the eclipse.

5. Find the "FAT JAR Exporter" option in File->Export->Other option.

6. Select the required project and create the JAR file.

7. Stop the mirth server and copy the JAR file in the /custom-lib folder of the Mirth home directory.

8. Start Mirth server and now java classes can be used using javascript.

Last edited by rohit.chawla12; 11-18-2013 at 08:47 PM.
Reply With Quote
  #6  
Old 11-20-2013, 07:09 AM
mtod mtod is offline
OBX.2 Kenobi
 
Join Date: Aug 2013
Posts: 57
mtod is on a distinguished road
Default

That's what I was looking for Thanks!!!
Reply With Quote
  #7  
Old 11-20-2013, 08:41 AM
mtod mtod is offline
OBX.2 Kenobi
 
Join Date: Aug 2013
Posts: 57
mtod is on a distinguished road
Default

I used the Web Service example from narupley above and compiled it into a Jar file and placed it in the custom-lib folder.
I then restarted Mirth and created a default Web Listener I selected the custom Web Service option and modified the Service Class Name: com.mirth.connect.connectors.ws.AcceptXMLMessage

I keep getting errors when I deploy the channel not sure what I'm doing wrong.

[2013-11-20 09:24:09,035] ERROR (com.mirth.connect.connectors.ws.WebServiceReceive r:101): Custom web service class initialization failed
java.lang.ClassNotFoundException: com.mirth.connect.connectors.ws.AcceptXMLMessage
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.mirth.connect.connectors.ws.WebServiceReceiver .onStart(WebServiceReceiver.java:83)
at com.mirth.connect.donkey.server.channel.SourceConn ector.start(SourceConnector.java:88)
at com.mirth.connect.donkey.server.channel.Channel$St artTask.call(Channel.java:1858)
at com.mirth.connect.donkey.server.channel.Channel$St artTask.call(Channel.java:1780)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
Reply With Quote
  #8  
Old 11-20-2013, 10:24 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

You probably have the fully qualified class name wrong. Look at the original code:

Quote:
Originally Posted by narupley View Post
Code:
package com.your.packagename.here;

...
The package is not "com.mirth.connect.connectors.ws", it's "com.your.packagename.here". Change it as you see fit and then use the correct class name in the listener settings.
__________________
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
  #9  
Old 11-20-2013, 12:43 PM
mtod mtod is offline
OBX.2 Kenobi
 
Join Date: Aug 2013
Posts: 57
mtod is on a distinguished road
Default

So I adjusted the package as follows:

package com.foundationmedicine.mirth;

Built the JAR and placed it in the custom-lib folder and restarted MIRTH.

Adjusted the Source settings:

com.foundationmedicine.mirth.AcceptXMLMessage

[IMG]c:\temp\capture.jpg[/IMG]

I'm still getting the Class Not found error.


[2013-11-20 13:32:31,504] ERROR (com.mirth.connect.connectors.ws.WebServiceReceive r:101): Custom web service class initialization failed
java.lang.ClassNotFoundException: com.foundationmedicine.mirth.AcceptXMLMessage
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.mirth.connect.connectors.ws.WebServiceReceiver .onStart(WebServiceReceiver.java:83)
at com.mirth.connect.donkey.server.channel.SourceConn ector.start(SourceConnector.java:88)
at com.mirth.connect.donkey.server.channel.Channel$St artTask.call(Channel.java:1858)
at com.mirth.connect.donkey.server.channel.Channel$St artTask.call(Channel.java:1780)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
Reply With Quote
  #10  
Old 11-20-2013, 01:00 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Can you post the JAR you're using?
__________________
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
Reply

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 03:04 PM.


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