Child pages
  • Create a SOAP based web services connector
Skip to end of metadata
Go to start of metadata

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

  1. Download WSDL2JAVA.
  2. Install the Groovy Eclipse plugin or use GroovyConsole
  3. 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.

  1. 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.
  2. Run WSDL2JAVA to create a client JAR: wsdl2java -client -clientjar client.jar Calc.wsdl
  3. This will result in a set of client classes that can be used to invoke the web service.
Optional: You may want to use SoapUI to create a mock service locally for testing purposes if you do not have access to a web service. Instructions can be found at the bottom of this article.

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:

  1. 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

  2. The bundler will output a new connector with the following structure:

An easy way to work with this is to create a new Groovy project in Eclipse and invoke the scripts from there. Template scripts should have been created as shown below:


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.

The Groovy script files can be found under: src/main/resources/script/<connector name> as shown above.
  1. 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.
  2. 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.

  1. Run Maven:  mvn package
  2. Copy the resulting connector jar to openidm/connectors
  3. Install any additional required libs in opendim/lib.
  4. 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.

To do this you can use SOAP UI:

  1. Create a new SOAP project:
  2. Create a new SOAP mock service:
     
  3. Configure the MockService port and endpoint:
  4. Right click and create a new mock operation
  5. Set a dummy response value:
  6. Start the service.


  • No labels