blob: b4e265e9aac60fa312095519f27a0a1ea453238b [file] [log] [blame]
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
~ 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.
-->
<document>
<properties>
<title>Apache Synapse - Sample 361</title>
</properties>
<body>
<section name="Sample 361: Introduction to DBReport Mediator">
<div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;sequence name="main"&gt;
&lt;in&gt;
&lt;send&gt;
&lt;endpoint&gt;
&lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
&lt;/endpoint&gt;
&lt;/send&gt;
&lt;/in&gt;
&lt;out&gt;
&lt;log level="custom"&gt;
&lt;property name="text" value="** Reporting to the Database **"/&gt;
&lt;/log&gt;
&lt;dbreport&gt;
&lt;connection&gt;
&lt;pool&gt;
&lt;driver&gt;org.apache.derby.jdbc.ClientDriver&lt;/driver&gt;
&lt;url&gt;jdbc:derby://localhost:1527/synapsedb;create=false&lt;/url&gt;
&lt;user&gt;synapse&lt;/user&gt;
&lt;password&gt;synapse&lt;/password&gt;
&lt;/pool&gt;
&lt;/connection&gt;
&lt;statement&gt;
&lt;sql&gt;update company set price=? where name =?&lt;/sql&gt;
&lt;parameter xmlns:m1="http://services.samples/xsd"
xmlns:m0="http://services.samples"
expression="//m0:return/m1:last/child::text()" type="DOUBLE"/&gt;
&lt;parameter xmlns:m1="http://services.samples/xsd"
xmlns:m0="http://services.samples"
expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/&gt;
&lt;/statement&gt;
&lt;/dbreport&gt;
&lt;send/&gt;
&lt;/out&gt;
&lt;/sequence&gt;
&lt;/definitions&gt;</div>
<subsection name="Objective">
<p>
<a href="sample360.html">Sample 360</a> shows how to perform database lookups
in Synapse. This sample illustrates how to write to a given database from
Synapse using the dbreport mediator.
</p>
</subsection>
<subsection name="Pre-requisites">
<p>
<ul>
<li>
Setup a Derby database as described in the <a href="setup/db.html">database setup guide</a>
</li>
<li>
Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
</li>
<li>
Start Synapse using the configuration numbered 361 (repository/conf/sample/synapse_sample_361.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 361<br/>
Windows: synapse.bat -sample 361
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
This sample demonstrates how to perform simple database write operations in
Synapse. The dbreport mediator writes (i.e. inserts one row) to a table using the
details available in messages. It works the same way as the dblookup mediator.
In this sample, dbreport mediator is used for updating the stock price of the
company using the last quote value which is calculated by evaluating an XPath
against the response message. After running this sample, user can check the
company table using the Derby client tool. It will show the value inserted by the
dbreport mediator.
</p>
<p>
To try this out run the sample client as follows.
</p>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
<p>
Now execute the following SQL query against the Derby database using the Derby
client tool.
</p>
<div class="command">select price from company where name='IBM';</div>
<p>
This operation will return the stock quote value returned earlier by Axis2. You
can compare the output of the sample Axis2 client with the output of the Derby
client tool for confirmation.
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>