You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by da...@apache.org on 2004/06/13 16:26:48 UTC
cvs commit: ws-axis/c/tests/client/exceptionTest AxisDivByZeroException.cpp AxisDivByZeroException.h DivByZeroStruct.cpp DivByZeroStruct.h Makefile.am MathOps.cpp MathOps.h MathOpsClient.cpp
damitha 2004/06/13 07:26:48
Added: c/tests/client/exceptionTest AxisDivByZeroException.cpp
AxisDivByZeroException.h DivByZeroStruct.cpp
DivByZeroStruct.h Makefile.am MathOps.cpp MathOps.h
MathOpsClient.cpp
Log:
Revision Changes Path
1.1 ws-axis/c/tests/client/exceptionTest/AxisDivByZeroException.cpp
Index: AxisDivByZeroException.cpp
===================================================================
/*
* This is the implementation file genarated by WSDL2Ws tool.
* AxisDivByZeroException.cpp: implemtation for the AxisDivByZeroException.
*
*/
#include "AxisDivByZeroException.h"
#include <axis/server/AxisWrapperAPI.h>
AxisDivByZeroException::AxisDivByZeroException()
{
/* This only serves the pupose of indicating that the
* service has thrown an excpetion
*/
m_iExceptionCode = AXISC_SERVICE_THROWN_EXCEPTION;
processException(m_iExceptionCode);
}
AxisDivByZeroException::AxisDivByZeroException(DivByZeroStruct*pFault)
{
m_iExceptionCode = AXISC_SERVICE_THROWN_EXCEPTION;
processException(pFault);}
AxisDivByZeroException::AxisDivByZeroException(int iExceptionCode)
{
m_iExceptionCode = iExceptionCode;
processException (iExceptionCode);
}
AxisDivByZeroException::AxisDivByZeroException(exception* e)
{
processException (e);
}
AxisDivByZeroException::AxisDivByZeroException(exception* e,int iExceptionCode)
{
processException (e, iExceptionCode);
}
AxisDivByZeroException::~AxisDivByZeroException() throw ()
{
m_sMessage ="";
}
void AxisDivByZeroException:: processException(exception* e, int iExceptionCode)
{
m_sMessage = getMessage (e) + getMessage (iExceptionCode);
}
void AxisDivByZeroException::processException (DivByZeroStruct* pFault)
{
/*User can do something like deserializing the struct into a string*/
int iSize = strlen(pFault->varString) + 8;
char* sMessage = (char*) malloc(iSize);
m_sMessage = (char*) malloc(iSize);
char carrTempBuff[4];
sprintf(carrTempBuff, "%d", pFault->varInt);
strcat(sMessage, carrTempBuff);
strcat(sMessage, "\n");
sprintf(carrTempBuff, "%f", pFault->varFloat);
strcat(sMessage, carrTempBuff);
strcat(sMessage, "\n");
strcat(sMessage, pFault->varString);
strcat(sMessage, "\n");
m_sMessage = sMessage;
free(sMessage);
}
void AxisDivByZeroException::processException(exception* e)
{
m_sMessage = getMessage (e);
}
void AxisDivByZeroException::processException(int iExceptionCode)
{
m_sMessage = getMessage (iExceptionCode);
}
const string AxisDivByZeroException::getMessage (exception* objException)
{
string sMessage = objException->what();
return sMessage;
}
const string AxisDivByZeroException::getMessage (int iExceptionCode)
{
string sMessage;
switch(iExceptionCode)
{
case AXISC_SERVICE_THROWN_EXCEPTION:
sMessage = "A service has thrown an exception. see detail";
break;
default:
sMessage = "Unknown Exception has occured";
}
return sMessage;
}
const char* AxisDivByZeroException::what() throw ()
{
return m_sMessage.c_str ();
}
const int AxisDivByZeroException::getExceptionCode(){
return m_iExceptionCode;
}
1.1 ws-axis/c/tests/client/exceptionTest/AxisDivByZeroException.h
Index: AxisDivByZeroException.h
===================================================================
/*
* This is the Client Stub Class genarated by the tool WSDL2Ws
* AxisDivByZeroException.h: interface for the AxisDivByZeroExceptionclass.
*
*/
#if !defined(__AXISDIVBYZEROEXCEPTION_EXCEPTION_H__INCLUDED_)
#define __AXISDIVBYZEROEXCEPTION_EXCEPTION_H__INCLUDED_
#include <string>
#include <exception>
#include <axis/server/AxisException.h>
#include "DivByZeroStruct.h"
using namespace std;
class AxisDivByZeroException: public AxisException
{
public:
AxisDivByZeroException();
AxisDivByZeroException(DivByZeroStruct* pFault);
AxisDivByZeroException(int iExceptionCode);
AxisDivByZeroException(exception* e);
AxisDivByZeroException(exception* e, int iExceptionCode);
virtual ~AxisDivByZeroException() throw();
const char* what() throw();
const int getExceptionCode();
const string getMessage(exception* e);
const string getMessage(int iExceptionCode);
private:
void processException(exception* e);
void processException(DivByZeroStruct* pFault);
void processException(exception* e, int iExceptionCode);
void processException(int iExceptionCode);
string m_sMessage;
int m_iExceptionCode;
};
#endif /* !defined(__AXISDIVBYZEROEXCEPTION_EXCEPTION_H__INCLUDED_)*/
1.1 ws-axis/c/tests/client/exceptionTest/DivByZeroStruct.cpp
Index: DivByZeroStruct.cpp
===================================================================
/*
*This file is automatically generated by the Axis C++ Wrapper Class Generator
*Web service wrapper class's implementation generated by Axis WCG
*Parameters and wrapper methos to manipulate DivByZeroStruct
*/
#include <malloc.h>
#include "DivByZeroStruct.h"
#include <axis/server/AxisWrapperAPI.h>
/*
* This static method serialize a DivByZeroStruct type of object
*/
int Axis_Serialize_DivByZeroStruct(DivByZeroStruct* param, IWrapperSoapSerializer* pSZ, bool bArray = false)
{
if (bArray)
{
pSZ->serialize("<", Axis_TypeName_DivByZeroStruct, ">", NULL);
}
else
{
const AxisChar* sPrefix = pSZ->getNamespacePrefix(Axis_URI_DivByZeroStruct);
pSZ->serialize("<", Axis_TypeName_DivByZeroStruct, " xsi:type=\"", sPrefix, ":",
Axis_TypeName_DivByZeroStruct, "\" xmlns:", sPrefix, "=\"",
Axis_URI_DivByZeroStruct, "\">", NULL);
}
pSZ->serializeAsElement("varString", (void*)&(param->varString), XSD_STRING);
pSZ->serializeAsElement("varInt", (void*)&(param->varInt), XSD_INT);
pSZ->serializeAsElement("varFloat", (void*)&(param->varFloat), XSD_FLOAT);
pSZ->serialize("</", Axis_TypeName_DivByZeroStruct, ">", NULL);
return AXIS_SUCCESS;
}
/*
* This static method deserialize a DivByZeroStruct type of object
*/
int Axis_DeSerialize_DivByZeroStruct(DivByZeroStruct* param, IWrapperSoapDeSerializer *pIWSDZ)
{
param->varString = pIWSDZ->getElementAsString("varString",0);
param->varInt = pIWSDZ->getElementAsInt("varInt",0);
param->varFloat = pIWSDZ->getElementAsFloat("varFloat",0);
return pIWSDZ->getStatus();
}
void* Axis_Create_DivByZeroStruct(DivByZeroStruct* pObj, bool bArray = false, int nSize=0)
{
if (bArray && (nSize > 0))
{
if (pObj)
{
DivByZeroStruct* pNew = new DivByZeroStruct[nSize];
memcpy(pNew, pObj, sizeof(DivByZeroStruct)*nSize/2);
memset(pObj, 0, sizeof(DivByZeroStruct)*nSize/2);
delete [] pObj;
return pNew;
}
else
{
return new DivByZeroStruct[nSize];
}
}
else
return new DivByZeroStruct;
}
/*
* This static method delete a DivByZeroStruct type of object
*/
void Axis_Delete_DivByZeroStruct(DivByZeroStruct* param, bool bArray = false, int nSize=0)
{
if (bArray)
{
delete [] param;
}
else
{
delete param;
}
}
/*
* This static method gives the size of DivByZeroStruct type of object
*/
int Axis_GetSize_DivByZeroStruct()
{
return sizeof(DivByZeroStruct);
}
DivByZeroStruct::DivByZeroStruct()
{
/*do not allocate memory to any pointer members here
because deserializer will allocate memory anyway. */
}
DivByZeroStruct::~DivByZeroStruct()
{
/*delete any pointer and array members here*/
}
1.1 ws-axis/c/tests/client/exceptionTest/DivByZeroStruct.h
Index: DivByZeroStruct.h
===================================================================
/*
*This file is automatically generated by the Axis C++ Wrapper Class Generator
*Web service wrapper class's implementation generated by Axis WCG
*Parameters and wrapper methos to manipulate DivByZeroStruct
*/
#if !defined(__DIVBYZEROSTRUCT_PARAM_H__INCLUDED_)
#define __DIVBYZEROSTRUCT_PARAM_H__INCLUDED_
#include <axis/server/AxisUserAPI.h>
/*Local name and the URI for the type*/
static const char* Axis_URI_DivByZeroStruct = "http://soapinterop.org/types";
static const char* Axis_TypeName_DivByZeroStruct = "DivByZeroStruct";
class DivByZeroStruct
{
public:
xsd__string varString;
int varInt;
float varFloat;
DivByZeroStruct();
virtual ~DivByZeroStruct();
};
#endif /* !defined(__DIVBYZEROSTRUCT_PARAM_H__INCLUDED_)*/
1.1 ws-axis/c/tests/client/exceptionTest/Makefile.am
Index: Makefile.am
===================================================================
bin_PROGRAMS = mathops
SUBDIRS =
AM_CPPFLAGS = $(CPPFLAGS)
mathops_SOURCES = MathOps.cpp \
MathOpsClient.cpp \
DivByZeroStruct.cpp \
AxisDivByZeroException.cpp
mathops_LDADD = $(LDFLAGS)
INCLUDES = -I$(AXISCPP_HOME)/include
1.1 ws-axis/c/tests/client/exceptionTest/MathOps.cpp
Index: MathOps.cpp
===================================================================
/*
* This is the Client Stub implementation file genarated by WSDL2Ws tool.
* MathOps.cpp: implemtation for the MathOps.
* Default when no parameter passed. When thrown with no parameter
more general MathOps is assumed.
*
*/
#include "MathOps.h"
#include <axis/server/AxisWrapperAPI.h>
using namespace std;
bool CallBase::bInitialized;
CallFunctions CallBase::ms_VFtable;
extern int Axis_DeSerialize_DivByZeroStruct(DivByZeroStruct* param, IWrapperSoapDeSerializer *pDZ);
extern void* Axis_Create_DivByZeroStruct(DivByZeroStruct *Obj, bool bArray = false, int nSize=0);
extern void Axis_Delete_DivByZeroStruct(DivByZeroStruct* param, bool bArray = false, int nSize=0);
extern int Axis_Serialize_DivByZeroStruct(DivByZeroStruct* param, IWrapperSoapSerializer* pSZ, bool bArray = false);
extern int Axis_GetSize_DivByZeroStruct();
MathOps::MathOps(const char* pchEndpointUri)
{
m_pCall = new Call();
m_pCall->setProtocol(APTHTTP);
m_pCall->setEndpointURI(pchEndpointUri);
}
MathOps::~MathOps()
{
delete m_pCall;
}
/*Methods corresponding to the web service methods*/
/*
* This method wrap the service method div
*/
int MathOps::div(int Value0, int Value1)
{
int Ret;
char* cFaultcode;
char* cFaultstring;
char* cFaultactor;
char* cFaultdetail;
try
{
if (AXIS_SUCCESS != m_pCall->initialize(CPP_RPC_PROVIDER, NORMAL_CHANNEL))
return Ret;
m_pCall->setTransportProperty(SOAPACTION_HEADER , "MathOps#div");
m_pCall->setSOAPVersion(SOAP_VER_1_1);
m_pCall->setOperation("div", "http://soapinterop.org/wsdl");
m_pCall->addParameter((void*)&Value0, "int0", XSD_INT);
m_pCall->addParameter((void*)&Value1, "int1", XSD_INT);
if (AXIS_SUCCESS == m_pCall->invoke())
{
if(AXIS_SUCCESS == m_pCall->checkMessage("divResponse", "http://soapinterop.org/wsdl"))
{
Ret = m_pCall->getElementAsInt("addReturn", 0);
}
}
m_pCall->unInitialize();
return Ret;
}
catch(AxisException& e)
{
int iExceptionCode = e.getExceptionCode();
if(AXISC_NODE_VALUE_MISMATCH_EXCEPTION != iExceptionCode)
{
throw;
}
else if (AXIS_SUCCESS == m_pCall->checkFault("Fault","http://localhost/axis/MathOps" ))//Exception handling code goes here
{
cFaultcode = m_pCall->getElementAsString("faultcode", 0);
cFaultstring = m_pCall->getElementAsString("faultstring", 0);
cFaultactor = m_pCall->getElementAsString("faultactor", 0);
if(0 == strcmp("DivByZeroStruct", cFaultstring))
{
if (AXIS_SUCCESS == m_pCall->checkFault("faultdetail","http://localhost/axis/MathOps"))
{
DivByZeroStruct* pFaultDetail = NULL;
pFaultDetail = (DivByZeroStruct*)m_pCall->
getCmplxObject((void*) Axis_DeSerialize_DivByZeroStruct,
(void*) Axis_Create_DivByZeroStruct,
(void*) Axis_Delete_DivByZeroStruct,"faultstruct1", 0);
/*User code to handle the struct can be inserted here*/
char* temp = pFaultDetail->varString;
printf("%s\n", temp);
printf("faultcode:%s\n", cFaultcode);
printf("faultstring:%s\n", cFaultstring);
printf("faultactor:%s\n", cFaultactor);
m_pCall->unInitialize();
throw AxisDivByZeroException(pFaultDetail);
}
}
else
{
cFaultdetail = m_pCall->getElementAsString("faultdetail", 0);
throw AxisException(cFaultdetail);
}
}
else throw;
}
}
int MathOps::getStatus()
{
if ( m_pCall==NULL )
return AXIS_SUCCESS;
else
return m_pCall->getStatus();
}
int MathOps::getFaultDetail(char** ppcDetail)
{
return m_pCall->getFaultDetail(ppcDetail);
}
1.1 ws-axis/c/tests/client/exceptionTest/MathOps.h
Index: MathOps.h
===================================================================
/*
* This is the Client Stub Class genarated by the tool WSDL2Ws
* MathOps.h: interface for the MathOpsclass.
*
*/
#if !defined(__MATHOPS_CLIENTSTUB_H__INCLUDED_)
#define __MATHOPS_CLIENTSTUB_H__INCLUDED_
#include <axis/client/Call.h>
/*include Exception header files here*/
#include "AxisDivByZeroException.h"
#include "DivByZeroStruct.h"
class MathOps
{
private:
Call* m_pCall;
public:
MathOps(const char* pchEndpointUri);
public:
virtual ~MathOps();
public:
int div(int Value0,int Value1);
int getStatus();
int getFaultDetail(char** ppcDetail);
};
#endif /* !defined(__MATHOPS_CLIENTSTUB_H__INCLUDED_)*/
1.1 ws-axis/c/tests/client/exceptionTest/MathOpsClient.cpp
Index: MathOpsClient.cpp
===================================================================
#include "MathOps.h"
#include <axis/server/AxisException.h>
#include <ctype.h>
void PrintUsage();
bool IsNumber(const char* p);
int main(int argc, char* argv[])
{
char endpoint[256];
const char* server="localhost";
const char* port="80";
const char* op = 0;
const char* p1 = 0;
const char* p2 = 0;
int i1=0, i2=0;
int iResult;
char* pcDetail;
if (argc < 6)
{
PrintUsage();
}
else
{
server = argv[1];
port = argv[2];
}
printf("Sending Requests to Server http://%s:%s ........\n\n", server, port);
sprintf(endpoint, "http://%s:%s/axis/MathOps", server, port);
MathOps ws(endpoint);
op = argv[3];
p1 = argv[4];
p2 = argv[5];
if (!IsNumber(p1))
{
printf("Invalid value for first <parameter>\n\n");
PrintUsage();
}
if (!IsNumber(p2))
{
printf("Invalid value for second <parameter>\n\n");
PrintUsage();
}
i1 = atoi(p1);
i2 = atoi(p2);
if (strcmp(op, "div") == 0)
{
try
{
iResult = ws.div(i1, i2);
printf("Result is:%d\n", iResult);
}
catch(AxisDivByZeroException& e)
{
printf("Exception : %s\n", e.what());
}
catch(AxisException& e)
{
printf("Exception : %s\n", e.what());
}
catch(exception& e)
{
}
catch(...)
{
}
}
else
{
printf("Invalid operation %s\n\n", op);
PrintUsage();
}
return 0;
}
void PrintUsage()
{
printf("Usage :\n MathOps <server> <port> <operation> <parameter> <parameter>\n\n");
exit(1);
}
bool IsNumber(const char* p)
{
for (int x=0; x < strlen(p); x++)
{
if (!isdigit(p[x])) return false;
}
return true;
}