\section{Math\-Ops Class Reference}
\label{classMathOps}\index{MathOps@{MathOps}}
A test class for exception and fault mapping. 




\subsection{Detailed Description}
A test class for exception and fault mapping.

This class is used to demonstrate error handling and fault mapping  testing. Here I have generated the stuff using Math\-Ops.wsdl. This wsdl simply have a complex type which consists of three simple types(xsd:int, xsd:foat and xsd:string). For port\-Type operation \char`\"{}div\char`\"{} we have a fault named Div\-By\-Zero the message for which is Div\-By\-Zero\-Fault which is of the complex type mentioned above(Div\-By\-Zero\-Struct). The server side for this client sample is in \$AXISCPP\_\-HOME/samples/server/rpcfault. When you generated the client side it will generate header and implementation files for three different types, namely, Math\-Ops: Service request class which calls div service method in the server and get\-Fault\-Details if there's any. Div\-By\-Zero\-Struct: The type corresponding to the complex type Div\-By\-Zero\-Struct in the Math\-Ops.wsdl Axis\-Div\-By\-Zero\-Exception: For each fault in wsdl we generate an exception class which is derived from {\bf Axis\-Exception} {\rm (p.\,\pageref{classAxisException})} base class which is the root class for exceptions in Axis C++. This root class in tern is derived from std::exception.  In the server side if division by zero fault is encountered in the service method it will call ... ... p\-IWSSZ-$>$create\-Soap\-Fault(\char`\"{}Div\-By\-Zero\-Struct\char`\"{}, \char`\"{}{\tt http://soapinterop.org/wsdl}\char`\"{}); ... ... where p\-IWSSZ is the soap serializer interface. Once this method is called  m\_\-p\-Soap\-Envelope-$>$m\_\-p\-Soap\-Body-$>$m\_\-p\-Soap\-Fault is assigned a new soap fault object. After that,

Div\-By\-Zero\-Struct$\ast$ p\-Obj\-Fault = new Div\-By\-Zero\-Struct(); p\-Obj\-Fault-$>$var\-String = \char`\"{}Division by zero exception\char`\"{}; p\-Obj\-Fault-$>$var\-Int = 1; p\-Obj\-Fault-$>$var\-Float = 10.52; if (p\-Obj\-Fault) p\-IWSSZ-$>$add\-Fault\-Detail(p\-Obj\-Fault, (void$\ast$) Axis\_\-Serialize\_\-Div\-By\-Zero\-Struct, (void$\ast$) Axis\_\-Delete\_\-Div\-By\-Zero\-Struct,\char`\"{}Div\-By\-Zero\char`\"{}, Axis\_\-URI\_\-Div\-By\-Zero\-Struct);

Here the service developer fills the Div\-By\-Zero\-Struct with appropriate values and call Soap\-Serialzer's add\-Fault\-Detail method with the knowledge of serializing and deserializing. Once this method is called set\-Fault\-Detail method of Soap\-Fault is called from {\bf Soap\-Serializer} {\rm (p.\,\pageref{classSoapSerializer})}. ... ... int Soap\-Fault::set\-Fault\-Detail(const Param$\ast$ p\-Fault\-Detail) \{ m\_\-p\-Fault\-Detail = (Param$\ast$) p\-Fault\-Detail; return AXIS\_\-SUCCESS; \} ... ...

So once the serialize method of {\bf Soap\-Serializer} {\rm (p.\,\pageref{classSoapSerializer})} is called then in addition to serializing Faultcode, Faultstring and Faultactor, Soap\-Fault's Fault\-Detail object is also serialized into the soap body's fault detail tag. So in the wire comes the Soap message with a soap fault.

Now when you run the client here, if it catch an exception  ... ... catch(Axis\-Exception\& e) \{ int i\-Exception\-Code = e.get\-Exception\-Code(); if(AXISC\_\-NODE\_\-VALUE\_\-MISMATCH\_\-EXCEPTION != i\-Exception\-Code) \{ throw; \} ... ... it checks the exception code and if exception code is not equal to AXISC\_\-NODE\_\-VALUE\_\-MISMATCH\_\-EXCEPTION value it means that the exception thrown not because of a soap fault. Exception is caused by some other mean in the client side. If a soap fault comes in the wire Soap\-Deseriazer's  check\-Message\-Body method throws and exception ... ... throw Axis\-Exception(AXISC\_\-NODE\_\-VALUE\_\-MISMATCH\_\-EXCEPTION); ... ...

When we catch that exception we knows that a soap fault has come. ... ... else if (AXIS\_\-SUCCESS == m\_\-p\-Call-$>$check\-Fault(\char`\"{}Fault\char`\"{}, \char`\"{}{\tt http://localhost/axis/Math\-Ops}\char`\"{} )) //Exception handling code goes here \{ c\-Faultcode = m\_\-p\-Call-$>$get\-Element\-As\-String(\char`\"{}faultcode\char`\"{}, 0); c\-Faultstring = m\_\-p\-Call-$>$get\-Element\-As\-String(\char`\"{}faultstring\char`\"{}, 0); c\-Faultactor = m\_\-p\-Call-$>$get\-Element\-As\-String(\char`\"{}faultactor\char`\"{}, 0); if(0 == strcmp(\char`\"{}Div\-By\-Zero\-Struct\char`\"{}, c\-Faultstring)) \{ if (AXIS\_\-SUCCESS == m\_\-p\-Call-$>$check\-Fault(\char`\"{}faultdetail\char`\"{}, \char`\"{}{\tt http://localhost/axis/Math\-Ops}\char`\"{})) \{ Div\-By\-Zero\-Struct$\ast$ p\-Fault\-Detail = NULL; p\-Fault\-Detail = (Div\-By\-Zero\-Struct$\ast$)m\_\-p\-Call-$>$ get\-Cmplx\-Object((void$\ast$) Axis\_\-De\-Serialize\_\-Div\-By\-Zero\-Struct, (void$\ast$) Axis\_\-Create\_\-Div\-By\-Zero\-Struct, (void$\ast$) Axis\_\-Delete\_\-Div\-By\-Zero\-Struct,\char`\"{}faultstruct1\char`\"{}, 0); //Client developers code goes here to handle the struct can  //be inserted here char$\ast$ temp = p\-Fault\-Detail-$>$var\-String; printf(\char`\"{}s\par
\char`\"{}, temp); printf(\char`\"{}faultcode:s\par
\char`\"{}, c\-Faultcode); printf(\char`\"{}faultstring:s\par
\char`\"{}, c\-Faultstring); printf(\char`\"{}faultactor:s\par
\char`\"{}, c\-Faultactor); m\_\-p\-Call-$>$un\-Initialize(); throw Axis\-Div\-By\-Zero\-Exception(p\-Fault\-Detail); \} \} ... ... Note that we compares c\-Faultstring which contains soap fault's faultstring  with the Div\-By\-Zero\-Struct. This is so because in the server side we set the  faultstring to take the fault's generated type name. If the faultdetail is just a simple string ... ... else \{ c\-Faultdetail = m\_\-p\-Call-$>$get\-Element\-As\-String(\char`\"{}faultdetail\char`\"{}, 0); throw Axis\-Exception(c\-Faultdetail); \} ... ...

You can also use this class as a test utility to test exceptions. You can generate exception in the server side and client side and test from here whether the correct exception messages come to the client. For example you can remove the shared libraries for Math\-Ops service (libmathops.so) from \$AXIS\_\-HOME/webservices folder and try to run client here. The you will get an exception message like \char`\"{}Service library is not loaded to the engine\char`\"{}.

\begin{Desc}
\item[Author: ]\par
Damitha Kumarage ({\tt damitha@opensource.lk}, {\tt damitha@jkcsworld.com}) \end{Desc}




The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
Math\-Ops.h\item 
Math\-Ops.cpp\end{CompactItemize}
