Skip to content
simcha edited this page Sep 13, 2010 · 4 revisions

The Mule Mappum module component provides support for processing mapping defined using ’’’mappum’’’ DSL.

Availability
Note that this component was developed with Mule releases = 2.2.1.

What is Mappum

Mappum is the tree to tree (object, bean etc.) mapping DSL. Mappum homepage can be found on mappum wiki.

Installation

Installing the mule-module-mappum component can be done in the following way:

  1. place mule-module-mappum-0.2.0.jar from downloads in the lib/usr subfolder of mule installation directory.
  2. place the following JAR files in the same lib/usr folder:
    1. mappum-jruby-complete-1.3.1.jar form mappum downloads
    2. mappum-core-0.2.0.jar form mappum downloads
    3. jruby-engine-20080611.jar from maven repo

Configuration

Prepare configuration file for mule, which uses mule-module-mappum component. Example configuration shows different ways of using mule-module-mappum.

This configuration uses also properties file, which defines some configuration parameters, explained below.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:spring="http://www.springframework.org/schema/beans"
	xmlns:script="http://www.mulesource.org/schema/mule/scripting/2.2"
	xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
	xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
	xmlns:mappum="http://www.infovidematrix.pl/schema/mule/mappum/2.2"                                                             <!-- NAMESPACE FOR MAPPUM MULE MODULE -->
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:http="http://www.mulesource.org/schema/mule/http/2.2"
	xsi:schemaLocation="
       http://www.mulesource.org/schema/mule/http/2.2 http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd
       http://www.infovidematrix.pl/schema/mule/mappum/2.2 http://github.com/simcha/mappum-mule/raw/master/mule-module-mappum/src/main/resources/META-INF/mule-mappum.xsd       <!-- LOCATION OF XML SCHEMA OF MAPPUM MULE MODULE -->
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
       http://www.mulesource.org/schema/mule/scripting/2.2 http://www.mulesource.org/schema/mule/scripting/2.2/mule-scripting.xsd
       http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
       http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">

	<description>
		This example demonstrates invoking a mappum transformation
		as the service component.
	</description>

	<!--
		Adds the default configuration for the 'mapFolder' and 'schemFolder'
		parameters below. Users can override these values by passing them as
		VM parameters i.e. -DmapFolder=/tmp/mappum/maps.
	-->
	<context:property-placeholder location="classpath:mappum-config.properties" />

	<!--
		The stdio connector is used to send and receive information via
		System.in and System.out. Note this connector is only really useful
		for testing purposes. promptMessage - is what is written to the
		console messageDelayTime - is the time in milliseconds before the user
		is prompted again. These properties are set as bean properties on the
		connector.
	-->
	<configuration defaultSynchronousEndpoints="true" />

	<stdio:connector name="SystemStreamConnector"
		promptMessage="Paste XML to be transformed" messageDelayTime="1000" />

	<model name="main">

		<service name="Mappum">

			<inbound>
				<stdio:inbound-endpoint system="IN" />

				<http:inbound-endpoint host="localhost" port="8888"                                                   <!-- HTTP ENDPOINT WITHOUT HARD CODED MAP NAME -->
					path="services/Mappum" synchronous="true" keep-alive="true">
				</http:inbound-endpoint>

				<http:inbound-endpoint host="localhost" port="8899"                                                   <!-- HTTP ENDPOINT WITH HARD CODED MAP NAME -->
					path="services/Mappum/Address" synchronous="true" keep-alive="true">
					<message-properties-transformer>
						<add-message-property key="mapName" value="address" />
					</message-properties-transformer>
				</http:inbound-endpoint>

				<vm:inbound-endpoint path="mappum" />
			</inbound>

			<mappum:component mapFolder="${mapFolder}"                                                                    <!-- INVOCATION OF MAPPUM MULE MODULE -->
				schemaFolder="${schemaFolder}">
			</mappum:component>

			<outbound>
				<chaining-router>
					<stdio:outbound-endpoint system="OUT" />
				</chaining-router>
			</outbound>

		</service>
	</model>
</mule>

The above configuration file contains invocation of the mule-module-mappum component by usage of <mappum:component> XML tag. This XML element can have 3 attributes:

Name Type Description Mandatory? Default value
mapFolder String folder containing maps definied in Mappum DSL (maps can be packed in service-unit archive file) no ’’map’’
(it means subfolder with the name “map” of the folder in which mule is started)
schemaFolder String folder containing XML schmemas for object types definitions, for which maps are defined no ’’schema’’
(it means subfolder with the name “schema” of the folder in which mule is started)
generatedClassesFolder String folder which will contain generated Ruby files for each object type defined in XML Schema files no ’’generated_classes’’
(it means folder with the name “generated_classes” in deployment folder – .mule)

The first HTTP inbound-endpoint defined in the above configuration file makes it possible to send in HTTP request any XML to be transferred by the ’’’mappum’’’ library. Map name which will be used is determined either by the root element name in the inbound XML, or by “mapName” HTTP request header set during sending XML to this endpoint.

The second HTTP inbound-endpoint defined in the above configuration file makes it possible to send in HTTP request for the given, hard-coded, map. In this case the name of the root element in the inbound XML will not be checked by the ’’’mappum’’’ library.

JUnit tests in file shows different ways of invoking mule-module-mappum via endpoints defined in the above configuration file.

Clone this wiki locally