Creating a custom Web Service in Mirth Connect 3.0.1 - rbeckman-nextgen/test-mc GitHub Wiki

  1. Mirth Connect
  2. Home
  3. Examples and Tutorials

Mirth Connect : Creating a custom Web Service in Mirth Connect 3.0.1

Created by Adrian Galvan, last modified by Christopher Schultz on Jul 15, 2016

Create a new Java project and create a class that extends com.mirth.connect.connectors.ws.AcceptMessage

Example

package com.custom.webservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.mirth.connect.connectors.ws.AcceptMessage;
import com.mirth.connect.connectors.ws.WebServiceReceiver;

@WebService
public class CustomAcceptMessage extends AcceptMessage {
 
    public CustomAcceptMessage(WebServiceReceiver webServiceReceiver) {
        super(webServiceReceiver);
    }
 
    @WebMethod(action = "sample_operation")
    public String operation(@WebParam(name = "param_name") String param) {
        // implement the web service operation here
        return param;
    }
 
    @WebMethod(action = "add")
    public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
        int k = i + j;
        return k;
    }
 
    // multiple response example
    @WebMethod(action = "calculate")
    public void calculate(@WebParam(name = "sum", mode = WebParam.Mode.OUT) Holder<Integer> sum, @WebParam(name = "multiply", mode = WebParam.Mode.OUT) Holder<Integer> multiply) {
        sum.value = 4+5;
        multiply.value = 4*5;
    }

    @WebMethod(action="swap")
    public Values swap(@XmlElement(required=true)
                       @WebParam(name=valus) Values values)
    {
        values = new Values(values.getLeft(), values.getRight());

        // Tell the channel that we actually did something
        super.webServiceReceiver.processData(String.valueOf(values));

        return values;
    }

    // This class may have to be in a separate file to work properly
    // (i.e. not an inner class). It's only here to make the example
    // simpler.
    public static class Values {
        private int left;
        private int right;
        public Values(int left, int right) {
            this.left = left;
            this.right = right;
        }
        // The @XmlElement annotation lets the WS-generator know that
        // these represent properties that should be serialized to XML
        @XmlElement
        public int getLeft() { return left; }
        @XmlElement
        public int getRight() { return right; }
    }
 }

I suggest that you include the following classes in your project:

Export this project as a jar file and add it to your custom-lib folder in your mirthconnect directory

Restart Mirth Connect

You can now create your own custom web service listener

 

Attachments:

Screen Shot 2014-02-11 at 1.12.14 PM.png (image/png)
JavaLibrary1.jar (application/octet-stream)
Example.JPG (image/jpeg)

Comments:

Has anyone some more explanation how to build a custom web service in Mirth?

Posted by mdehoog at Mar 10, 2015 08:09

Note that to actually process a message through a channel, you need to call processData on the WebServiceReceiver object.

Posted by narupley at Apr 15, 2015 07:03
Hello there is a way to give back to the client two values , such as < id > 33 < / id > < name> test < / name> ?
Posted by firestar at Jul 31, 2015 14:10

I tried but it does not work.

I create a new Java project and create a class CustomAcceptMessage, i configure the build path with 

C:\Program Files (x86)\Mirth Connect\extensions\ws\ws-server.jar

but when i deploy the mirth channel 

"

Custom web service class initialization failed
java.lang.ClassNotFoundException: com.custom.webservice.CustomAcceptMessage
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:114)
at com.mirth.connect.donkey.server.channel.SourceConnector.start(SourceConnector.java:103)
at com.mirth.connect.donkey.server.channel.Channel.start(Channel.java:671)
at com.mirth.connect.server.controllers.DonkeyEngineController$DeployTask.doDeploy(DonkeyEngineController.java:1274)
at com.mirth.connect.server.controllers.DonkeyEngineController$DeployTask.execute(DonkeyEngineController.java:1171)
at com.mirth.connect.server.channel.ChannelTask.call(ChannelTask.java:59)
at com.mirth.connect.server.channel.ChannelTask.call(ChannelTask.java:16)
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)

Custom web service class initialization failed
java.lang.ClassNotFoundException: com.custom.webservice.CustomAcceptMessage

"

Posted by rlopresti at Feb 03, 2016 05:14

Note that to actually process a message through a channel, you need to call processData on the WebServiceReceiver object.

Sorry, but what does it mean?

i'm beginner in mirth developement.

Thanks

 

Posted by rlopresti at Feb 04, 2016 03:07

Hi, this example is not working anymore in 3.5 version. 

Can anybody tell me how to do it in 3.5 version? Where to find the .jar library?

it's only to change the method name of web service (not accept message)

thanks in advance

Posted by fospi at Oct 25, 2017 04:19

Document generated by Confluence on Nov 11, 2019 08:40

Atlassian

⚠️ **GitHub.com Fallback** ⚠️