We now have to
Excerpt |
---|
configure the http-handler-su |
.
In order to make the build output a little bit more comprehensible, we first change the project name in the generated pom.xml file.
Code Block |
---|
|
<project>
...
<name>Http Uploader :: HTTP Handler SU</name>
...
</project>
|
In this case, we already have two set dependencies called servicemix-core
and servicemix-bean
.
We are going to add some more dependencies now:
- log4j - for logging to show another logging possibility
- commons-io - for easy file handling
The
No Format |
---|
${servicemix-version} |
is a variable defined at the end of the pom.xml file. If you followed the advice to move this variable to your root pom file, you can just delete it here, otherwise let it as it is.
Modify your dependencies section now to look like the following:
Code Block |
---|
|
<dependencies>
<dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-bean</artifactId>
<version>${servicemix-version}</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-core</artifactId>
<version>${servicemix-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.8</version>
</dependency>
</dependencies>
|
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-handler-su module. The sample shown below defines two namespaces: the bean
prefix refers to namespace to address the standard bean functionality, while the ex
prefix will be used for the namespace in which all our services will be defined.
Code Block |
---|
|
<beans xmlns:bean="http://servicemix.apache.org/bean/1.0"
xmlns:ex="http://www.servicemix.org/example">
...
</beans>
|
With the XML snippet shown below, we create a bean endpoint by using appropriate XML element and specifying additional configuration like the service name, endpoint name and bean reference.
Code Block |
---|
|
<bean:endpoint service="ex:httphandler" endpoint="handlerEndpoint" bean="#extractorBean"/>
|
The bean reference is pointing to a bean named extractorBean defined later in the xbean.xml file.
Now it's time to define the extractor bean. The id is what you specified in the bean attribute. The class is the full class name of the bean class. This class has to implement the interface MessageExchangeListener in order to receive messages.
Code Block |
---|
|
<bean id="extractorBean" class="org.apache.servicemix.jbi.HandlerBean" />
|
Code Block |
---|
| xml |
---|
| xml |
---|
title | xbean.xml |
---|
borderStyle | solid |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns:bean="http://servicemix.apache.org/bean/1.0"
xmlns:ex="http://www.servicemix.org/example">
<bean:endpoint service="ex:httphandler" endpoint="handlerEndpoint" bean="#extractorBean"/>
<bean id="extractorBean" class="org.apache.servicemix.jbi.HandlerBean" />
</beans>
|
Now, all we have to do is to write the bean class and the SU is done.
- 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
- servicemix-bean contains more information about the servicemix-bean JBI component and an overview of the various configuration options.