camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Tutorial-AXIS-Camel
Date Fri, 22 Jul 2011 09:22:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Tutorial-AXIS-Camel">Tutorial-AXIS-Camel</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h2. Tutorial using Axis 1.4 with Apache Camel <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{info:title=Removed from distribution} <br>This example has been removed from *Camel 2.9* onwards. Apache Axis 1.4 is a very old and unsupported framework. We encourage users to use [CXF] instead of Axis. <br>{info} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{toc} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Tutorial-AXIS-Camel-TutorialusingAxis1.4withApacheCamel"></a>Tutorial using Axis 1.4 with Apache Camel</h2>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Removed from distribution</b><br />This example has been removed from <b>Camel 2.9</b> onwards. Apache Axis 1.4 is a very old and unsupported framework. We encourage users to use <a href="/confluence/display/CAMEL/CXF" title="CXF">CXF</a> instead of Axis.</td></tr></table></div>

<div>
<ul>
    <li><a href='#Tutorial-AXIS-Camel-TutorialusingAxis1.4withApacheCamel'>Tutorial using Axis 1.4 with Apache Camel</a></li>
<ul>
    <li><a href='#Tutorial-AXIS-Camel-Prerequisites'>Prerequisites</a></li>
    <li><a href='#Tutorial-AXIS-Camel-Distribution'>Distribution</a></li>
    <li><a href='#Tutorial-AXIS-Camel-Introduction'>Introduction</a></li>
    <li><a href='#Tutorial-AXIS-Camel-SettinguptheprojecttorunAxis'>Setting up the project to run Axis</a></li>
<ul>
    <li><a href='#Tutorial-AXIS-Camel-Maven2'>Maven 2</a></li>
    <li><a href='#Tutorial-AXIS-Camel-wsdl'>wsdl</a></li>
    <li><a href='#Tutorial-AXIS-Camel-ConfiguringAxis'>Configuring Axis</a></li>
    <li><a href='#Tutorial-AXIS-Camel-RunningtheExample'>Running the Example</a></li>
</ul>
    <li><a href='#Tutorial-AXIS-Camel-IntegratingSpring'>Integrating Spring</a></li>
<ul>
    <li><a href='#Tutorial-AXIS-Camel-UsingSpring'>Using Spring</a></li>
</ul>
    <li><a href='#Tutorial-AXIS-Camel-IntegratingCamel'>Integrating Camel</a></li>
<ul>
    <li><a href='#Tutorial-AXIS-Camel-CamelContext'>CamelContext</a></li>
    <li><a href='#Tutorial-AXIS-Camel-Storeafilebackup'>Store a file backup</a></li>
</ul>
    <li><a href='#Tutorial-AXIS-Camel-Runningtheexample'>Running the example</a></li>
    <li><a href='#Tutorial-AXIS-Camel-UnitTesting'>Unit Testing</a></li>
<ul>
    <li><a href='#Tutorial-AXIS-Camel-SmarterUnitTestingwithSpring'>Smarter Unit Testing with Spring</a></li>
</ul>
    <li><a href='#Tutorial-AXIS-Camel-UnitTestcallingWebService'>Unit Test calling WebService</a></li>
    <li><a href='#Tutorial-AXIS-Camel-Annotations'>Annotations</a></li>
    <li><a href='#Tutorial-AXIS-Camel-TheEnd'>The End</a></li>
    <li><a href='#Tutorial-AXIS-Camel-SeeAlso'>See Also</a></li>
</ul>
</ul></div>

<h3><a name="Tutorial-AXIS-Camel-Prerequisites"></a>Prerequisites</h3>

<p>This tutorial uses Maven 2 to setup the Camel project and for dependencies for artifacts.</p>

<h3><a name="Tutorial-AXIS-Camel-Distribution"></a>Distribution</h3>

<p>This sample is distributed with the Camel 1.5 distribution as <tt>examples/camel-example-axis</tt>.</p>

<h3><a name="Tutorial-AXIS-Camel-Introduction"></a>Introduction</h3>
<p><a href="http://ws.apache.org/axis/" class="external-link" rel="nofollow">Apache Axis</a> is/was widely used as a webservice framework. So in line with some of the other tutorials to demonstrate how Camel is not an invasive framework but is flexible and integrates well with existing solution. </p>

<p>We have an existing solution that exposes a webservice using Axis 1.4 deployed as web applications. This is a common solution. We use contract first so we have Axis generated source code from an existing wsdl file. Then we show how we introduce Spring and Camel to integrate with Axis.</p>

<p>This tutorial uses the following frameworks:</p>
<ul>
	<li>Maven 2.0.9</li>
	<li>Apache Camel 1.5.0</li>
	<li>Apache Axis 1.4</li>
	<li>Spring 2.5.5</li>
</ul>


<h3><a name="Tutorial-AXIS-Camel-SettinguptheprojecttorunAxis"></a>Setting up the project to run Axis</h3>
<p>This first part is about getting the project up to speed with Axis. We are not touching Camel or Spring at this time.</p>

<h4><a name="Tutorial-AXIS-Camel-Maven2"></a>Maven 2</h4>
<p>Axis dependencies is available for maven 2 so we configure our pom.xml as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.axis<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>axis<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>1.4<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>

        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.axis<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>axis-jaxrpc<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>1.4<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>

        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.axis<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>axis-saaj<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>1.4<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>

	<span class="code-tag">&lt;dependency&gt;</span>
	    <span class="code-tag">&lt;groupId&gt;</span>axis<span class="code-tag">&lt;/groupId&gt;</span>
	    <span class="code-tag">&lt;artifactId&gt;</span>axis-wsdl4j<span class="code-tag">&lt;/artifactId&gt;</span>
	    <span class="code-tag">&lt;version&gt;</span>1.5.1<span class="code-tag">&lt;/version&gt;</span>
	<span class="code-tag">&lt;/dependency&gt;</span>

	<span class="code-tag">&lt;dependency&gt;</span>
	    <span class="code-tag">&lt;groupId&gt;</span>commons-discovery<span class="code-tag">&lt;/groupId&gt;</span>
	    <span class="code-tag">&lt;artifactId&gt;</span>commons-discovery<span class="code-tag">&lt;/artifactId&gt;</span>
	    <span class="code-tag">&lt;version&gt;</span>0.4<span class="code-tag">&lt;/version&gt;</span>
	<span class="code-tag">&lt;/dependency&gt;</span> 

        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>log4j<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>log4j<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>1.2.14<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<p>Then we need to configure maven to use Java 1.5 and the Axis maven plugin that generates the source code based on the wsdl file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag"><span class="code-comment">&lt;!-- to compile with 1.5 --&gt;</span></span>
	<span class="code-tag">&lt;plugin&gt;</span>
		<span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.plugins<span class="code-tag">&lt;/groupId&gt;</span>
		<span class="code-tag">&lt;artifactId&gt;</span>maven-compiler-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
		<span class="code-tag">&lt;configuration&gt;</span>
			<span class="code-tag">&lt;source&gt;</span>1.5<span class="code-tag">&lt;/source&gt;</span>
			<span class="code-tag">&lt;target&gt;</span>1.5<span class="code-tag">&lt;/target&gt;</span>
		<span class="code-tag">&lt;/configuration&gt;</span>
	<span class="code-tag">&lt;/plugin&gt;</span>

            <span class="code-tag">&lt;plugin&gt;</span>
               <span class="code-tag">&lt;groupId&gt;</span>org.codehaus.mojo<span class="code-tag">&lt;/groupId&gt;</span>
               <span class="code-tag">&lt;artifactId&gt;</span>axistools-maven-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
               <span class="code-tag">&lt;configuration&gt;</span>
	          <span class="code-tag">&lt;sourceDirectory&gt;</span>src/main/resources/<span class="code-tag">&lt;/sourceDirectory&gt;</span>
                  <span class="code-tag">&lt;packageSpace&gt;</span>com.mycompany.myschema<span class="code-tag">&lt;/packageSpace&gt;</span>
                  <span class="code-tag">&lt;testCases&gt;</span>false<span class="code-tag">&lt;/testCases&gt;</span>
                  <span class="code-tag">&lt;serverSide&gt;</span>true<span class="code-tag">&lt;/serverSide&gt;</span>
                  <span class="code-tag">&lt;subPackageByFileName&gt;</span>false<span class="code-tag">&lt;/subPackageByFileName&gt;</span>
               <span class="code-tag">&lt;/configuration&gt;</span>
               <span class="code-tag">&lt;executions&gt;</span>
                 <span class="code-tag">&lt;execution&gt;</span>
                   <span class="code-tag">&lt;goals&gt;</span>
                     <span class="code-tag">&lt;goal&gt;</span>wsdl2java<span class="code-tag">&lt;/goal&gt;</span>
                   <span class="code-tag">&lt;/goals&gt;</span>
                 <span class="code-tag">&lt;/execution&gt;</span>
               <span class="code-tag">&lt;/executions&gt;</span>
            <span class="code-tag">&lt;/plugin&gt;</span>
</pre>
</div></div>

<h4><a name="Tutorial-AXIS-Camel-wsdl"></a>wsdl</h4>
<p>We use the same .wsdl file as the <a href="/confluence/display/CAMEL/Tutorial-Example-ReportIncident" title="Tutorial-Example-ReportIncident">Tutorial&#45;Example&#45;ReportIncident</a> and copy it to <tt>src/main/webapp/WEB-INF/wsdl</tt></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"ISO-8859-1"</span>?&gt;</span>
&lt;wsdl:definitions <span class="code-keyword">xmlns:soap</span>=<span class="code-quote">"http://schemas.xmlsoap.org/wsdl/soap/"</span>
	<span class="code-keyword">xmlns:tns</span>=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>
	<span class="code-keyword">xmlns:xs</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema"</span>
	<span class="code-keyword">xmlns:http</span>=<span class="code-quote">"http://schemas.xmlsoap.org/wsdl/http/"</span>
	<span class="code-keyword">xmlns:wsdl</span>=<span class="code-quote">"http://schemas.xmlsoap.org/wsdl/"</span>
	targetNamespace=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>&gt;

	<span class="code-tag"><span class="code-comment">&lt;!-- Type definitions for input- and output parameters for webservice --&gt;</span></span>
	<span class="code-tag">&lt;wsdl:types&gt;</span>
	<span class="code-tag">&lt;xs:schema targetNamespace=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>&gt;</span>
			<span class="code-tag">&lt;xs:element name=<span class="code-quote">"inputReportIncident"</span>&gt;</span>
				<span class="code-tag">&lt;xs:complexType&gt;</span>
					<span class="code-tag">&lt;xs:sequence&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"incidentId"</span>/&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"incidentDate"</span>/&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"givenName"</span>/&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"familyName"</span>/&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"summary"</span>/&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"details"</span>/&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"email"</span>/&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span>  name=<span class="code-quote">"phone"</span>/&gt;</span>
					<span class="code-tag">&lt;/xs:sequence&gt;</span>
				<span class="code-tag">&lt;/xs:complexType&gt;</span>
			<span class="code-tag">&lt;/xs:element&gt;</span>
			<span class="code-tag">&lt;xs:element name=<span class="code-quote">"outputReportIncident"</span>&gt;</span>
				<span class="code-tag">&lt;xs:complexType&gt;</span>
					<span class="code-tag">&lt;xs:sequence&gt;</span>
						<span class="code-tag">&lt;xs:element type=<span class="code-quote">"xs:string"</span> name=<span class="code-quote">"code"</span>/&gt;</span>
					<span class="code-tag">&lt;/xs:sequence&gt;</span>
				<span class="code-tag">&lt;/xs:complexType&gt;</span>
			<span class="code-tag">&lt;/xs:element&gt;</span>
		<span class="code-tag">&lt;/xs:schema&gt;</span>
	<span class="code-tag">&lt;/wsdl:types&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Message definitions for input and output --&gt;</span></span>
	<span class="code-tag">&lt;wsdl:message name=<span class="code-quote">"inputReportIncident"</span>&gt;</span>
		<span class="code-tag">&lt;wsdl:part name=<span class="code-quote">"parameters"</span> element=<span class="code-quote">"tns:inputReportIncident"</span>/&gt;</span>
	<span class="code-tag">&lt;/wsdl:message&gt;</span>
	<span class="code-tag">&lt;wsdl:message name=<span class="code-quote">"outputReportIncident"</span>&gt;</span>
		<span class="code-tag">&lt;wsdl:part name=<span class="code-quote">"parameters"</span> element=<span class="code-quote">"tns:outputReportIncident"</span>/&gt;</span>
	<span class="code-tag">&lt;/wsdl:message&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Port (interface) definitions --&gt;</span></span>
	<span class="code-tag">&lt;wsdl:portType name=<span class="code-quote">"ReportIncidentEndpoint"</span>&gt;</span>
		<span class="code-tag">&lt;wsdl:operation name=<span class="code-quote">"ReportIncident"</span>&gt;</span>
			<span class="code-tag">&lt;wsdl:input message=<span class="code-quote">"tns:inputReportIncident"</span>/&gt;</span>
			<span class="code-tag">&lt;wsdl:output message=<span class="code-quote">"tns:outputReportIncident"</span>/&gt;</span>
		<span class="code-tag">&lt;/wsdl:operation&gt;</span>
	<span class="code-tag">&lt;/wsdl:portType&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Port bindings to transports and encoding - HTTP, document literal encoding is used --&gt;</span></span>
	<span class="code-tag">&lt;wsdl:binding name=<span class="code-quote">"ReportIncidentBinding"</span> type=<span class="code-quote">"tns:ReportIncidentEndpoint"</span>&gt;</span>
		<span class="code-tag">&lt;soap:binding transport=<span class="code-quote">"http://schemas.xmlsoap.org/soap/http"</span>/&gt;</span>
		<span class="code-tag">&lt;wsdl:operation name=<span class="code-quote">"ReportIncident"</span>&gt;</span>
			&lt;soap:operation
				soapAction=<span class="code-quote">"http://reportincident.example.camel.apache.org/ReportIncident"</span>
				style=<span class="code-quote">"document"</span>/&gt;
			<span class="code-tag">&lt;wsdl:input&gt;</span>
				<span class="code-tag">&lt;soap:body parts=<span class="code-quote">"parameters"</span> use=<span class="code-quote">"literal"</span>/&gt;</span>
			<span class="code-tag">&lt;/wsdl:input&gt;</span>
			<span class="code-tag">&lt;wsdl:output&gt;</span>
				<span class="code-tag">&lt;soap:body parts=<span class="code-quote">"parameters"</span> use=<span class="code-quote">"literal"</span>/&gt;</span>
			<span class="code-tag">&lt;/wsdl:output&gt;</span>
		<span class="code-tag">&lt;/wsdl:operation&gt;</span>
	<span class="code-tag">&lt;/wsdl:binding&gt;</span>

	<span class="code-tag"><span class="code-comment">&lt;!-- Service definition --&gt;</span></span>
	<span class="code-tag">&lt;wsdl:service name=<span class="code-quote">"ReportIncidentService"</span>&gt;</span>
		<span class="code-tag">&lt;wsdl:port name=<span class="code-quote">"ReportIncidentPort"</span> binding=<span class="code-quote">"tns:ReportIncidentBinding"</span>&gt;</span>
			<span class="code-tag">&lt;soap:address location=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>/&gt;</span>
		<span class="code-tag">&lt;/wsdl:port&gt;</span>
	<span class="code-tag">&lt;/wsdl:service&gt;</span>

<span class="code-tag">&lt;/wsdl:definitions&gt;</span>
</pre>
</div></div>

<h4><a name="Tutorial-AXIS-Camel-ConfiguringAxis"></a>Configuring Axis</h4>
<p>Okay we are now setup for the contract first development and can generate the source file. For now we are still only using standard Axis and not Spring nor Camel. We still need to setup Axis as a web application so we configure the web.xml in <tt>src/main/webapp/WEB-INF/web.xml</tt> as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;servlet&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>axis<span class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;servlet-class&gt;</span>org.apache.axis.transport.http.AxisServlet<span class="code-tag">&lt;/servlet-class&gt;</span>
    <span class="code-tag">&lt;/servlet&gt;</span>

    <span class="code-tag">&lt;servlet-mapping&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>axis<span class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;url-pattern&gt;</span>/services/*<span class="code-tag">&lt;/url-pattern&gt;</span>
    <span class="code-tag">&lt;/servlet-mapping&gt;</span>
</pre>
</div></div>
<p>The web.xml just registers Axis servlet that is handling the incoming web requests to its servlet mapping. We still need to configure Axis itself and this is done using its special configuration file <tt>server-config.wsdd</tt>. We nearly get this file for free if we let Axis generate the source code so we run the maven goal:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn axistools:wsdl2java
</pre>
</div></div>
<p>The tool will generate the source code based on the wsdl and save the files to the following folder:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.\target\generated-sources\axistools\wsdl2java\org\apache\camel\example\reportincident
deploy.wsdd
InputReportIncident.java
OutputReportIncident.java
ReportIncidentBindingImpl.java
ReportIncidentBindingStub.java
ReportIncidentService_PortType.java
ReportIncidentService_Service.java
ReportIncidentService_ServiceLocator.java
undeploy.wsdd
</pre>
</div></div>
<p>This is standard Axis and so far no Camel or Spring has been touched. To implement our webservice we will add our code, so we create a new class <tt>AxisReportIncidentService</tt> that implements the port type interface where we can implement our code logic what happens when the webservice is invoked.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.camel.example.axis;

<span class="code-keyword">import</span> org.apache.camel.example.reportincident.InputReportIncident;
<span class="code-keyword">import</span> org.apache.camel.example.reportincident.OutputReportIncident;
<span class="code-keyword">import</span> org.apache.camel.example.reportincident.ReportIncidentService_PortType;

<span class="code-keyword">import</span> java.rmi.RemoteException;

/**
 * Axis webservice
 */
<span class="code-keyword">public</span> class AxisReportIncidentService <span class="code-keyword">implements</span> ReportIncidentService_PortType {

    <span class="code-keyword">public</span> OutputReportIncident reportIncident(InputReportIncident parameters) <span class="code-keyword">throws</span> RemoteException {
        <span class="code-object">System</span>.out.println(<span class="code-quote">"Hello AxisReportIncidentService is called from "</span> + parameters.getGivenName());

        OutputReportIncident out = <span class="code-keyword">new</span> OutputReportIncident();
        out.setCode(<span class="code-quote">"OK"</span>);
        <span class="code-keyword">return</span> out;
    }

}
</pre>
</div></div>
<p>Now we need to configure Axis itself and this is done using its <tt>server-config.wsdd</tt> file. We nearly get this for for free from the auto generated code, we copy the stuff from <tt>deploy.wsdd</tt> and made a few modifications:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;</span>
<span class="code-tag">&lt;deployment xmlns=<span class="code-quote">"http://xml.apache.org/axis/wsdd/"</span> <span class="code-keyword">xmlns:java</span>=<span class="code-quote">"http://xml.apache.org/axis/wsdd/providers/java"</span>&gt;</span>
  <span class="code-tag"><span class="code-comment">&lt;!-- global configuration --&gt;</span></span>
	<span class="code-tag">&lt;globalConfiguration&gt;</span>
		<span class="code-tag">&lt;parameter name=<span class="code-quote">"sendXsiTypes"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
		<span class="code-tag">&lt;parameter name=<span class="code-quote">"sendMultiRefs"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
		<span class="code-tag">&lt;parameter name=<span class="code-quote">"sendXMLDeclaration"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
		<span class="code-tag">&lt;parameter name=<span class="code-quote">"axis.sendMinimizedElements"</span> value=<span class="code-quote">"true"</span>/&gt;</span>
	<span class="code-tag">&lt;/globalConfiguration&gt;</span>
	<span class="code-tag">&lt;handler name=<span class="code-quote">"URLMapper"</span> type=<span class="code-quote">"java:org.apache.axis.handlers.http.URLMapper"</span>/&gt;</span>

  <span class="code-tag"><span class="code-comment">&lt;!-- this service is from deploy.wsdd --&gt;</span></span>
  <span class="code-tag">&lt;service name=<span class="code-quote">"ReportIncidentPort"</span> provider=<span class="code-quote">"java:RPC"</span> style=<span class="code-quote">"document"</span> use=<span class="code-quote">"literal"</span>&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"wsdlTargetNamespace"</span> value=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>/&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"wsdlServiceElement"</span> value=<span class="code-quote">"ReportIncidentService"</span>/&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"schemaUnqualified"</span> value=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>/&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"wsdlServicePort"</span> value=<span class="code-quote">"ReportIncidentPort"</span>/&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"className"</span> value=<span class="code-quote">"org.apache.camel.example.reportincident.ReportIncidentBindingImpl"</span>/&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"wsdlPortType"</span> value=<span class="code-quote">"ReportIncidentService"</span>/&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"typeMappingVersion"</span> value=<span class="code-quote">"1.2"</span>/&gt;</span>
      &lt;operation name=<span class="code-quote">"reportIncident"</span> qname=<span class="code-quote">"ReportIncident"</span> returnQName=<span class="code-quote">"retNS:outputReportIncident"</span> <span class="code-keyword">xmlns:retNS</span>=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>
                 returnType=<span class="code-quote">"rtns:&gt;outputReportIncident"</span> <span class="code-keyword">xmlns:rtns</span>=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>
                 soapAction=<span class="code-quote">"http://reportincident.example.camel.apache.org/ReportIncident"</span> &gt;
        &lt;parameter qname=<span class="code-quote">"pns:inputReportIncident"</span> <span class="code-keyword">xmlns:pns</span>=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>
                 type=<span class="code-quote">"tns:&gt;inputReportIncident"</span> <span class="code-keyword">xmlns:tns</span>=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>/&gt;
      <span class="code-tag">&lt;/operation&gt;</span>
      <span class="code-tag">&lt;parameter name=<span class="code-quote">"allowedMethods"</span> value=<span class="code-quote">"reportIncident"</span>/&gt;</span>

      &lt;typeMapping
        <span class="code-keyword">xmlns:ns</span>=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>
        qname=<span class="code-quote">"ns:&gt;outputReportIncident"</span>
        type=<span class="code-quote">"java:org.apache.camel.example.reportincident.OutputReportIncident"</span>
        serializer=<span class="code-quote">"org.apache.axis.encoding.ser.BeanSerializerFactory"</span>
        deserializer=<span class="code-quote">"org.apache.axis.encoding.ser.BeanDeserializerFactory"</span>
        encodingStyle=""
      /&gt;
      &lt;typeMapping
        <span class="code-keyword">xmlns:ns</span>=<span class="code-quote">"http://reportincident.example.camel.apache.org"</span>
        qname=<span class="code-quote">"ns:&gt;inputReportIncident"</span>
        type=<span class="code-quote">"java:org.apache.camel.example.reportincident.InputReportIncident"</span>
        serializer=<span class="code-quote">"org.apache.axis.encoding.ser.BeanSerializerFactory"</span>
        deserializer=<span class="code-quote">"org.apache.axis.encoding.ser.BeanDeserializerFactory"</span>
        encodingStyle=""
      /&gt;
  <span class="code-tag">&lt;/service&gt;</span>

  <span class="code-tag"><span class="code-comment">&lt;!-- part of Axis configuration --&gt;</span></span>
	<span class="code-tag">&lt;transport name=<span class="code-quote">"http"</span>&gt;</span>
		<span class="code-tag">&lt;requestFlow&gt;</span>
			<span class="code-tag">&lt;handler type=<span class="code-quote">"URLMapper"</span>/&gt;</span>
			<span class="code-tag">&lt;handler type=<span class="code-quote">"java:org.apache.axis.handlers.http.HTTPAuthHandler"</span>/&gt;</span>
		<span class="code-tag">&lt;/requestFlow&gt;</span>
	<span class="code-tag">&lt;/transport&gt;</span>
<span class="code-tag">&lt;/deployment&gt;</span>
</pre>
</div></div>
<p>The <b>globalConfiguration</b> and <b>transport</b> is not in the deploy.wsdd file so you gotta write that yourself. The <b>service</b> is a 100% copy from deploy.wsdd. Axis has more configuration to it than shown here, but then you should check the <a href="http://ws.apache.org/axis/" class="external-link" rel="nofollow">Axis documentation</a>.</p>

<p>What we need to do now is important, as we need to modify the above configuration to use our webservice class than the default one, so we change the classname parameter to our class <b>AxisReportIncidentService</b>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;parameter name=<span class="code-quote">"className"</span> value=<span class="code-quote">"org.apache.camel.example.axis.AxisReportIncidentService"</span>/&gt;</span>
</pre>
</div></div>




<h4><a name="Tutorial-AXIS-Camel-RunningtheExample"></a>Running the Example</h4>
<p>Now we are ready to run our example for the first time, so we use Jetty as the quick web container using its maven command:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn jetty:run
</pre>
</div></div>
<p>Then we can hit the web browser and enter this URL: <tt><a href="http://localhost:8080/camel-example-axis/services" class="external-link" rel="nofollow">http://localhost:8080/camel-example-axis/services</a></tt> and you should see the famous Axis start page with the text <b>And now... Some Services</b>. </p>

<p>Clicking on the .wsdl link shows the wsdl file, but what. It's an auto generated one and not our original .wsdl file. So we need to fix this ASAP and this is done by configuring Axis in the server-config.wsdd file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;service name=<span class="code-quote">"ReportIncidentPort"</span> provider=<span class="code-quote">"java:RPC"</span> style=<span class="code-quote">"document"</span> use=<span class="code-quote">"literal"</span>&gt;</span>
    <span class="code-tag">&lt;wsdlFile&gt;</span>/WEB-INF/wsdl/report_incident.wsdl<span class="code-tag">&lt;/wsdlFile&gt;</span>
    ...
</pre>
</div></div>
<p>We do this by adding the wsdlFile tag in the service element where we can point to the real .wsdl file.</p>

<h3><a name="Tutorial-AXIS-Camel-IntegratingSpring"></a>Integrating Spring</h3>
<p>First we need to add its dependencies to the <b>pom.xml</b>. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.springframework<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>spring-web<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>2.5.5<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<p>Spring is integrated just as it would like to, we add its listener to the web.xml and a context parameter to be able to configure precisely what spring xml files to use:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;context-param&gt;</span>
        <span class="code-tag">&lt;param-name&gt;</span>contextConfigLocation<span class="code-tag">&lt;/param-name&gt;</span>
        <span class="code-tag">&lt;param-value&gt;</span>
            classpath:axis-example-context.xml
        <span class="code-tag">&lt;/param-value&gt;</span>
    <span class="code-tag">&lt;/context-param&gt;</span>

    <span class="code-tag">&lt;listener&gt;</span>
        <span class="code-tag">&lt;listener-class&gt;</span>org.springframework.web.context.ContextLoaderListener<span class="code-tag">&lt;/listener-class&gt;</span>
    <span class="code-tag">&lt;/listener&gt;</span>
</pre>
</div></div>
<p>Next is to add a plain spring XML file named <b>axis-example-context.xml</b> in the src/main/resources folder.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;</span>
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;

<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>
<p>The spring XML file is currently empty. We hit jetty again with <tt>mvn jetty:run</tt> just to make sure Spring was setup correctly.</p>

<h4><a name="Tutorial-AXIS-Camel-UsingSpring"></a>Using Spring</h4>
<p>We would like to be able to get hold of the Spring ApplicationContext from our webservice so we can get access to the glory spring, but how do we do this? And our webservice class AxisReportIncidentService is created and managed by Axis we want to let Spring do this. So we have two problems.</p>

<p>We solve these problems by creating a delegate class that Axis creates, and this delegate class gets hold on Spring and then gets our real webservice as a spring bean and invoke the service. </p>

<p>First we create a new class that is 100% independent from Axis and just a plain POJO. This is our real service.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.camel.example.axis;

<span class="code-keyword">import</span> org.apache.camel.example.reportincident.InputReportIncident;
<span class="code-keyword">import</span> org.apache.camel.example.reportincident.OutputReportIncident;

/**
 * Our real service that is not tied to Axis
 */
<span class="code-keyword">public</span> class ReportIncidentService  {

    <span class="code-keyword">public</span> OutputReportIncident reportIncident(InputReportIncident parameters) {
        <span class="code-object">System</span>.out.println(<span class="code-quote">"Hello ReportIncidentService is called from "</span> + parameters.getGivenName());

        OutputReportIncident out = <span class="code-keyword">new</span> OutputReportIncident();
        out.setCode(<span class="code-quote">"OK"</span>);
        <span class="code-keyword">return</span> out;
    }

}
</pre>
</div></div>
<p>So now we need to get from AxisReportIncidentService to this one ReportIncidentService using Spring. Well first of all we add our real service to spring XML configuration file so Spring can handle its lifecycle:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;</span>
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;
    
    <span class="code-tag">&lt;bean id=<span class="code-quote">"incidentservice"</span> class=<span class="code-quote">"org.apache.camel.example.axis.ReportIncidentService"</span>/&gt;</span>

<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>
<p>And then we need to modify AxisReportIncidentService to use Spring to lookup the spring bean <b>id="incidentservice"</b> and delegate the call. We do this by extending the spring class <tt>org.springframework.remoting.jaxrpc.ServletEndpointSupport</tt> so the refactored code is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.camel.example.axis;

<span class="code-keyword">import</span> org.apache.camel.example.reportincident.InputReportIncident;
<span class="code-keyword">import</span> org.apache.camel.example.reportincident.OutputReportIncident;
<span class="code-keyword">import</span> org.apache.camel.example.reportincident.ReportIncidentService_PortType;
<span class="code-keyword">import</span> org.springframework.remoting.jaxrpc.ServletEndpointSupport;

<span class="code-keyword">import</span> java.rmi.RemoteException;

/**
 * Axis webservice
 */
<span class="code-keyword">public</span> class AxisReportIncidentService <span class="code-keyword">extends</span> ServletEndpointSupport <span class="code-keyword">implements</span> ReportIncidentService_PortType {

    <span class="code-keyword">public</span> OutputReportIncident reportIncident(InputReportIncident parameters) <span class="code-keyword">throws</span> RemoteException {
        <span class="code-comment">// get hold of the spring bean from the application context
</span>        ReportIncidentService service = (ReportIncidentService) getApplicationContext().getBean(<span class="code-quote">"incidentservice"</span>);

        <span class="code-comment">// delegate to the real service
</span>        <span class="code-keyword">return</span> service.reportIncident(parameters);
    }

}
</pre>
</div></div>
<p>To see if everything is okay we run <tt>mvn jetty:run</tt>.</p>

<p>In the code above we get hold of our service at each request by looking up in the application context. However Spring also supports an <b>init</b> method where we can do this once. So we change the code to:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class AxisReportIncidentService <span class="code-keyword">extends</span> ServletEndpointSupport <span class="code-keyword">implements</span> ReportIncidentService_PortType {

    <span class="code-keyword">private</span> ReportIncidentService service;

    @Override
    <span class="code-keyword">protected</span> void onInit() <span class="code-keyword">throws</span> ServiceException {
        <span class="code-comment">// get hold of the spring bean from the application context
</span>        service = (ReportIncidentService) getApplicationContext().getBean(<span class="code-quote">"incidentservice"</span>);
    }

    <span class="code-keyword">public</span> OutputReportIncident reportIncident(InputReportIncident parameters) <span class="code-keyword">throws</span> RemoteException {
        <span class="code-comment">// delegate to the real service
</span>        <span class="code-keyword">return</span> service.reportIncident(parameters);
    }

}
</pre>
</div></div>
<p>So now we have integrated Axis with Spring and we are ready for Camel.</p>

<h3><a name="Tutorial-AXIS-Camel-IntegratingCamel"></a>Integrating Camel</h3>
<p>Again the first step is to add the dependencies to the maven <b>pom.xml</b> file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>camel-core<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>1.5.0<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>

        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>camel-spring<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>1.5.0<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>
<p>Now that we have integrated with Spring then we easily integrate with Camel as Camel works well with Spring.</p>
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Camel does not require Spring</b><br />Camel does not require Spring, we could easily have used Camel without Spring, but most users prefer to use Spring also.</td></tr></table></div>
<p>We choose to integrate Camel in the Spring XML file so we add the camel namespace and the schema location:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
xmlns:camel=<span class="code-quote">"http:<span class="code-comment">//activemq.apache.org/camel/schema/spring"</span>
</span>http:<span class="code-comment">//activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"</span>
</pre>
</div></div>
<h4><a name="Tutorial-AXIS-Camel-CamelContext"></a>CamelContext</h4>
<p><a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> is the heart of Camel its where all the <a href="/confluence/display/CAMEL/Routes" title="Routes">routes</a>, <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoints</a>, <a href="/confluence/display/CAMEL/Components" title="Components">components</a>, etc. is registered. So we setup a <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> and the spring XML files looks like:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;</span>
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:camel</span>=<span class="code-quote">"http://activemq.apache.org/camel/schema/spring"</span>
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
         http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"&gt;

    <span class="code-tag">&lt;bean id=<span class="code-quote">"incidentservice"</span> class=<span class="code-quote">"org.apache.camel.example.axis.ReportIncidentService"</span>/&gt;</span>

    <span class="code-tag">&lt;camel:camelContext id=<span class="code-quote">"camel"</span>&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- TODO: Here we can add Camel stuff --&gt;</span></span>
    <span class="code-tag">&lt;/camel:camelContext&gt;</span>

<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<h4><a name="Tutorial-AXIS-Camel-Storeafilebackup"></a>Store a file backup</h4>
<p>We want to store the web service request as a file before we return a response. To do this we want to send the file content as a <a href="/confluence/display/CAMEL/Message" title="Message">message</a> to an <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">endpoint</a> that produces the <a href="/confluence/display/CAMEL/File" title="File">file</a>. So we need to do two steps:</p>
<ul class="alternate" type="square">
	<li>configure the file backup endpoint</li>
	<li>send the message to the endpoint</li>
</ul>


<p>The endpoint is configured in spring XML so we just add it as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;camel:camelContext id=<span class="code-quote">"camelContext"</span>&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- endpoint named backup that is configued as a file component --&gt;</span></span>
        <span class="code-tag">&lt;camel:endpoint id=<span class="code-quote">"backup"</span> uri=<span class="code-quote">"file://target?append=false"</span>/&gt;</span>
    <span class="code-tag">&lt;/camel:camelContext&gt;</span>
</pre>
</div></div>
<p>In the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> we have defined our endpoint with the id <tt>backup</tt> and configured it use the <a href="/confluence/display/CAMEL/How+do+I+configure+endpoints" title="How do I configure endpoints">URL notation</a> that we know from the internet. Its a <tt>file</tt> scheme that accepts a context and some options. The contest is <tt>target</tt> and its the folder to store the file. The option is just as the internet with ? and &amp; for subsequent options. We configure it to not append, meaning than any existing file will be overwritten. See the <a href="/confluence/display/CAMEL/File" title="File">File</a> component for options and how to use the camel file endpoint.</p>

<p>Next up is to be able to send a message to this endpoint. The easiest way is to use a ProducerTemplate. A ProducerTemplate is inspired by Spring template pattern with for instance JmsTemplate or JdbcTemplate in mind. The template that all the grunt work and exposes a simple interface to the end-user where he/she can set the payload to send. Then the template will do proper resource handling and all related issues in that regard. But how do we get hold of such a template? Well the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> is able to provide one. This is done by configuring the template on the camel context in the spring XML as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;camel:camelContext id=<span class="code-quote">"camelContext"</span>&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- producer template exposed with this id --&gt;</span></span>
        <span class="code-tag">&lt;camel:template id=<span class="code-quote">"camelTemplate"</span>/&gt;</span>

        <span class="code-tag"><span class="code-comment">&lt;!-- endpoint named backup that is configued as a file component --&gt;</span></span>
        <span class="code-tag">&lt;camel:endpoint id=<span class="code-quote">"backup"</span> uri=<span class="code-quote">"file://target?append=false"</span>/&gt;</span>
    <span class="code-tag">&lt;/camel:camelContext&gt;</span>
</pre>
</div></div>
<p>Then we can expose a ProducerTemplate property on our service with a setter in the Java code as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class ReportIncidentService {

    <span class="code-keyword">private</span> ProducerTemplate template;

    <span class="code-keyword">public</span> void setTemplate(ProducerTemplate template) {
        <span class="code-keyword">this</span>.template = template;
    }
</pre>
</div></div>
<p>And then let Spring handle the dependency inject as below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;bean id=<span class="code-quote">"incidentservice"</span> class=<span class="code-quote">"org.apache.camel.example.axis.ReportIncidentService"</span>&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- set the producer template to use from the camel context below --&gt;</span></span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"template"</span> ref=<span class="code-quote">"camelTemplate"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>Now we are ready to use the producer template in our service to send the payload to the endpoint. The template has many <b>sendXXX</b> methods for this purpose. But before we send the payload to the file endpoint we must also specify what filename to store the file as. This is done by sending meta data with the payload. In Camel metadata is sent as headers. Headers is just a plain <tt>Map&lt;String, Object&gt;</tt>. So if we needed to send several metadata then we could construct an ordinary HashMap and put the values in there. But as we just need to send one header with the filename Camel has a convenient send method <tt>sendBodyAndHeader</tt> so we choose this one. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> OutputReportIncident reportIncident(InputReportIncident parameters) {
        <span class="code-object">System</span>.out.println(<span class="code-quote">"Hello ReportIncidentService is called from "</span> + parameters.getGivenName());

        <span class="code-object">String</span> data = parameters.getDetails();

        <span class="code-comment">// store the data as a file
</span>        <span class="code-object">String</span> filename = parameters.getIncidentId() + <span class="code-quote">".txt"</span>;
        <span class="code-comment">// send the data to the endpoint and the header contains what filename it should be stored as
</span>        template.sendBodyAndHeader(<span class="code-quote">"backup"</span>, data, <span class="code-quote">"org.apache.camel.file.name"</span>, filename);

        OutputReportIncident out = <span class="code-keyword">new</span> OutputReportIncident();
        out.setCode(<span class="code-quote">"OK"</span>);
        <span class="code-keyword">return</span> out;
    }
</pre>
</div></div>
<p>The template in the code above uses 4 parameters:</p>
<ul class="alternate" type="square">
	<li>the endpoint name, in this case the id referring to the endpoint defined in Spring XML in the camelContext element.</li>
	<li>the payload, can be any kind of object</li>
	<li>the key for the header, in this case a Camel keyword to set the filename</li>
	<li>and the value for the header</li>
</ul>


<h3><a name="Tutorial-AXIS-Camel-Runningtheexample"></a>Running the example</h3>
<p>We start our integration with maven using <tt>mvn jetty:run</tt>. Then we open a browser and hit <tt><a href="http://localhost:8080" class="external-link" rel="nofollow">http://localhost:8080</a></tt>. Jetty is so smart that it display a frontpage with links to the deployed application so just hit the link and you get our application. Now we hit append /services to the URL to access the Axis frontpage. The URL should be <tt><a href="http://localhost:8080/camel-example-axis/services" class="external-link" rel="nofollow">http://localhost:8080/camel-example-axis/services</a></tt>. </p>

<p>You can then test it using a web service test tools such as <a href="http://www.soapui.org/" class="external-link" rel="nofollow">SoapUI</a>. <br/>
Hitting the service will output to the console</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
2008-09-06 15:01:41.718::INFO:  Started SelectChannelConnector @ 0.0.0.0:8080
[INFO] Started Jetty Server
Hello ReportIncidentService is called from Ibsen
</pre>
</div></div>
<p>And there should be a file in the target subfolder.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
dir target /b
123.txt
</pre>
</div></div>

<h3><a name="Tutorial-AXIS-Camel-UnitTesting"></a>Unit Testing</h3>
<p>We would like to be able to unit test our <b>ReportIncidentService</b> class. So we add junit to the maven dependency:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>junit<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>junit<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>3.8.2<span class="code-tag">&lt;/version&gt;</span>
            <span class="code-tag">&lt;scope&gt;</span>test<span class="code-tag">&lt;/scope&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>
<p>And then we create a plain junit testcase for our service class.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.camel.example.axis;

<span class="code-keyword">import</span> junit.framework.TestCase;
<span class="code-keyword">import</span> org.apache.camel.example.reportincident.InputReportIncident;
<span class="code-keyword">import</span> org.apache.camel.example.reportincident.OutputReportIncident;

/**
 * Unit test of service
 */
<span class="code-keyword">public</span> class ReportIncidentServiceTest <span class="code-keyword">extends</span> TestCase {

    <span class="code-keyword">public</span> void testIncident() {
        ReportIncidentService service = <span class="code-keyword">new</span> ReportIncidentService();

        InputReportIncident input = createDummyIncident();
        OutputReportIncident output = service.reportIncident(input);
        assertEquals(<span class="code-quote">"OK"</span>, output.getCode());
    }

   <span class="code-keyword">protected</span> InputReportIncident createDummyIncident() {
        InputReportIncident input = <span class="code-keyword">new</span> InputReportIncident();
        input.setEmail(<span class="code-quote">"davsclaus@apache.org"</span>);
        input.setIncidentId(<span class="code-quote">"12345678"</span>);
        input.setIncidentDate(<span class="code-quote">"2008-07-13"</span>);
        input.setPhone(<span class="code-quote">"+45 2962 7576"</span>);
        input.setSummary(<span class="code-quote">"Failed operation"</span>);
        input.setDetails(<span class="code-quote">"The wrong foot was operated."</span>);
        input.setFamilyName(<span class="code-quote">"Ibsen"</span>);
        input.setGivenName(<span class="code-quote">"Claus"</span>);
        <span class="code-keyword">return</span> input;
    }

}
</pre>
</div></div>
<p>Then we can run the test with maven using: <tt>mvn test</tt>. But we will get a failure:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Running org.apache.camel.example.axis.ReportIncidentServiceTest
Hello ReportIncidentService is called from Claus
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.235 sec &lt;&lt;&lt; FAILURE!

Results :

Tests in error:
  testIncident(org.apache.camel.example.axis.ReportIncidentServiceTest)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
</pre>
</div></div>
<p>What is the problem? Well our service uses a CamelProducer (the template) to send a message to the file endpoint so the message will be stored in a file. What we need is to get hold of such a producer and inject it on our service, by calling the setter.</p>

<p>Since Camel is very light weight and embedable we are able to create a CamelContext and add the endpoint in our unit test code directly. We do this to show how this is possible:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">private</span> CamelContext context;

    @Override
    <span class="code-keyword">protected</span> void setUp() <span class="code-keyword">throws</span> Exception {
        <span class="code-keyword">super</span>.setUp();
        <span class="code-comment">// CamelContext is just created like <span class="code-keyword">this</span>
</span>        context = <span class="code-keyword">new</span> DefaultCamelContext();

        <span class="code-comment">// then we can create our endpoint and set the options
</span>        FileEndpoint endpoint = <span class="code-keyword">new</span> FileEndpoint();
        <span class="code-comment">// the endpoint must have the camel context set also
</span>        endpoint.setCamelContext(context);
        <span class="code-comment">// our output folder
</span>        endpoint.setFile(<span class="code-keyword">new</span> File(<span class="code-quote">"target"</span>));
        <span class="code-comment">// and the option not to append
</span>        endpoint.setAppend(<span class="code-keyword">false</span>);

        <span class="code-comment">// then we add the endpoint just in java code just as the spring XML, we register it with the <span class="code-quote">"backup"</span> id.
</span>        context.addSingletonEndpoint(<span class="code-quote">"backup"</span>, endpoint);

        <span class="code-comment">// <span class="code-keyword">finally</span> we need to start the context so Camel is ready to rock
</span>        context.start();
    }

    @Override
    <span class="code-keyword">protected</span> void tearDown() <span class="code-keyword">throws</span> Exception {
        <span class="code-keyword">super</span>.tearDown();
        <span class="code-comment">// and we are nice boys so we stop it to allow resources to clean up
</span>        context.stop();
    }
</pre>
</div></div>
<p>So now we are ready to set the ProducerTemplate on our service, and we get a hold of that baby from the CamelContext as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> void testIncident() {
        ReportIncidentService service = <span class="code-keyword">new</span> ReportIncidentService();

        <span class="code-comment">// get a producer template from the camel context
</span>        ProducerTemplate template = context.createProducerTemplate();
        <span class="code-comment">// inject it on our service using the setter
</span>        service.setTemplate(template);

        InputReportIncident input = createDummyIncident();
        OutputReportIncident output = service.reportIncident(input);
        assertEquals(<span class="code-quote">"OK"</span>, output.getCode());
    }
</pre>
</div></div>
<p>And this time when we run the unit test its a success:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
</pre>
</div></div>
<p>We would like to test that the file exists so we add these two lines to our test method:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        <span class="code-comment">// should generate a file also
</span>        File file = <span class="code-keyword">new</span> File(<span class="code-quote">"target/"</span> + input.getIncidentId() + <span class="code-quote">".txt"</span>);
        assertTrue(<span class="code-quote">"File should exists"</span>, file.exists());
</pre>
</div></div>

<h4><a name="Tutorial-AXIS-Camel-SmarterUnitTestingwithSpring"></a>Smarter Unit Testing with Spring</h4>
<p>The unit test above requires us to assemble the Camel pieces manually in java code. What if we would like our unit test to use our spring configuration file <b>axis-example-context.xml</b> where we already have setup the endpoint. And of course we would like to test using this configuration file as this is the real file we will use. Well hey presto the xml file is a spring ApplicationContext file and spring is able to load it, so we go the spring path for unit testing. First we add the spring-test jar to our maven dependency:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.springframework<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>spring-test<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;scope&gt;</span>test<span class="code-tag">&lt;/scope&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>
<p>And then we refactor our unit test to be a standard spring unit class. What we need to do is to extend <tt>AbstractJUnit38SpringContextTests</tt> instead of <tt>TestCase</tt> in our unit test. Since Spring 2.5 embraces annotations we will use one as well to instruct what our xml configuration file is located:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@ContextConfiguration(locations = <span class="code-quote">"classpath:axis-example-context.xml"</span>)
<span class="code-keyword">public</span> class ReportIncidentServiceTest <span class="code-keyword">extends</span> AbstractJUnit38SpringContextTests {
</pre>
</div></div>
<p>What we must remember to add is the <b>classpath:</b> prefix as our xml file is located in <tt>src/main/resources</tt>. If we omit the prefix then Spring will by default try to locate the xml file in the current package and that is org.apache.camel.example.axis. If the xml file is located outside the classpath you can use file: prefix instead. So with these two modifications we can get rid of all the setup and teardown code we had before and now we will test our real configuration.</p>

<p>The last change is to get hold of the producer template and now we can just refer to the bean id it has in the spring xml file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag"><span class="code-comment">&lt;!-- producer template exposed with this id --&gt;</span></span>
        <span class="code-tag">&lt;camel:template id=<span class="code-quote">"camelTemplate"</span>/&gt;</span>
</pre>
</div></div>
<p>So we get hold of it by just getting it from the spring ApplicationContext as all spring users is used to do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        <span class="code-comment">// get a producer template from the the spring context
</span>        ProducerTemplate template = (ProducerTemplate) applicationContext.getBean(<span class="code-quote">"camelTemplate"</span>);
        <span class="code-comment">// inject it on our service using the setter
</span>        service.setTemplate(template);
</pre>
</div></div>

<p>Now our unit test is much better, and a real power of Camel is that is fits nicely with Spring and you can use standard Spring'ish unit test to test your Camel applications as well.</p>

<h3><a name="Tutorial-AXIS-Camel-UnitTestcallingWebService"></a>Unit Test calling WebService</h3>
<p>What if you would like to execute a unit test where you send a webservice request to the <b>AxisReportIncidentService</b> how do we unit test this one? Well first of all the code is merely just a delegate to our real service that we have just tested, but nevertheless its a good question and we would like to know how. Well the answer is that we can exploit that fact that Jetty is also a slim web container that can be embedded anywhere just as Camel can. So we add this to our pom.xml:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
        <span class="code-tag">&lt;dependency&gt;</span>
            <span class="code-tag">&lt;groupId&gt;</span>org.mortbay.jetty<span class="code-tag">&lt;/groupId&gt;</span>
            <span class="code-tag">&lt;artifactId&gt;</span>jetty<span class="code-tag">&lt;/artifactId&gt;</span>
            <span class="code-tag">&lt;version&gt;</span>${jetty-version}<span class="code-tag">&lt;/version&gt;</span>
            <span class="code-tag">&lt;scope&gt;</span>test<span class="code-tag">&lt;/scope&gt;</span>
        <span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>
<p>Then we can create a new class <b>AxisReportIncidentServiceTest</b> to unit test with Jetty. The code to setup Jetty is shown below with code comments:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class AxisReportIncidentServiceTest <span class="code-keyword">extends</span> TestCase {

    <span class="code-keyword">private</span> Server server;

    <span class="code-keyword">private</span> void startJetty() <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// create an embedded Jetty server
</span>        server = <span class="code-keyword">new</span> Server();

        <span class="code-comment">// add a listener on port 8080 on localhost (127.0.0.1)
</span>        Connector connector = <span class="code-keyword">new</span> SelectChannelConnector();
        connector.setPort(8080);
        connector.setHost(<span class="code-quote">"127.0.0.1"</span>);
        server.addConnector(connector);

        <span class="code-comment">// add our web context path
</span>        WebAppContext wac = <span class="code-keyword">new</span> WebAppContext();
        wac.setContextPath(<span class="code-quote">"/unittest"</span>);
        <span class="code-comment">// set the location of the exploded webapp where WEB-INF is located
</span>        <span class="code-comment">// <span class="code-keyword">this</span> is a nice feature of Jetty where we can point to src/main/webapp
</span>        wac.setWar(<span class="code-quote">"./src/main/webapp"</span>);
        server.setHandler(wac);

        <span class="code-comment">// then start Jetty
</span>        server.setStopAtShutdown(<span class="code-keyword">true</span>);
        server.start();
    }

    @Override
    <span class="code-keyword">protected</span> void setUp() <span class="code-keyword">throws</span> Exception {
        <span class="code-keyword">super</span>.setUp();
        startJetty();
    }

    @Override
    <span class="code-keyword">protected</span> void tearDown() <span class="code-keyword">throws</span> Exception {
        <span class="code-keyword">super</span>.tearDown();
        server.stop();
    }

}
</pre>
</div></div>
<p>Now we just need to send the incident as a webservice request using Axis. So we add the following code:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> void testReportIncidentWithAxis() <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// the url to the axis webservice exposed by jetty
</span>        URL url = <span class="code-keyword">new</span> URL(<span class="code-quote">"http:<span class="code-comment">//localhost:8080/unittest/services/ReportIncidentPort"</span>);
</span>
        <span class="code-comment">// Axis stuff to get the port where we can send the webservice request
</span>        ReportIncidentService_ServiceLocator locator = <span class="code-keyword">new</span> ReportIncidentService_ServiceLocator();
        ReportIncidentService_PortType port = locator.getReportIncidentPort(url);

        <span class="code-comment">// create input to send
</span>        InputReportIncident input = createDummyIncident();
        <span class="code-comment">// send the webservice and get the response
</span>        OutputReportIncident output = port.reportIncident(input);
        assertEquals(<span class="code-quote">"OK"</span>, output.getCode());

        <span class="code-comment">// should generate a file also
</span>        File file = <span class="code-keyword">new</span> File(<span class="code-quote">"target/"</span> + input.getIncidentId() + <span class="code-quote">".txt"</span>);
        assertTrue(<span class="code-quote">"File should exists"</span>, file.exists());
    }

    <span class="code-keyword">protected</span> InputReportIncident createDummyIncident() {
        InputReportIncident input = <span class="code-keyword">new</span> InputReportIncident();
        input.setEmail(<span class="code-quote">"davsclaus@apache.org"</span>);
        input.setIncidentId(<span class="code-quote">"12345678"</span>);
        input.setIncidentDate(<span class="code-quote">"2008-07-13"</span>);
        input.setPhone(<span class="code-quote">"+45 2962 7576"</span>);
        input.setSummary(<span class="code-quote">"Failed operation"</span>);
        input.setDetails(<span class="code-quote">"The wrong foot was operated."</span>);
        input.setFamilyName(<span class="code-quote">"Ibsen"</span>);
        input.setGivenName(<span class="code-quote">"Claus"</span>);
        <span class="code-keyword">return</span> input;
    }
</pre>
</div></div>
<p>And now we have an unittest that sends a webservice request using good old Axis.</p>

<h3><a name="Tutorial-AXIS-Camel-Annotations"></a>Annotations</h3>
<p>Both Camel and Spring has annotations that can be used to configure and wire trivial settings more elegantly. Camel has the endpoint annotation <tt><a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">@EndpointInjected</a></tt> that is just what we need. With this annotation we can inject the endpoint into our service. The annotation takes either a name or uri parameter. The name is the bean id in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>. The uri is the URI configuration for the endpoint. Using this you can actually inject an endpoint that you have not defined in the camel context. As we have defined our endpoint with the id <b>backup</b> we use the name parameter.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    @EndpointInject(name = <span class="code-quote">"backup"</span>)
    <span class="code-keyword">private</span> ProducerTemplate template;
</pre>
</div></div>
<p>Camel is smart as <tt><a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">@EndpointInjected</a></tt> supports different kinds of object types. We like the ProducerTemplate so we just keep it as it is. <br/>
Since we use annotations on the field directly we do not need to set the property in the spring xml file so we change our service bean:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;bean id=<span class="code-quote">"incidentservice"</span> class=<span class="code-quote">"org.apache.camel.example.axis.ReportIncidentService"</span>/&gt;</span>
</pre>
</div></div>
<p>Running the unit test with <tt>mvn test</tt> reveals that it works nicely.</p>

<p>And since we use the <tt><a href="/confluence/display/CAMEL/Bean+Integration" title="Bean Integration">@EndpointInjected</a></tt> that refers to the endpoint with the id backup directly we can loose the template tag in the xml, so its shorter:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;bean id=<span class="code-quote">"incidentservice"</span> class=<span class="code-quote">"org.apache.camel.example.axis.ReportIncidentService"</span>/&gt;</span>

    <span class="code-tag">&lt;camel:camelContext id=<span class="code-quote">"camelContext"</span>&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- producer template exposed with this id --&gt;</span></span>
        <span class="code-tag">&lt;camel:template id=<span class="code-quote">"camelTemplate"</span>/&gt;</span>

        <span class="code-tag"><span class="code-comment">&lt;!-- endpoint named backup that is configued as a file component --&gt;</span></span>
        <span class="code-tag">&lt;camel:endpoint id=<span class="code-quote">"backup"</span> uri=<span class="code-quote">"file://target?append=false"</span>/&gt;</span>

    <span class="code-tag">&lt;/camel:camelContext&gt;</span>
</pre>
</div></div>
<p>And the final touch we can do is that since the endpoint is injected with concrete endpoint to use we can remove the <tt>"backup"</tt> name parameter when we send the message. So we change from:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        <span class="code-comment">// send the data to the endpoint and the header contains what filename it should be stored as
</span>        template.sendBodyAndHeader(<span class="code-quote">"backup"</span>, data, <span class="code-quote">"org.apache.camel.file.name"</span>, filename);
</pre>
</div></div>
<p>To without the name:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        <span class="code-comment">// send the data to the endpoint and the header contains what filename it should be stored as
</span>        template.sendBodyAndHeader(data, <span class="code-quote">"org.apache.camel.file.name"</span>, filename);
</pre>
</div></div>
<p>Then we avoid to duplicate the name and if we rename the endpoint name then we don't forget to change it in the code also.</p>

<h3><a name="Tutorial-AXIS-Camel-TheEnd"></a>The End</h3>
<p>This tutorial hasn't really touched the one of the key concept of Camel as a powerful routing and mediation framework. But we wanted to demonstrate its flexibility and that it integrates well with even older frameworks such as Apache Axis 1.4.</p>

<p>Check out the other tutorials on Camel and the other examples. </p>

<p>Note that the code shown here also applies to Camel 1.4 so actually you can get started right away with the released version of Camel. As this time of writing Camel 1.5 is work in progress.</p>

<h3><a name="Tutorial-AXIS-Camel-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Tutorials" title="Tutorials">Tutorials</a></li>
	<li><a href="/confluence/display/CAMEL/Examples" title="Examples">Examples</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Tutorial-AXIS-Camel">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=96474&revisedVersion=30&originalVersion=29">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Tutorial-AXIS-Camel?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message