...
- 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
No Format |
---|
${servicemix-version} |
is a variable defined at the end of the pom.xml file. We keep using it for servicemix-core.
Modify your dependencies section now to look like the following:
...
Code Block | ||||
---|---|---|---|---|
| ||||
<http:consumer service="ex:httplistener" endpoint="listenerEndpoint" locationURI="http://localhost:8192/upload/" defaultMep="http://www.w3.org/2004/08/wsdl/in-out" targetService="ex:httphandler" marshaler="#marshaler" /> |
Defining a file poller endpoint
We are going to read XML files from a specific directory (specified by the file
attribute, so change this into an existing directory on your own system). The XML snippet below is used to configure a poller, which will check for new files every few seconds. The files will be sent to the file sender endpoint, which is specified by the targetService
and targetEndpoint
attributes.
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.
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="marshaler" class="org.apache.servicemix.jbi.HTTPMarshaler" />
|
The finished xbean.xml
Code Block | ||||
---|---|---|---|---|
| ||||
<?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:http="http://servicemix.apache.org/http/1.0"
xmlns:ex="http://www.servicemix.org/example">
<http:consumer service="ex:httplistener"
| ||||
Code Block | ||||
xml | xml | <file:poller service="tut:file" endpoint="pollerlistenerEndpoint" file locationURI="filehttp://homelocalhost:8192/gertupload/poller" " defaultMep="http://www.w3.org/2004/08/wsdl/in-out" targetService="tutex:filehttphandler" marshaler="#marshaler" /> <bean id="marshaler" targetEndpointclass="sender"org.apache.servicemix.jbi.HTTPMarshaler" /> </beans> |
Now, all we have to do is package the SU in a service assembly and deploy itto 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-filehttp contains more information about the servicemix-file http JBI component and an overview of the various configuration options.
...