Creating a custom Web Service in Mirth Connect 3.0.1 - rbeckman-nextgen/test-mc GitHub Wiki
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:
- com.mirth.connect.connectors.ws.AcceptMessage.class
- com.mirth.connect.connectors.ws.DefaultAcceptMessage.class
- com.mirth.connect.connectors.ws.LoggingSOAPHandler.class
- com.mirth.connect.connectors.ws.WebServiceConnectorService.class
- com.mirth.connect.connectors.ws.WebServiceDispatcher.class
- com.mirth.connect.connectors.ws.WebServiceReceiver.class
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
Screen
Shot 2014-02-11 at 1.12.14 PM.png
(image/png)
JavaLibrary1.jar
(application/octet-stream)
Example.JPG (image/jpeg)
Has anyone some more explanation how to build a custom web service in Mirth? ![]() |
Note that to actually process a message through a channel, you need to call processData on the WebServiceReceiver object. ![]() |
![]() |
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 Custom web service class initialization failed " ![]() |
Thanks
![]() |
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 ![]() |
Document generated by Confluence on Nov 11, 2019 08:40