Our blog

20 Apr 2015
by cvringer

Connect to Twinfield using Java

Twinfield has an extensive webservice API available. It has documented how to connect for popular technologies like C, .net and php. Unfortunately there is no Java tutorial available, so i wrote it down here. First, i’ll explain how to setup a Java project in Intellij using Spring-ws and maven. Of course you can use your own IDE for this. In a next entry i will explain how to create and abandon a session, and how to execute requests. Lets start!


First of all: If you want to download the full example and get quick and dirty in minutes, you can do that HERE. No need to further explore this page. Glad i could help!




Get to know a little more of the working code below, and build the bastard for yourself.
Many developers have precedeeded you. I’m sure you can build it too!


Step one: Create a maven project: In your IDE you can create a new maven project. In Intellij you will use file/new Project/Spring application. This will result in a maven-structured project, which contains a pom.xml file with some spring dependencies in it. You can also use command-line maven to create a new project. Details are HERE


Next, fill your pom with dependencies. An full pom example is HERE


Step two: Import the wsdl for session into your project and save it in scr/main/resources/wsdl. The maven-jaxb2-plugin plugin will take care of generating objects from the wsdl. If you run mvn clean install from your project root directory, Twinfield objects will be generated in your target directory.


For the coding part:
You will need a Spring configuration. I use an AnnotationBasedConfiguration class for this.

Next write the WebServiceClient implementation. A Unit test example is HERE (thanks #Kees). This example uses a
SessionDetails wrapper object to store the requested sessionId and actionUrl.


Note that the webserviceclient sets a SOAP Action variable. This variable is required by Twinfield and should define the action (Logon or Abandon). Now you have Twinfield connection, you can query or send XML to Twinfield.


Good luck coding!

© Keienberg Consultants