Overview of the ServiceMix 2.x Http Binding Example
The following procedure describes how to run the Http Binding example and provides details regarding what it does. For information on the business use case, please refer to: Use Case for Http Binding.
The Http Binding example illustrates:
- use of declarative programming
- how to perform Http binding in ServiceMix
The source code for the Http Binding example is located in the ServiceMix installation directory under the examples\http-binding
directory in the servicemix.xml
file. It is recommended that you refer to the source code while reading this document.
This example shows how to use the HTTP bindings to handle a simple http post. One component acts as the http server that listens to on http://localhost:8912 while another invokes another service implemented as a URLEndpoint. A simple HTTP client is provided so that a simple post can be set to the server.
Running the Http Binding Example
- From a command shell, go to the JMS Binding example directory:
where
cd [servicemix_install_dir]\examples\http-binding
servicemix_install_dir
is the directory in which ServiceMix was installed. - Then type:
[servicemix_install_dir]\bin\servicemix servicemix.xml
- To start sending and receiving of messages from the Http server, send an initial message. To do this, compile and run a simple Http client. The client is built and run from source code using Ant. Execute Ant from the JMS Binding directory:
servicemix_install_dir\examples\http-binding
. To run the Http client type:
ant
Ant will compile and run the simple Http client, HttpClient, which performs a simple post on the Http Server into the ServiceMix container before returning the results to the console.
Stopping the Http Binding Example
To terminate the Http Binding example, type "CTRL-C" in the command shell in which it is running and answer "y" to the "Terminate batch job (y/n)?" question.
How it Works
The diagram below illustrates the flow of messages through the Http Binding components:
Messages flow through the components as follows:
- HttpClient, a java standalone program connects to http://localhost:8912
through URLConnection class. It then sends the file "request.xml" to this port.
- httpReceiver, an http server, being a listenser on http://localhost:8912
receives the message.
- It then sends the message to stockQuote as specified in its destinationService property, via NMR.
- stockQuote sends in into another service, soapEndpoint for processing.
- soapEndpoint sends the response to stockQuote.
- stockQuote send the response to httpReceiver via NMR.
- httpReceiver sends the response to http://localhost:8912
.
- HttpClient reads the response.
- The response is printed on the console.
Typical output looks like the following:
Loading ServiceMix from file: C:\exist\servicemix\servicemix-2.0.2\examples\http -binding\servicemix.xml 17:34:34.768 EVENT Starting Jetty/4.2.20RC0 17:34:34.848 EVENT Started ServletHttpContext[/] 17:34:34.858 EVENT Started SocketListener on 127.0.0.1:8912 17:34:34.858 EVENT Started org.mortbay.jetty.Server@1f06dc3
Details
The following table provides more details about the function of each component and bean in the servicemix.xml file.
Component or Bean ID |
Description |
---|---|
jbi |
jbi is the "id" of the JBI container and provides the basic infrastructure services for the following components: |
httpReceiver |
his component is an http server that is set to listen at http://localhost/8912![]() . It forwards the message it receives from this url to stockQuote as specified in its property destinationService. |
stockQuote |
This is a SaajBinding component that invokes an endpoint service called soapEndpoint. It is implemented by the SaajBinding class which converts an inbound JBI message into a SAAJ (Soap With Attachments for Java) request-response and outputs the response back into httpReceiver. This provides a message centric way of invoking SOAP services inside providers such as Apache Axis |
soapEndpoint |
A URLEndpoint object contains a URL, which is used to make connections to the remote party. A standalone client can pass a URLEndpoint object to the SOAPConnection method call to send a message. |
Related Documentation
For more information on the following topics please see: