You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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.

<project>
  ...
   <name>Http Uploader :: HTTP Consumer SU</name>
  ...
</project>

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

Modify your dependencies section to look like the following:

<dependencies>
    <dependency>
      <groupId>org.apache.servicemix</groupId>
      <artifactId>servicemix-core</artifactId>
      <version>${servicemix-version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.servicemix</groupId>
      <artifactId>servicemix-http</artifactId>
      <version>${servicemix-version}</version>
    </dependency>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.2</version>
    </dependency>
</dependencies>

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.

<beans xmlns:http="http://servicemix.apache.org/http/1.0"
       xmlns:ex="http://www.servicemix.org/example"> 
   ...
</beans>

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.

<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.

<file:poller service="tut:file" 
             endpoint="poller"
             file="file:/home/gert/poller" 
             targetService="tut:file"
             targetEndpoint="sender"/>

Now, all we have to do is package the SU in a service assembly and deploy it.

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-file contains more information about the servicemix-file JBI component and an overview of the various configuration options.



  • No labels