Configuring the http consumer SU
We now have to configure the http-consumer-su
Configuring pom.xml
Changing the project name
In order to make the build output a little bit more comprehensible, we first change the project name in the generated pom.xml file.
Adding dependencies
In this case, we already have one set dependency called servicemix-http
. We are going to add some more dependencies now:
- servicemix-core - for access to marshaler classes used later
- commons-fileupload - for parsing multipart-formdata as provided by our upload form later on
- commons-io - for easy file handling
The
is a variable defined at the end of the pom.xml file. It can be helpful to move this variable into your root pom.xml. If defined there all subprojects will have this variable automatically. If you want to move to another servicemix version later on it is just a matter of changing this variable in the root pom instead of touching each single pom in your project.
This will ease the maintainance of the project a lot. The same can be done for repositories as well. If you do so, you should remove these things from the pom files in the subprojects.
Modify your dependencies section now to look like the following:
Configuring xbean.xml
Next, we will have to configure our new SU to really provide some services. We do this by modifying the file named xbean.xml
in the src/main/resources
directory of our http-consumer-su module. The sample shown below defines two namespaces: the http
prefix refers to namespace to address the standard http functionality, while the ex
prefix will be used for the namespace in which all our services will be defined.
Defining the http consumer endpoint
To accept data under a specific URI we need to define a http consumer endpoint. With the XML snippet shown below, we create such a consumer endpoint by using appropriate XML element and specifying additional configuration like the service name, endpoint name , etc.
The locationURI attribute defines where to accept incoming data. The targetService attribute specifies the service to deliver the data to. The last but very important attribute is the marshaler. This attribute does still not show up in the documentation directly. You can use this marshaler inside the http:consumer element. This element is existing in ServiceMix version 3.2 and above only. Via this marshaler you can define your own handler for incoming and outgoing data. We will discuss this later on more detailed. The value entered here as marshaler is a reference to a bean defined later in the xbean.xml file, therefor it starts with the # char followed by the identifier/name of the bean.
Defining the marshaler bean
Now it's time to define the marshaler bean. The id is what you specified in the marshaler attribute. The class is the full class name of the marshaler class. This class has to implement the interface HttpConsumerMarshaler directly or indirectly. We will discuss this later.
The finished xbean.xml
Now, all we have to do is to write the marshaler class and the SU is done.
Things to remember
- You specify the target component for a SU as a normal dependency in Maven's pom.xml file
- In ServiceMix, most service units will be configured by a file named
xbean.xml
Further reading
- servicemix-http contains more information about the servicemix-http JBI component and an overview of the various configuration options.
Proceed to the next step