Overview
Very simple guide to creating a functioning OpenIDM scripted Groovy connector that invokes a SOAP web service.
For this example we are going to use Apache CXF to create a web service stub that will be invoked by a new instance of the scripted Groovy connector.
Prerequisites
- Download WSDL2JAVA.
- Install the Groovy Eclipse plugin or use GroovyConsole
- If you haven't already, install Maven.
1. Creating the web service clients
First, we create the Java client classes that will be used to invoke the service.
- Create or save an existing web service definition language (WSDL) file. For the purposes of this example we have used this simple Calculator example provided by Microsoft.
- Run WSDL2JAVA to create a client JAR: wsdl2java -client -clientjar client.jar Calc.wsdl
- This will result in a set of client classes that can be used to invoke the web service.
2. Creating a new scripted Groovy connector
Follow the instructions here to create a new instance of the scripted Groovy connector. You can use the following scriptedsoap.json file as example file for use with the connector bundler. The commands for creating the connector are summarised below:
- Create a new connector:
cd openidm
mkdir scriptedsoapconnector
cp scriptedsoap.json scriptedsoapconnector
cd scriptedsoapconnector
java -jar ../tools/custom-scripted-connector-bundler-4.0.0.jar --config scriptedsoap.json - The bundler will output a new connector with the following structure:
3. Invoking the web service in Groovy scripts
Before trying to integrate with OpenIDM, it is advisable to use the Eclipse Groovy plugin to get service invocation working against your test service.
- Set up dependencies. Ensure the Apache CXF libraries are available to the project as well as the client JAR we created earlier. Also ensure these are imported into the Groovy scripts. If you are running in Eclipse set up the project as you normally would, if you are running in GroovyConsole use Script -> Add Jar(s) to Classpath.
- Each of the Groovy scripts will need to be configured to invoke the service as required. An example follows:
import org.example.CalculatorService
...
...
...
def url = new URL("http://localhost:8088/mockDefaultBinding_ICalculator?WSDL")
def service = new CalculatorService(url)
def client = service.getICalculator()
def result = client.add(3,5)
Use this code as a template to invoke the service from your Groovy scripts. Make sure all the Groovy scripts are populated as required. Again, we recommend testing outside of OpenIDM for now until it is all working.
Note: You will ideally want to treat the URL and any username and password as parameters and configure them accordingly in OpenIDM.
Note: An example of returning values through SearchScript.groovy can be found below using the handler:
for(user in result.getUsers()) {
println user.userid;handler {
uid user.userid
id user.userid
attribute 'group',user.group
attribute 'username', user.userName
attribute 'fullname', user.fullName
}}
The above will return records for each use to OpenIDM with the attribute configured in the handler.
4. Installing the connector in OpenIDM
Once the Groovy scripts are working as expected you need to build the connector and copy it to OpenIDM.
- Run Maven: mvn package
- Copy the resulting connector jar to openidm/connectors
- Install any additional required libs in opendim/lib.
- Create a connector as you usually would in OpenIDM. Your new SOAP connector should be available to select and configure.
Optional - creating a mock service
This can be helpful to test locally with if you do not have an actual service available.
- Create a new SOAP project:
- Create a new SOAP mock service:
- Configure the MockService port and endpoint:
- Right click and create a new mock operation
- Set a dummy response value:
- Start the service.