| <?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 7</title> |
| </properties> |
| <body> |
| <section name="Sample 7: Introduction to Local Registry Entries and Using Schema Validation"> |
| <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse"> |
| |
| <sequence name="main"> |
| <in> |
| <validate> |
| <schema key="validate_schema"/> |
| <on-fail> |
| <!-- if the request does not validate againt schema throw a fault --> |
| <makefault response="true"> |
| <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/> |
| <reason value="Invalid custom quote request"/> |
| </makefault> |
| </on-fail> |
| </validate> |
| </in> |
| <send/> |
| </sequence> |
| |
| <localEntry key="validate_schema"> |
| <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" |
| xmlns="http://services.samples" elementFormDefault="qualified" |
| attributeFormDefault="unqualified" targetNamespace="http://services.samples"> |
| <xs:element name="getQuote"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="request"> |
| <xs:complexType> |
| <xs:sequence> |
| <xs:element name="stocksymbol" type="xs:string"/> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| </xs:sequence> |
| </xs:complexType> |
| </xs:element> |
| </xs:schema> |
| </localEntry> |
| |
| </definitions></div> |
| <subsection name="Objective"> |
| <p> |
| Demonstrating the usage of the validate mediator for XML schema validation |
| and using local registry (local entries) for storing configuration metadata. |
| </p> |
| </subsection> |
| <subsection name="Pre-requisites"> |
| <p> |
| <ul> |
| <li> |
| Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2 |
| </li> |
| <li> |
| Start Synapse using the configuration numbered 7 (repository/conf/sample/synapse_sample_7.xml) |
| <div class="command"> |
| Unix/Linux: sh synapse.sh -sample 7<br/> |
| Windows: synapse.bat -sample 7 |
| </div> |
| </li> |
| </ul> |
| </p> |
| </subsection> |
| <subsection name="Executing the Client"> |
| <p> |
| This example shows how a static XML fragment could be stored in the the |
| Synapse local registry. Resources defined in the local registry are static |
| (i.e. never changes over the lifetime of the configuration) and may be |
| specified as a source URL, in-line text or in-line xml. In this example the |
| schema is made available under the key 'validate_schema'. |
| </p> |
| <p> |
| The validate mediator by default operates on the first child element of the |
| SOAP body. You may specify an XPath expression using the 'source' attribute |
| to override this behaviour. The validate mediator in this sample uses the 'validate_schema' |
| resource to validate the incoming message, and if the message validation fails |
| it invokes the 'on-fail' sequence of mediators. |
| </p> |
| <p> |
| If you send a stockquote request using the 'ant stockquote ...' command as follows |
| you will get a fault back with the message 'Invalid custom quote request' as |
| the schema validation fails. This is because the schema used in the example |
| expects a slightly different message than what is created by the stock quote |
| client. (i.e. expects a 'stocksymbol' element instead of 'symbol' to specify |
| the stock symbol) |
| </p> |
| <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div> |
| </subsection> |
| </section> |
| <p><a href="../samples.html">Back to Catalog</a></p> |
| </body> |
| </document> |