This example shows how you can write a plugin that reads and manipulates XML messages. You can use this as a template to write realize your own XML processing.
The example installs a plugin called BasicXmlInterceptor which adds a date-element with the current time inside a bar-element. In the same way you can:
- Read and process SOAP message headers
- Add XML-elements as SOAP headers
- Read and manipulate XML message bodies
To run the example execute the following steps:
- Goto the
examples/xml/basic-xml-interceptordirectory - Run below command
mvn package
- Execute membrane.cmd or membrane.sh
- Open a second terminal
- Run below command
curl -d @example.xml http://localhost:2000 -H "Content-Type: application/xml"
- You can see on the console, the date tag was added with current date information
Using maven, we create a jar file and copy the compiled jar file into the libs directory of membrane to make the new interceptor available to the router.
So when we start the membrane, it is able to find and load our custom interceptor.
In the proxies.xml file, we define a name for our interceptor and write its fully qualified name, so we can use our interceptor on serviceProxy. You can see it in the line below.
<spring:bean id="basicXmlInterceptor" class="com.predic8.myInterceptor.BasicXmlInterceptor" />
Again in the proxies.xml file inside ` tag you can see that we added our basic xml interceptor using the beanname we defined above.
<api name="echo" port="2000">
<interceptor refid="basicXmlInterceptor"/>
Our interceptor checks if the content of the request is xml and creates a date element which contains current time information and adds it into the bar element using Java DOM API.