axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From susan...@apache.org
Subject cvs commit: xml-axis/c/src/server/samples/cservicewrapper CService.cpp CServiceWrapper.cpp CServiceWrapper.hpp
Date Mon, 01 Sep 2003 13:36:34 GMT
susantha    2003/09/01 06:36:34

  Added:       c/src/server/samples/cservicewrapper CService.cpp
                        CServiceWrapper.cpp CServiceWrapper.hpp
  Log:
  new sample web services
  
  Revision  Changes    Path
  1.1                  xml-axis/c/src/server/samples/cservicewrapper/CService.cpp
  
  Index: CService.cpp
  ===================================================================
  //This file is automatically generated by the Axis C++ Wrapper Class Generator
  //Service file containing the two export functions of the Web service Library
  #ifdef WIN32
  #define STORAGE_CLASS_INFO __declspec(dllexport)
  #else
  #define STORAGE_CLASS_INFO 
  #endif
  
  #include "CServiceWrapper.hpp"
  
  extern "C" {
  
  STORAGE_CLASS_INFO
  int GetClassInstance(BasicHandler **inst)
  {
  	WrapperClassHandler* pWCH = new CServiceWrapper();
  	if (pWCH) 
  	{
  		pWCH->Init();
  		*inst = pWCH;
  		return SUCCESS;
  	}
  	return FAIL;
  }
  STORAGE_CLASS_INFO 
  int DestroyInstance(BasicHandler *inst)
  {
  	if (inst) 
  	{
  		WrapperClassHandler* pWCH = static_cast<WrapperClassHandler*>(inst);
  		pWCH->Fini();
  		delete pWCH;
  		return SUCCESS;
  	}
  	return FAIL;
  }
  }
  
  
  
  1.1                  xml-axis/c/src/server/samples/cservicewrapper/CServiceWrapper.cpp
  
  Index: CServiceWrapper.cpp
  ===================================================================
  //Manually written Wrapper for C web services
  //01 September 2003 by Susantha Kumara (susantha@opensource.lk, skumara@virtusa.com)
  
  #include "CServiceWrapper.hpp"
  #include "Service.h"
  
  extern "C" int AddInt(int a, int b);
  extern "C" double Distance(Point *p1, Point *p2);
  extern "C" Point* AddPoint(Point *p1, Point *p2);
  extern "C" double Perimeter(const Triangle* pTri);
  
  //Parameters and wrapper methos to manipulate Point
  static const AxisChar* Axis_URI_Point = L"http://www.opensource.lk/Point";
  static const AxisChar* Axis_TypeName_Point = L"Point";
  
  int Axis_DeSerialize_Point(Point* p, IWrapperSoapDeSerializer *pDZ)
  {
  	p->x = pDZ->GetParam()->GetInt();
  	p->y = pDZ->GetParam()->GetInt();
  	return SUCCESS;
  }
  
  void Axis_Delete_Point(Point* p, bool bArray = false, int nSize=0)
  {
  	if (bArray)
  		delete [] p;
  	else
  		delete p;
  }
  
  int Axis_Serialize_Point(Point* p, IWrapperSoapSerializer& pSZ, bool bArray = false)
  {
  	if (bArray)
  	{
  		pSZ << "<" << Axis_TypeName_Point << ">";
  	}
  	else
  	{
  		AxisString sPrefix = pSZ.getNewNamespacePrefix();
  		pSZ << "<" << Axis_TypeName_Point << " xsi:type=\"" << sPrefix.c_str()
<<":" 
  			<< Axis_TypeName_Point << " xmlns:" << sPrefix.c_str() << "=\""

  			<< Axis_URI_Point << "\">";
  	}
  	pSZ << pSZ.SerializeBasicType(L"x", p->x);
  	pSZ << pSZ.SerializeBasicType(L"y", p->y);
  	pSZ << "</" << Axis_TypeName_Point << ">";
  	return SUCCESS;
  }
  
  int Axis_GetSize_Point(Point* p)
  {
  	return sizeof(Point);
  }
  
  //Parameters and wrapper methods to manipulate Triangle
  static const AxisChar* Axis_URI_Triangle = L"http://www.opensource.lk/Triangle";
  static const AxisChar* Axis_TypeName_Triangle = L"Triangle";
  
  int Axis_DeSerialize_Triangle(Triangle* p, IWrapperSoapDeSerializer *pDZ)
  {
  	IParam* pParam;
  	pParam = pDZ->GetParam(); //get head param and do any validation if necessary.
  	p->p1 = new Point;
  	Axis_DeSerialize_Point(p->p1, pDZ);
  	pParam = pDZ->GetParam(); //get head param and do any validation if necessary.
  	p->p2 = new Point;
  	Axis_DeSerialize_Point(p->p2, pDZ);
  	pParam = pDZ->GetParam(); //get head param and do any validation if necessary.
  	p->p3 = new Point;
  	Axis_DeSerialize_Point(p->p3, pDZ);
  	return SUCCESS;
  }
  
  void Axis_Delete_Triangle(Triangle* p, bool bArray = false, int nSize=0)
  {
  	if (bArray)
  	{
  		//delete any pointer members of this struct here
  		Triangle* pTemp = p;
  		for (int x=0; x<nSize; x++)
  		{
  			Axis_Delete_Point(pTemp->p1);
  			Axis_Delete_Point(pTemp->p2);
  			Axis_Delete_Point(pTemp->p3);
  			pTemp++;
  		}
  		delete [] p;
  	}
  	else
  	{
  		//delete any pointer members of this struct here
  		Axis_Delete_Point(p->p1);
  		Axis_Delete_Point(p->p2);
  		Axis_Delete_Point(p->p3);
  		delete p;
  	}
  }
  
  int Axis_Serialize_Triangle(Triangle* p, IWrapperSoapSerializer& pSZ, bool bArray =
false)
  {
  	if (bArray)
  	{
  		pSZ << "<" << Axis_TypeName_Triangle << ">";
  	}
  	else
  	{
  		AxisString sPrefix = pSZ.getNewNamespacePrefix();
  		pSZ << "<" << Axis_TypeName_Triangle << " xsi:type=\"" << sPrefix.c_str()
<<":" 
  			<< Axis_TypeName_Triangle << " xmlns:" << sPrefix.c_str() <<
"=\"" 
  			<< Axis_URI_Triangle << "\">";
  	}
  	Axis_Serialize_Point(p->p1, pSZ);
  	Axis_Serialize_Point(p->p1, pSZ);
  	Axis_Serialize_Point(p->p1, pSZ);
  	pSZ << "</" << Axis_TypeName_Triangle << ">";
  	return SUCCESS;
  }
  
  int Axis_GetSize_Triangle(Triangle* p)
  {
  	return sizeof(Triangle);
  }
  
  CServiceWrapper::CServiceWrapper()
  {
  	//does nothing
  }
  
  CServiceWrapper::~CServiceWrapper()
  {
  	//does nothing
  }
  
  // Implementation of WrapperClassHandler interfaces.
  int CServiceWrapper::Invoke(IMessageData* mc)
  {
  	IWrapperSoapDeSerializer* pIWSDZ = NULL;
  	mc->getSoapDeSerializer(&pIWSDZ);
  	if (!pIWSDZ) return FAIL;
  	AxisString method = pIWSDZ->GetMethodName();
  	if (method == L"Distance")
  		return DistanceWrapped(mc);
  	else if (method == L"AddPoint")
  		return AddPointWrapped(mc);
  	else if (method == L"Add")
  		return AddWrapped(mc);
  	else if (method == L"Perimeter")
  		return PerimeterWrapped(mc);
  	else return FAIL;
  }
  
  void CServiceWrapper::OnFault(IMessageData* pMsg)
  {
  }
  
  int CServiceWrapper::Init()
  {
  	return 0;
  }
  
  int CServiceWrapper::Fini()
  {
  	return 0;
  }
  
  int CServiceWrapper::SetResponseMethod(IMessageData* mc, const AxisChar* name)
  {
  	AxisString method = name;
  	IWrapperSoapSerializer* pIWSSZ = NULL;
  	mc->getSoapSerializer(&pIWSSZ);
  	if (!pIWSSZ) return FAIL;
  	ISoapMethod* pMethod = pIWSSZ->createSoapMethod();
  	pMethod->setLocalName(method + L"Response");
  	pMethod->setPrefix(pIWSSZ->getNewNamespacePrefix());
  	pMethod->setUri(L"http://www.opensource.lk/CService");
  	return SUCCESS;
  }
  
  int CServiceWrapper::DistanceWrapped(IMessageData* mc)
  {
  	IWrapperSoapSerializer* pIWSSZ = NULL;
  	mc->getSoapSerializer(&pIWSSZ);
  	if (!pIWSSZ) return FAIL;
  	IWrapperSoapDeSerializer* pIWSDZ = NULL;
  	mc->getSoapDeSerializer(&pIWSDZ);
  	if (!pIWSDZ) return FAIL;
  	SetResponseMethod(mc, L"Distance");
  
  	IParam *param0 = pIWSDZ->GetParam();
  	Point* v0 = new Point();
  
  	param0->SetUserType(v0, (AXIS_DESERIALIZE_FUNCT)Axis_DeSerialize_Point, (AXIS_OBJECT_DELETE_FUNCT)Axis_Delete_Point);
  	pIWSDZ->Deserialize(param0,0);
  
  	IParam *param1 = pIWSDZ->GetParam();
  	Point* v1 = new Point();
  
  	param1->SetUserType(v1, (AXIS_DESERIALIZE_FUNCT)Axis_DeSerialize_Point, (AXIS_OBJECT_DELETE_FUNCT)Axis_Delete_Point);
  	pIWSDZ->Deserialize(param1,0);
  
  	//Call actual web service method with appropriate parameters
  	double ret = Distance(v0, v1);
  
  	uParamValue value;
  	value.dValue = ret;
  	IParam* pRetParam = pIWSSZ->setResponseParam(XSD_DOUBLE, value);
  	pRetParam->SetName(L"DistanceReturn");
  	return SUCCESS;
  }
  
  int CServiceWrapper::AddPointWrapped(IMessageData* mc)
  {
  	IWrapperSoapSerializer* pIWSSZ = NULL;
  	mc->getSoapSerializer(&pIWSSZ);
  	if (!pIWSSZ) return FAIL;
  	IWrapperSoapDeSerializer* pIWSDZ = NULL;
  	mc->getSoapDeSerializer(&pIWSDZ);
  	if (!pIWSDZ) return FAIL;
  	SetResponseMethod(mc, L"AddPoint");
  
  	IParam *param0 = pIWSDZ->GetParam();
  	Point* v0 = new Point();
  
  	param0->SetUserType(v0, (AXIS_DESERIALIZE_FUNCT)Axis_DeSerialize_Point, (AXIS_OBJECT_DELETE_FUNCT)Axis_Delete_Point);
  	pIWSDZ->Deserialize(param0,0);
  
  	IParam *param1 = pIWSDZ->GetParam();
  	Point* v1 = new Point();
  
  	param1->SetUserType(v1, (AXIS_DESERIALIZE_FUNCT)Axis_DeSerialize_Point, (AXIS_OBJECT_DELETE_FUNCT)Axis_Delete_Point);
  	pIWSDZ->Deserialize(param1,0);
  
  	//Call actual web service method with appropriate parameters
  	Point* ret = AddPoint(v0, v1);
  
  	IParam* pRetParam = pIWSSZ->setResponseParam(ret, (AXIS_SERIALIZE_FUNCT)Axis_Serialize_Point,
(AXIS_OBJECT_DELETE_FUNCT)Axis_Delete_Point);
  	pRetParam->SetName(L"AddPointReturn");
  	return SUCCESS;
  }
  
  int CServiceWrapper::AddWrapped(IMessageData* mc)
  {
  	IWrapperSoapSerializer* pIWSSZ = NULL;
  	mc->getSoapSerializer(&pIWSSZ);
  	if (!pIWSSZ) return FAIL;
  	IWrapperSoapDeSerializer* pIWSDZ = NULL;
  	mc->getSoapDeSerializer(&pIWSDZ);
  	if (!pIWSDZ) return FAIL;
  	SetResponseMethod(mc, L"Add");
  
  	IParam *param0 = pIWSDZ->GetParam();
  	int v0 = param0->GetInt();
  
  	IParam *param1 = pIWSDZ->GetParam();
  	int v1 = param1->GetInt();
  
  	//Call actual web service method with appropriate parameters
  	int ret = AddInt(v0, v1);
  
  	uParamValue value;
  	value.nValue = ret;
  	IParam* pRetParam = pIWSSZ->setResponseParam(XSD_INT, value);
  	pRetParam->SetName(L"AddReturn");
  	return SUCCESS;
  }
  
  int CServiceWrapper::PerimeterWrapped(IMessageData* mc)
  {
  	IWrapperSoapSerializer* pIWSSZ = NULL;
  	mc->getSoapSerializer(&pIWSSZ);
  	if (!pIWSSZ) return FAIL;
  	IWrapperSoapDeSerializer* pIWSDZ = NULL;
  	mc->getSoapDeSerializer(&pIWSDZ);
  	if (!pIWSDZ) return FAIL;
  	SetResponseMethod(mc, L"Perimeter");
  
  	IParam *param0 = pIWSDZ->GetParam();
  	Triangle* v0 = new Triangle();
  
  	param0->SetUserType(v0, (AXIS_DESERIALIZE_FUNCT)Axis_DeSerialize_Triangle, (AXIS_OBJECT_DELETE_FUNCT)Axis_Delete_Triangle);
  	pIWSDZ->Deserialize(param0,0);
  
  	//Call actual web service method with appropriate parameters
  	double ret = Perimeter(v0);
  
  	uParamValue value;
  	value.dValue = ret;
  	IParam* pRetParam = pIWSSZ->setResponseParam(XSD_DOUBLE, value);
  	pRetParam->SetName(L"PerimeterReturn");
  	return SUCCESS;
  }
  
  
  
  1.1                  xml-axis/c/src/server/samples/cservicewrapper/CServiceWrapper.hpp
  
  Index: CServiceWrapper.hpp
  ===================================================================
  #if !defined __WRAPPER_CLASS_CSERVICEWRAPPER_INCLUDED__
  #define __WRAPPER_CLASS_CSERVICEWRAPPER_INCLUDED__
  
  #include <WrapperClassHandler.h>
  #include <IMessageData.h>
  #include <GDefine.h>
  #include <IWrapperSoapDeSerializer.h>
  #include <IWrapperSoapSerializer.h>
  #include <ISoapMethod.h>
  #include <IParam.h>
  #include <string>
  using namespace std;
  
  class CServiceWrapper : public WrapperClassHandler
  {
  public:
  	CServiceWrapper();
  	virtual ~CServiceWrapper();
  public://implementation of WrapperClassHandler interface
  	int Invoke(IMessageData* mc);
  	void OnFault(IMessageData* pMsg);
  	int Init();
  	int Fini();
  private://Methods corresponding to the web service methods
  	int SetResponseMethod(IMessageData* mc, const AxisChar* name);
  	int DistanceWrapped(IMessageData* mc);
  	int AddPointWrapped(IMessageData* mc);
  	int AddWrapped(IMessageData* mc);
  	int PerimeterWrapped(IMessageData* mc);
  };
  
  #endif //__WRAPPER_CLASS_CSERVICEWRAPPER_INCLUDED__
  
  
  

Mime
View raw message