Page tree
Skip to end of metadata
Go to start of metadata

AsdeqServer supports integration with the  Mule Enterprise Service Bus.

This consists of an OData Service based on the Apache Olingo library (https://olingo.apache.org/) that allows Mule to accept an OData payload and transform it for consumption by external systems.

 

OData

AsdeqServer 5.0+ supports integration with OData data sources.

OData (Open Data Protocol) is an OASIS standard that defines a set of best practices for building and consuming RESTful APIs.

See http://www.odata.org/ for more information.

 

This guide provides a step-by-step guide on how to setup a Mule Project to integrate with AsdeqServer in Anypoint Studio.

Software requirements for this guide

Step-by-step guide

1. Download the Connector

Download the AsdeqServer odataconnector files:

  1. odataconnector-sample-flow.xml
  2. odataconnector-1.0.0-RELEASE.jar
  3. pom.xml

2. Create a new Anypoint Studio Project

  • Place these files in a folder and open Anypoint Studio. 
  • Go to File --> Import --> Maven-based Mule Project from pom.xml


 

 

  • Specify the settings for the Mule Project and browse to the pom.xml file in the AsdeqServer odataconnector distribution.
  • Click "Finish" when ready.

 

 

  • A new Maven based project will be created. Anypoint Studio will download the required 3rd party resources from the Internet and setup the project structure.

 

3. Create an OData Model


  • Take the odataconnector-sample-flow.xml and move it to the src/main/app (Flows) folder.
  • Create a POJO (Plain Old Java Object) to represent your data to be passed from the OData Service. (See example code below). This model should correspond to the entity from the back end system you are integrating with.

  • Note the Olingo annotations on the class and properties, these specify the data to be exposed by the Service.

 

 

Example OData Java Model
package com.asdeq.otr.model;
import org.apache.olingo.odata2.api.annotation.edm.*;
@EdmEntityType
@EdmEntitySet
public class Car 
{
  @EdmKey
  @EdmProperty
  private String id;
  @EdmProperty
  private String model;
  @EdmProperty
  private Double price;
  @EdmProperty
  private Integer productionYear;
  
  /** optional getter and setter */
  public Car()
  {
	  
  }
  public String getId()
{
	return id;
}
public void setId(String id)
{
	this.id = id;
}
public String getModel()
{
	return model;
}
public void setModel(String model)
{
	this.model = model;
}
public Double getPrice()
{
	return price;
}
public void setPrice(Double price)
{
	this.price = price;
}
public Integer getProductionYear()
{
	return productionYear;
}
public void setProductionYear(Integer productionYear)
{
	this.productionYear = productionYear;
}
public Car(String id, String model, Double price, Integer productionYear)
  {
	  this.id =id;
	  this.model = model;
	  this.price =price;
	  this.productionYear = productionYear;
  }
}

 

4. Setup the OData Service

  • Open the odataconnector-sample-flow.xml file. View the Configuration XML and modify the http listener config as required to set the port number and authentication mechanism.
  • Modify the modelPackage property to point to the package where you have create you POJO model. This will be scanned automatically by Mule.
  • Note that the IDE may claim the binding configuration is invalid, this is a bug in the Mule Schema definition and can be ignored, it does not effect running of the Mule Flow.


 

 

 

  • The Mule readData and writeData endpoint are used to request and write data from the OData service into Mule. The messages sent and received will contain POJO's matching the data model you defined.
  • Start the Mule Server and the OData Service for this example service will be available at a url similar to the following: http://hostname:8004/odata.svc/ (note that using localhost as the hostname may not work properly with this example)
  • The following XML fragment shows a simple flow that reads data from a JSON text file on disk and returns it to the OData service via the readData VM, see the sample flow for further details:

 

	<flow name="readData">
		<vm:inbound-endpoint exchange-pattern="request-response"
			path="readData" doc:name="VM" />
		<message-properties-transformer
			doc:name="Set Parameters" scope="invocation">
			<add-message-property key="parameters" value="#[payload[1]]" />
			<add-message-property key="entitySetName" value="#[payload[0]]" />
		</message-properties-transformer>
		<flow-ref name="loadDataFromFile" doc:name="Load Data from File" />
		<collection-splitter doc:name="Collection Splitter" />
		<expression-filter
			expression="#[(flowVars['parameters']==null) || (flowVars.parameters.Id==payload.Id)]"
			doc:name="Expression" />
	</flow>
	<sub-flow name="loadDataFromFile">
		<scripting:component doc:name="Read Cars">
			<scripting:script engine="Groovy"><![CDATA[return new File("/tmp/cars.json")]]></scripting:script>
		</scripting:component>
		<file:file-to-string-transformer
			doc:name="File to String" />
		<json:json-to-object-transformer
			returnClass="com.asdeq.otr.model.Car[]" doc:name="JSON to Object" />
	</sub-flow>

 

  • The following is the cars.JSON sample file that readData is return as an array of Car to the OData service.

 

Cars.JSON
[
{"id": "Outback","model": "Subaru","productionYear": 2013,"price": 39990},
{"id": "Corolla","model": "Toyota","productionYear": 2015,"price": 21990},
{"id": "Magna","model": "Mitsubishi","productionYear": 2011,"price": 7000}
]

 

  • Writing to the OData service is effectively the reverse of the above using the writeData VM. e.g. See below - note this implementation is incomplete.

 

	<flow name="writeData">
		<vm:inbound-endpoint exchange-pattern="request-response"
			path="writeData" doc:name="VM" />
		<message-properties-transformer
			doc:name="Set Parameters" scope="invocation">
			<add-message-property key="entitySetName" value="#[payload[0]]" />
			<add-message-property key="data" value="#[payload[1]]" />
		</message-properties-transformer>
		<set-payload value="#[payload[1]]" doc:name="Set Payload" />
		<flow-ref name="loadDataFromFile" doc:name="Load Data from File" />
		<collection-splitter doc:name="Collection Splitter" />
		<expression-filter expression="#[flowVars.data.Id!=payload.Id)]"
			doc:name="Expression" />
		<combine-collections-transformer
			doc:name="Combine Collections" />
		<set-payload value="#[{payload, flowVars.data }]"
			doc:name="Set Payload" />
		<combine-collections-transformer
			doc:name="Combine Collections" />
		<json:object-to-json-transformer
			doc:name="Object to JSON" />

	</flow>

Note

Basic content filtering is handled internally by the Olingo engine, the filter can be passed into the Flow for more complicated filtering / querying at the Mule ESB level.

 

Connecting AsdeqServer to Mule

Once you have a basic OData Service running in Mule you can connect AsdeqServer. This is done by creating an OData Source Location as follows:

  • Log into AsdeqServer as an Administrator.
  • Go to the Source Locations screen.
  • Create a new Source Location and select OData:
  • Configure the Source Location:
    Depending on how you have setup security in Mule your configuration screen may look like the following.
    The default endpoint for the OData Service in Mule: /odata.svc/
  • Select the Entity / Folder in the Location browser where submissions will be saved.
  • Save the Source Location.
  • Go to the Forms configuration page and setup your Form Library.
  • To use the OData Source Location go to the Submissions tab and specify the OData Entity Folder as the submission location.
  • This will now read and write Drafts / Submissions to the OData Service for the Form Library depending on the Form Library configuration.

 

 

There is no content with the specified labels