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/03/24 13:48:41 UTC
cvs commit: ws-axis/c/src/engine/server Axis.cpp ServerAxisEngine.cpp
damitha 2004/03/24 04:48:41
Modified: c/src/engine Makefile.am
Added: c/src/engine/client Axis.cpp ClientAxisEngine.cpp
c/src/engine/server Axis.cpp ServerAxisEngine.cpp
Removed: c/src/engine ClientAxisEngine.cpp ServerAxisEngine.cpp
Log:
Revision Changes Path
1.11 +1 -19 ws-axis/c/src/engine/Makefile.am
Index: Makefile.am
===================================================================
RCS file: /home/cvs/ws-axis/c/src/engine/Makefile.am,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Makefile.am 10 Mar 2004 07:04:59 -0000 1.10
+++ Makefile.am 24 Mar 2004 12:48:41 -0000 1.11
@@ -1,19 +1 @@
-noinst_LTLIBRARIES = libengine.la
-AM_CPPFLAGS = -Wall -DUSE_EXPAT_PARSER -DUSE_LTDL
-libengine_la_SOURCES = Axis.cpp \
- AxisEngine.cpp \
- ServerAxisEngine.cpp \
- ClientAxisEngine.cpp \
- HandlerChain.cpp \
- HandlerLoader.cpp \
- HandlerPool.cpp \
- AppScopeHandlerPool.cpp \
- DeserializerPool.cpp \
- RequestScopeHandlerPool.cpp \
- SerializerPool.cpp \
- SessionScopeHandlerPool.cpp \
- SharedObject.cpp
-
-
-libengine_la_LIBADD = -L$(AXISCPP_HOME)/lib/expat -lexpat -lstdc++ -L$(AXISCPP_HOME)/lib/axis -laxiscpp_client
-INCLUDES = -I$(AXISCPP_HOME)/include
+SUBDIRS = server client
1.1 ws-axis/c/src/engine/client/Axis.cpp
Index: Axis.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*
*
* @author Sanjaya Sinharage (sanjayasing@opensource.lk)
* @author Susantha Kumara (skumara@virtusa.com)
*
*/
#ifdef WIN32
#pragma warning (disable : 4503)
#endif
#ifdef WIN32
#include <Windows.h> //for Sleep(0);
#else
#include <unistd.h>
#endif
#include "../server/ServerAxisEngine.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <axis/server/Packet.h>
#include <string>
#include <map>
#include <axis/server/SoapFault.h>
#include "../../soap/URIMapping.h"
#include "../../soap/SoapKeywordMapping.h"
#include "../HandlerLoader.h"
#include "../AppScopeHandlerPool.h"
#include "../RequestScopeHandlerPool.h"
#include "../SessionScopeHandlerPool.h"
#include "../HandlerPool.h"
#include "../SerializerPool.h"
#include "../DeserializerPool.h"
#include "../../wsdd/WSDDDeployment.h"
#include "../../common/AxisUtils.h"
#include <axis/server/AxisConfig.h>
#include "../../wsdd/WSDDKeywords.h"
#include <axis/server/AxisTrace.h>
#include <axis/client/Call.h>
#define BYTESTOREAD 64
//the relative location of the wsdl files hardcoded
#define WSDLDIRECTORY "/wsdls/"
//define all global variables of the axisengine
#ifdef _AXISTRACE
unsigned char chEBuf[1024];
#endif
//synchronized global variables.
HandlerLoader* g_pHandlerLoader;
AppScopeHandlerPool* g_pAppScopeHandlerPool;
RequestScopeHandlerPool* g_pRequestScopeHandlerPool;
SessionScopeHandlerPool* g_pSessionScopeHandlerPool;
DeserializerPool* g_pDeserializerPool;
SerializerPool* g_pSerializerPool;
HandlerPool* g_pHandlerPool;
//un synchronized read-only global variables.
WSDDDeployment* g_pWSDDDeployment;
AxisConfig* g_pConfig;
AxisTrace* g_pAT;
extern "C" int process_request(Ax_soapstream *stream)
{
int Status = AXIS_FAIL;
FILE * WsddFile;
char ReadBuffer[BYTESTOREAD];
ReadBuffer[0] = '\0';
const WSDDServiceMap* pSrvMap = NULL;
WSDDServiceMap::const_iterator iter;
WSDDService* pService = NULL;
/* If there is no send function given in the Ax_soapstream struct */
if (!stream->transport.pSendFunct) return AXIS_FAIL;
switch (stream->trtype)
{
case APTHTTP:
//Handle the POST method
if (stream->so.http->ip_method == AXIS_HTTP_POST)
{
AxisEngine* engine = new ServerAxisEngine();
if (engine)
{
if (AXIS_SUCCESS == engine->Initialize())
{
Status = engine->Process(stream);
}
delete engine;
}
}
//Handler the GET method
else if (stream->so.http->ip_method == AXIS_HTTP_GET)
{
//get the uri path
//i.e "/abc/xyz/" part of http://somehost/abc/xyz/
string sUriWOAxis = stream->transport.pGetTrtFunct(SERVICE_URI, stream);
string sServiceName;
bool bNoExt = true;
if (sUriWOAxis == "/" )
{
bNoExt = false;
sUriWOAxis = "";
}
if (sUriWOAxis.empty())
{
pSrvMap = g_pWSDDDeployment->GetWSDDServiceMap();
if (!pSrvMap)
{
stream->transport.pSendFunct("<html><body>\
<h1 align=\"center\">Welcome to Axis C++</h1>\
<br>\
<h2>Deployment Descripter Not Found</h2>\
<br>\
</body></html>", NULL, stream);
return AXIS_FAIL;
}
stream->transport.pSendFunct("<html><body>\
<h1 align=\"center\">Welcome to Axis C++</h1>\
<br>\
<h2 align=\"center\">List of Deployed Web services<br></h2>\
<table width=\"100%\" border=1 align=\"center\"><tbody>", NULL, stream);
stream->transport.pSendFunct("<tr><td width=\"20%\"><b>Web Service</b></td>\
<td width=\"10%\" align=\"left\"><b>WSDL</b></td>\
<td width=\"70%\"><b>Description</b></td></tr>", NULL, stream);
for (iter = pSrvMap->begin();iter != pSrvMap->end();iter++)
{
pService = (*iter).second;
stream->transport.pSendFunct("<tr><td width=\"20%\">", NULL, stream);
stream->transport.pSendFunct((char *)pService->GetServiceName(), NULL, stream);
stream->transport.pSendFunct("</td><td width=\"10%\" align=\"left\"><a href=\"./", NULL, stream);
if (bNoExt) stream->transport.pSendFunct("axis/", NULL, stream);
stream->transport.pSendFunct((char *)pService->GetServiceName(), NULL, stream);
stream->transport.pSendFunct("?wsdl", NULL, stream);
stream->transport.pSendFunct("\">wsdl</a></td><td width=\"70%\">", NULL, stream);
stream->transport.pSendFunct((char *)pService->GetDescription(), NULL, stream);
stream->transport.pSendFunct("</td></tr>", NULL, stream);
}
stream->transport.pSendFunct("</tbody></table>", NULL, stream);
stream->transport.pSendFunct("<br><p align=\"center\">Copyright � 2001-2003 The Apache Software Foundation<br></p></body></html>", NULL, stream);
Status = AXIS_SUCCESS;
}
else
{
sServiceName = g_pConfig->GetAxisHomePath();
sServiceName += WSDLDIRECTORY + sUriWOAxis + ".wsdl";
//check whether wsdl file is available
if((WsddFile = fopen(sServiceName.c_str(),"r"))==NULL)
{
stream->transport.pSendFunct("<h3>Url not available</h3>", NULL, stream);
Status = AXIS_SUCCESS;
//handle the error
}
else
{
int charcount = 0;
while((charcount = fread(ReadBuffer, 1, BYTESTOREAD-1, WsddFile)) != 0)
{
*(ReadBuffer + charcount) = '\0';
stream->transport.pSendFunct(ReadBuffer, NULL, stream);
}
Status = AXIS_SUCCESS;
fclose(WsddFile);
}
}
}
break;
default:
stream->transport.pSendFunct("Unknown Protocol", NULL, stream);
break;
}
return Status;
}
extern "C" int initialize_module(int bServer)
{
int status = 0;
//order of these initialization method invocation should not be changed
//XMLPlatformUtils::Initialize();
AxisEngine::m_bServer = bServer;
AxisUtils::Initialize();
WSDDKeywords::Initialize();
SoapKeywordMapping::Initialize();
TypeMapping::Initialize();
URIMapping::Initialize();
SoapFault::initialize();
CallBase::s_Initialize();
IWrapperSoapDeSerializer::s_Initialize();
IWrapperSoapSerializer::s_Initialize();
IMessageData::s_Initialize();
ModuleInitialize();
if (bServer) //no client side wsdd processing at the moment
{
int status = g_pConfig->ReadConfFile();/*Read from the configuration file*/
if(status == AXIS_SUCCESS)
{
char* pWsddPath = g_pConfig->GetWsddFilePath();
if (AXIS_SUCCESS != g_pWSDDDeployment->LoadWSDD(pWsddPath)) return AXIS_FAIL;
#if defined(__AXISTRACE__)
status = g_pAT->openFile();
if(status == AXIS_FAIL)
{
return AXIS_FAIL;
}
#endif
}
else
{
AXISTRACE1("Reading from the configuration file failed. " \
"Check for error in the configuration file", CRITICAL);
/*TODO:Improve the AxisTrace so that it will log
these kind of messages into a log file according to the
critical level specified.
*/
return AXIS_FAIL;
}
}
else if(bServer == 0)//client side module initialization
{
#if defined(__AXISTRACE__)
status = g_pAT->openFileByClient();
if(status == AXIS_FAIL)
{
return AXIS_FAIL;
}
#endif
}
return AXIS_SUCCESS;
}
extern "C" int uninitialize_module()
{
//XMLPlatformUtils::Terminate();
ModuleUnInitialize();
return AXIS_SUCCESS;
}
void Ax_Sleep(int nTime)
{
#ifdef WIN32
Sleep(0);
#else
sleep(0);
#endif
}
void ModuleInitialize()
{
//synchronized global variables.
g_pHandlerLoader = new HandlerLoader();
g_pAppScopeHandlerPool = new AppScopeHandlerPool();
g_pRequestScopeHandlerPool = new RequestScopeHandlerPool();
g_pSessionScopeHandlerPool = new SessionScopeHandlerPool();
g_pDeserializerPool = new DeserializerPool();
g_pSerializerPool = new SerializerPool();
g_pHandlerPool = new HandlerPool();
//un synchronized read-only global variables.
g_pWSDDDeployment = new WSDDDeployment();
g_pConfig = new AxisConfig();
g_pAT = new AxisTrace();
}
void ModuleUnInitialize()
{
//synchronized global variables.
delete g_pAppScopeHandlerPool;
delete g_pRequestScopeHandlerPool;
delete g_pSessionScopeHandlerPool;
delete g_pHandlerLoader;
delete g_pDeserializerPool;
delete g_pSerializerPool;
delete g_pHandlerPool;
//un synchronized read-only global variables.
delete g_pWSDDDeployment;
delete g_pConfig;
delete g_pAT;
}
1.1 ws-axis/c/src/engine/client/ClientAxisEngine.cpp
Index: ClientAxisEngine.cpp
===================================================================
// ClientAxisEngine.cpp: implementation of the ClientAxisEngine class.
//
//////////////////////////////////////////////////////////////////////
#include <axis/server/ClientAxisEngine.h>
#include "../../wsdd/WSDDDeployment.h"
#include "../HandlerPool.h"
#include <axis/server/AxisTrace.h>
extern AxisTrace* g_pAT;
extern WSDDDeployment* g_pWSDDDeployment;
extern HandlerPool* g_pHandlerPool;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ClientAxisEngine::ClientAxisEngine()
{
}
ClientAxisEngine::~ClientAxisEngine()
{
}
MessageData* ClientAxisEngine::GetMessageData()
{
return m_pMsgData;
}
int ClientAxisEngine::Process(Ax_soapstream* pSoap)
{
int Status;
//const WSDDService* pService = NULL;
if (!pSoap)
{
AXISTRACE1("Ax_soapstream is null", CRITICAL);
return AXIS_FAIL;
}
m_pSoap = pSoap;
string sSessionId = m_pSoap->sessionid;
if (!(m_pSoap->transport.pSendFunct && m_pSoap->transport.pGetFunct &&
m_pSoap->transport.pSetTrtFunct && m_pSoap->transport.pGetTrtFunct))
{
AXISTRACE1("transport is not set properly", CRITICAL);
return AXIS_FAIL;
}
do {
//const char* cService = get_header(soap, SOAPACTIONHEADER);
/*
//Get Global and Transport Handlers
if(AXIS_SUCCESS != (Status = InitializeHandlers(sSessionId, soap->trtype)))
{
break; //do .. while(0)
}
//Get Service specific Handlers from the pool if configured any
if(AXIS_SUCCESS != (Status = g_pHandlerPool->GetRequestFlowHandlerChain(&m_pSReqFChain, sSessionId, pService)))
{
break; //do .. while(0)
}
if(AXIS_SUCCESS != (Status = g_pHandlerPool->GetResponseFlowHandlerChain(&m_pSResFChain, sSessionId, pService)))
{
break; //do .. while(0)
}
*/
//Invoke all handlers and then the remote webservice
Status = Invoke(m_pMsgData); //we generate response in the same way even if this has failed
}
while(0);
//Pool back the Service specific handlers
//if (m_pSReqFChain) g_pHandlerPool->PoolHandlerChain(m_pSReqFChain, sSessionId);
//if (m_pSResFChain) g_pHandlerPool->PoolHandlerChain(m_pSResFChain, sSessionId);
//Pool back the Global and Transport handlers
//UnInitializeHandlers(sSessionId, soap->trtype);
return Status;
}
int ClientAxisEngine::Invoke(MessageData* pMsg)
{
enum AE_LEVEL {AE_START=1, AE_TRH, AE_GLH, AE_SERH, AE_SERV};
int Status = AXIS_FAIL;
//int level = AE_START;
/*
No Client side handlers for now. Therefore returns AXIS_SUCCESS
*/
Status = AXIS_SUCCESS;
/*
do
{
//invoke client side service specific request handlers
if (m_pSReqFChain)
{
if(AXIS_SUCCESS != (Status = m_pSReqFChain->Invoke(pMsg)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_CLIENTHANDLERFAILED));
break; //do .. while (0)
}
}
// AXISTRACE1("AFTER invoke service specific request handlers");
level++; //AE_SERH //invoke transport request handlers
//invoke global request handlers
if (m_pGReqFChain)
{
if(AXIS_SUCCESS != (Status = m_pGReqFChain->Invoke(pMsg)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_CLIENTHANDLERFAILED));
break; //do .. while (0)
}
}
// AXISTRACE1("AFTER invoke global request handlers");
level++; //AE_GLH
if (m_pTReqFChain) {
if(AXIS_SUCCESS != (Status = m_pTReqFChain->Invoke(pMsg)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_CLIENTHANDLERFAILED));
break; //do .. while (0)
}
}
// AXISTRACE1("AFTER invoke transport request handlers");
level++; // AE_TRH
}
while(0);
*/
do
{
if (AXIS_SUCCESS != (Status = m_pSZ->SetOutputStream(m_pSoap))) break;
m_pSZ->MarkEndOfStream();
pMsg->setPastPivotState(true);
if (AXIS_SUCCESS != (Status = m_pDZ->SetInputStream(m_pSoap))) break;
}
while(0);
int nSoapVersion = m_pDZ->GetVersion();
if (nSoapVersion == VERSION_LAST) /* version not supported */
{
Status = AXIS_FAIL;
//return AXIS_FAIL;
}
m_pDZ->GetHeader();
/*
switch (level)
{
case AE_SERV: //everything success
Status = AXIS_SUCCESS;
//no break;
case AE_SERH: //actual web service handler has failed
//invoke web service specific response handlers
if (m_pSResFChain)
{
m_pSResFChain->Invoke(pMsg);
}
//no break;
case AE_GLH: //web service specific handlers have failed
//invoke global response handlers
if (m_pGResFChain)
{
m_pGResFChain->Invoke(pMsg);
}
//no break;
case AE_TRH: //global handlers have failed
if (m_pTResFChain)
{
m_pTResFChain->Invoke(pMsg);
}
//no break;
case AE_START:;//transport handlers have failed
};
*/
// AXISTRACE1("end axisengine process()");
return Status;
}
void ClientAxisEngine::OnFault(MessageData* pMsg)
{
}
1.1 ws-axis/c/src/engine/server/Axis.cpp
Index: Axis.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "SOAP" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*
*
* @author Sanjaya Sinharage (sanjayasing@opensource.lk)
* @author Susantha Kumara (skumara@virtusa.com)
*
*/
#ifdef WIN32
#pragma warning (disable : 4503)
#endif
#ifdef WIN32
#include <Windows.h> //for Sleep(0);
#else
#include <unistd.h>
#endif
#include "ServerAxisEngine.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <axis/server/Packet.h>
#include <string>
#include <map>
#include <axis/server/SoapFault.h>
#include "../../soap/URIMapping.h"
#include "../../soap/SoapKeywordMapping.h"
#include "../HandlerLoader.h"
#include "../AppScopeHandlerPool.h"
#include "../RequestScopeHandlerPool.h"
#include "../SessionScopeHandlerPool.h"
#include "../HandlerPool.h"
#include "../SerializerPool.h"
#include "../DeserializerPool.h"
#include "../../wsdd/WSDDDeployment.h"
#include "../../common/AxisUtils.h"
#include <axis/server/AxisConfig.h>
#include "../../wsdd/WSDDKeywords.h"
#include <axis/server/AxisTrace.h>
#include <axis/client/Call.h>
#define BYTESTOREAD 64
//the relative location of the wsdl files hardcoded
#define WSDLDIRECTORY "/wsdls/"
//define all global variables of the axisengine
#ifdef _AXISTRACE
unsigned char chEBuf[1024];
#endif
//synchronized global variables.
HandlerLoader* g_pHandlerLoader;
AppScopeHandlerPool* g_pAppScopeHandlerPool;
RequestScopeHandlerPool* g_pRequestScopeHandlerPool;
SessionScopeHandlerPool* g_pSessionScopeHandlerPool;
DeserializerPool* g_pDeserializerPool;
SerializerPool* g_pSerializerPool;
HandlerPool* g_pHandlerPool;
//un synchronized read-only global variables.
WSDDDeployment* g_pWSDDDeployment;
AxisConfig* g_pConfig;
AxisTrace* g_pAT;
extern "C" int process_request(Ax_soapstream *stream)
{
int Status = AXIS_FAIL;
FILE * WsddFile;
char ReadBuffer[BYTESTOREAD];
ReadBuffer[0] = '\0';
const WSDDServiceMap* pSrvMap = NULL;
WSDDServiceMap::const_iterator iter;
WSDDService* pService = NULL;
/* If there is no send function given in the Ax_soapstream struct */
if (!stream->transport.pSendFunct) return AXIS_FAIL;
switch (stream->trtype)
{
case APTHTTP:
//Handle the POST method
if (stream->so.http->ip_method == AXIS_HTTP_POST)
{
AxisEngine* engine = new ServerAxisEngine();
if (engine)
{
if (AXIS_SUCCESS == engine->Initialize())
{
Status = engine->Process(stream);
}
delete engine;
}
}
//Handler the GET method
else if (stream->so.http->ip_method == AXIS_HTTP_GET)
{
//get the uri path
//i.e "/abc/xyz/" part of http://somehost/abc/xyz/
string sUriWOAxis = stream->transport.pGetTrtFunct(SERVICE_URI, stream);
string sServiceName;
bool bNoExt = true;
if (sUriWOAxis == "/" )
{
bNoExt = false;
sUriWOAxis = "";
}
if (sUriWOAxis.empty())
{
pSrvMap = g_pWSDDDeployment->GetWSDDServiceMap();
if (!pSrvMap)
{
stream->transport.pSendFunct("<html><body>\
<h1 align=\"center\">Welcome to Axis C++</h1>\
<br>\
<h2>Deployment Descripter Not Found</h2>\
<br>\
</body></html>", NULL, stream);
return AXIS_FAIL;
}
stream->transport.pSendFunct("<html><body>\
<h1 align=\"center\">Welcome to Axis C++</h1>\
<br>\
<h2 align=\"center\">List of Deployed Web services<br></h2>\
<table width=\"100%\" border=1 align=\"center\"><tbody>", NULL, stream);
stream->transport.pSendFunct("<tr><td width=\"20%\"><b>Web Service</b></td>\
<td width=\"10%\" align=\"left\"><b>WSDL</b></td>\
<td width=\"70%\"><b>Description</b></td></tr>", NULL, stream);
for (iter = pSrvMap->begin();iter != pSrvMap->end();iter++)
{
pService = (*iter).second;
stream->transport.pSendFunct("<tr><td width=\"20%\">", NULL, stream);
stream->transport.pSendFunct((char *)pService->GetServiceName(), NULL, stream);
stream->transport.pSendFunct("</td><td width=\"10%\" align=\"left\"><a href=\"./", NULL, stream);
if (bNoExt) stream->transport.pSendFunct("axis/", NULL, stream);
stream->transport.pSendFunct((char *)pService->GetServiceName(), NULL, stream);
stream->transport.pSendFunct("?wsdl", NULL, stream);
stream->transport.pSendFunct("\">wsdl</a></td><td width=\"70%\">", NULL, stream);
stream->transport.pSendFunct((char *)pService->GetDescription(), NULL, stream);
stream->transport.pSendFunct("</td></tr>", NULL, stream);
}
stream->transport.pSendFunct("</tbody></table>", NULL, stream);
stream->transport.pSendFunct("<br><p align=\"center\">Copyright � 2001-2003 The Apache Software Foundation<br></p></body></html>", NULL, stream);
Status = AXIS_SUCCESS;
}
else
{
sServiceName = g_pConfig->GetAxisHomePath();
sServiceName += WSDLDIRECTORY + sUriWOAxis + ".wsdl";
//check whether wsdl file is available
if((WsddFile = fopen(sServiceName.c_str(),"r"))==NULL)
{
stream->transport.pSendFunct("<h3>Url not available</h3>", NULL, stream);
Status = AXIS_SUCCESS;
//handle the error
}
else
{
int charcount = 0;
while((charcount = fread(ReadBuffer, 1, BYTESTOREAD-1, WsddFile)) != 0)
{
*(ReadBuffer + charcount) = '\0';
stream->transport.pSendFunct(ReadBuffer, NULL, stream);
}
Status = AXIS_SUCCESS;
fclose(WsddFile);
}
}
}
break;
default:
stream->transport.pSendFunct("Unknown Protocol", NULL, stream);
break;
}
return Status;
}
extern "C" int initialize_module(int bServer)
{
int status = 0;
//order of these initialization method invocation should not be changed
//XMLPlatformUtils::Initialize();
AxisEngine::m_bServer = bServer;
AxisUtils::Initialize();
WSDDKeywords::Initialize();
SoapKeywordMapping::Initialize();
TypeMapping::Initialize();
URIMapping::Initialize();
SoapFault::initialize();
//CallBase::s_Initialize();
IWrapperSoapDeSerializer::s_Initialize();
IWrapperSoapSerializer::s_Initialize();
IMessageData::s_Initialize();
ModuleInitialize();
if (bServer) //no client side wsdd processing at the moment
{
int status = g_pConfig->ReadConfFile();/*Read from the configuration file*/
if(status == AXIS_SUCCESS)
{
char* pWsddPath = g_pConfig->GetWsddFilePath();
if (AXIS_SUCCESS != g_pWSDDDeployment->LoadWSDD(pWsddPath)) return AXIS_FAIL;
#if defined(__AXISTRACE__)
status = g_pAT->openFile();
if(status == AXIS_FAIL)
{
return AXIS_FAIL;
}
#endif
}
else
{
AXISTRACE1("Reading from the configuration file failed. " \
"Check for error in the configuration file", CRITICAL);
/*TODO:Improve the AxisTrace so that it will log
these kind of messages into a log file according to the
critical level specified.
*/
return AXIS_FAIL;
}
}
else if(bServer == 0)//client side module initialization
{
#if defined(__AXISTRACE__)
status = g_pAT->openFileByClient();
if(status == AXIS_FAIL)
{
return AXIS_FAIL;
}
#endif
}
return AXIS_SUCCESS;
}
extern "C" int uninitialize_module()
{
//XMLPlatformUtils::Terminate();
ModuleUnInitialize();
return AXIS_SUCCESS;
}
void Ax_Sleep(int nTime)
{
#ifdef WIN32
Sleep(0);
#else
sleep(0);
#endif
}
void ModuleInitialize()
{
//synchronized global variables.
g_pHandlerLoader = new HandlerLoader();
g_pAppScopeHandlerPool = new AppScopeHandlerPool();
g_pRequestScopeHandlerPool = new RequestScopeHandlerPool();
g_pSessionScopeHandlerPool = new SessionScopeHandlerPool();
g_pDeserializerPool = new DeserializerPool();
g_pSerializerPool = new SerializerPool();
g_pHandlerPool = new HandlerPool();
//un synchronized read-only global variables.
g_pWSDDDeployment = new WSDDDeployment();
g_pConfig = new AxisConfig();
g_pAT = new AxisTrace();
}
void ModuleUnInitialize()
{
//synchronized global variables.
delete g_pAppScopeHandlerPool;
delete g_pRequestScopeHandlerPool;
delete g_pSessionScopeHandlerPool;
delete g_pHandlerLoader;
delete g_pDeserializerPool;
delete g_pSerializerPool;
delete g_pHandlerPool;
//un synchronized read-only global variables.
delete g_pWSDDDeployment;
delete g_pConfig;
delete g_pAT;
}
1.1 ws-axis/c/src/engine/server/ServerAxisEngine.cpp
Index: ServerAxisEngine.cpp
===================================================================
// ServerAxisEngine.cpp: implementation of the ServerAxisEngine class.
//
//////////////////////////////////////////////////////////////////////
#include "../../soap/SoapBody.h"
#include "../../soap/SoapMethod.h"
#include "ServerAxisEngine.h"
#include <stdio.h>
#include <axis/server/AxisException.h>
#include "../../common/AxisUtils.h"
#include "../../wsdd/WSDDDeployment.h"
#include "../HandlerPool.h"
#include <axis/server/AxisTrace.h>
extern AxisTrace* g_pAT;
extern HandlerPool* g_pHandlerPool;
extern WSDDDeployment* g_pWSDDDeployment;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ServerAxisEngine::ServerAxisEngine()
{
m_pWebService = NULL;
}
ServerAxisEngine::~ServerAxisEngine()
{
}
int ServerAxisEngine::Process(Ax_soapstream* stream)
{
int Status = 0;
/*AXIS_TRY*/
const WSDDService* pService = NULL;
string sSessionId = stream->sessionid;
int nSoapVersion;
if (!(stream->transport.pSendFunct && stream->transport.pGetFunct &&
stream->transport.pSetTrtFunct && stream->transport.pGetTrtFunct))
{
AXISTRACE1("transport is not set properly", CRITICAL);
return AXIS_FAIL;
}
/*
* after this point we should return AXIS_SUCCESS. Otherwise the transport layer
* may not send the response back (either soap fault or result).
*/
do {
/* populate MessageData with transport information */
m_pMsgData->m_Protocol = stream->trtype;
if (AXIS_SUCCESS != m_pDZ->SetInputStream(stream))
{
nSoapVersion = m_pDZ->GetVersion();
nSoapVersion = (nSoapVersion == VERSION_LAST) ? SOAP_VER_1_2 : nSoapVersion;
m_pSZ->setSoapVersion((SOAP_VERSION)nSoapVersion);
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SOAPCONTENTERROR));
break; //do .. while(0)
}
const char* cService = stream->transport.pGetTrtFunct(SERVICE_URI, stream);
if (!cService)
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SOAPCONTENTERROR));
break; //do .. while(0)
}
AxisString service = (cService == NULL)? "" : cService;
if (service.empty())
{
nSoapVersion = m_pMsgData->m_pDZ->GetVersion();
nSoapVersion = (nSoapVersion == VERSION_LAST) ? SOAP_VER_1_2 : nSoapVersion;
m_pSZ->setSoapVersion((SOAP_VERSION)nSoapVersion);
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SOAPACTIONEMPTY));
break; //do .. while(0)
}
/* if there are quotes remove them. */
if (service.find('\"') != string::npos)
{
service = service.substr(1, service.length() - 2);
}
/* get service description object from the WSDD Deployment object */
pService = g_pWSDDDeployment->GetService(service.c_str());
if (!pService)
{
nSoapVersion = m_pMsgData->m_pDZ->GetVersion();
nSoapVersion = (nSoapVersion == VERSION_LAST) ? SOAP_VER_1_2 : nSoapVersion;
m_pSZ->setSoapVersion((SOAP_VERSION)nSoapVersion);
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SERVICENOTFOUND));
break; //do .. while(0)
}
m_pMsgData->SetService(pService);
m_CurrentProviderType = pService->GetProvider();
m_pSZ->SetCurrentProviderType(m_CurrentProviderType);
m_pDZ->SetCurrentProviderType(m_CurrentProviderType);
switch(m_CurrentProviderType)
{
case C_RPC_PROVIDER:
case CPP_RPC_PROVIDER:
m_pSZ->SetStyle(RPC_ENCODED);
m_pDZ->SetStyle(RPC_ENCODED);
break;
case C_DOC_PROVIDER:
case CPP_DOC_PROVIDER:
m_pSZ->SetStyle(DOC_LITERAL);
m_pDZ->SetStyle(DOC_LITERAL);
break;
case COM_PROVIDER:
//TODO: ??
break;
default:;
//TODO: ??
}
/* check for stream version in the request and decide whether we support it or not
* if we do not support send a soapfault with version mismatch. */
nSoapVersion = m_pDZ->GetVersion();
if (nSoapVersion == VERSION_LAST) /* version not supported */
{
m_pSZ->setSoapVersion(SOAP_VER_1_2);
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_VERSION_MISMATCH));
break; //do .. while(0)
}
/* Set Soap version in the Serializer and the envelope */
if (AXIS_SUCCESS != m_pSZ->setSoapVersion((SOAP_VERSION)nSoapVersion))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SOAPCONTENTERROR));
break; //do .. while(0)
}
/* get the operation name from transport information Ex: from SOAPAction header */
AxisString sOperation = stream->transport.pGetTrtFunct(OPERATION_NAME, stream);
if (sOperation.empty())
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_NOSOAPMETHOD));
break; //do .. while(0)
}
/* remove any quotes in the operation name */
if (sOperation.rfind('\"') != string::npos)
{
sOperation = sOperation.substr(0, sOperation.length() - 1);
}
m_pMsgData->SetOperationName(sOperation.c_str());
if (pService->IsAllowedMethod(sOperation.c_str()))
{
/* load actual web service handler */
if (AXIS_SUCCESS != g_pHandlerPool->GetWebService(&m_pWebService, sSessionId, pService))
{
/* error : couldnot load web service */
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_COULDNOTLOADSRV));
break; //do .. while(0)
}
/* check whether the provider type in the wsdd matchs the service's binding style */
AXIS_BINDING_STYLE nBindingStyle;
if (0 != m_pWebService->_functions)
/* C service */
{
nBindingStyle = m_pWebService->_functions->GetBindingStyle(m_pWebService->_object);
}
else if (0 != m_pWebService->_object)
{
nBindingStyle = ((WrapperClassHandler*)m_pWebService->_object)->GetBindingStyle();
}
if (m_pSZ->GetStyle() != nBindingStyle)
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SOAPCONTENTERROR));
break; //do .. while(0)
}
}
else
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_METHODNOTALLOWED));
//method is not an exposed allowed method
break; //do .. while(0)
}
//Get Global and Transport Handlers
if(AXIS_SUCCESS != (Status = InitializeHandlers(sSessionId, stream->trtype)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_COULDNOTLOADHDL));
break; //do .. while(0)
}
//Get Service specific Handlers from the pool if configured any
if(AXIS_SUCCESS != (Status = g_pHandlerPool->GetRequestFlowHandlerChain(&m_pSReqFChain, sSessionId, pService)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_COULDNOTLOADHDL));
break; //do .. while(0)
}
if(AXIS_SUCCESS != (Status = g_pHandlerPool->GetResponseFlowHandlerChain(&m_pSResFChain, sSessionId, pService)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_COULDNOTLOADHDL));
break; //do .. while(0)
}
/**
* Let Deserializer parse the header section so that handlers can use them.
* Each handler should remove the header block targetted to it
* and handlers may add header blocks to the DeSerializer and Serializer
* irrespective of whether it is request message path or response path.
* A header may be added to the Deserializer ONLY IF there is a CAN BE
* a handler in this soap processor to handle it.
*/
if (AXIS_SUCCESS != m_pDZ->GetHeader())
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SOAPCONTENTERROR));
break; //do .. while(0)
}
/**
* Invoke all handlers including the webservice
* in case of failure coresponding stream fault message will be set
*/
Status = Invoke(m_pMsgData);
}
while(0);
/**
* Get any header blocks unprocessed (left) in the Deserializer and add them to the Serializer
* They may be headers targetted to next soap processors
*/
HeaderBlock* pHderBlk = NULL;
while(true)
{
/* following function gets a header block from Deserializer irrespective of any thing */
pHderBlk = m_pDZ->GetHeaderBlock();
/* add it to the Serializer */
if (pHderBlk) m_pSZ->AddHeaderBlock(pHderBlk);
else break;
}
m_pSZ->SetOutputStream(stream);
//Pool back the Service specific handlers
if (m_pSReqFChain) g_pHandlerPool->PoolHandlerChain(m_pSReqFChain, sSessionId);
if (m_pSResFChain) g_pHandlerPool->PoolHandlerChain(m_pSResFChain, sSessionId);
//Pool back the Global and Transport handlers
//UnInitializeHandlers(sSessionId, stream->trtype);
//Pool back the webservice
if (m_pWebService) g_pHandlerPool->PoolWebService(sSessionId, m_pWebService, pService);
// AXIS_CATCH(exception* e)
//todo
/*
An exception derived from exception which is not handled will be handled here.
You can call a method in AxisModule which may unload the ServerAxisEngine
from the webserver and report the error. You can also write this
in a logfile specific to axis.
*/
#ifdef _AXISTRACE
delete(e);
#endif
// AXIS_CATCH(...)
//todo
/*
An unknown exception which is not handled will be handled here.
You can call a method in AxisModule which may unload the ServerAxisEngine
from the webserver and report the error. You can also write this
in a logfile specific to axis.
*/
// AXIS_ENDCATCH
return AXIS_SUCCESS;
}
int ServerAxisEngine::Invoke(MessageData* pMsg)
{
enum AE_LEVEL {AE_START=1, AE_TRH, AE_GLH, AE_SERH, AE_SERV};
int Status = AXIS_FAIL;
int level = AE_START;
do
{
//invoke transport request handlers
if (m_pTReqFChain) {
if(AXIS_SUCCESS != (Status = m_pTReqFChain->Invoke(pMsg)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_HANDLERFAILED));
break; //do .. while (0)
}
}
level++; // AE_TRH
//invoke global request handlers
if (m_pGReqFChain)
{
if(AXIS_SUCCESS != (Status = m_pGReqFChain->Invoke(pMsg)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_HANDLERFAILED));
break; //do .. while (0)
}
}
level++; //AE_GLH
//invoke service specific request handlers
if (m_pSReqFChain)
{
if(AXIS_SUCCESS != (Status = m_pSReqFChain->Invoke(pMsg)))
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_HANDLERFAILED));
break; //do .. while (0)
}
}
level++; //AE_SERH
/*
* Before processing the soap body check whether there is any header blocks
* with mustUnderstand attribute left unprocessed in the Deserializer. If so
* return a soap fault.
*/
if (m_pDZ->IsAnyMustUnderstandHeadersLeft())
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_MUST_UNDERSTAND));
break; //do .. while (0)
}
//call actual web service handler
if (m_pWebService)
{
if (0 != m_pWebService->_functions)
/* C web service */
{
IMessageData_C cMC = {0,0};
cMC._object = pMsg;
cMC._functions = &IMessageData::ms_VFtable;
Status = m_pWebService->_functions->Invoke(m_pWebService->_object, &cMC);
}
else if (0 != m_pWebService->_object)
{
Status = ((WrapperClassHandler*)m_pWebService->_object)->Invoke(pMsg);
}
else Status = AXIS_FAIL;
if (AXIS_SUCCESS != Status)
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_WEBSERVICEFAILED));
break;
}
}
level++; //AE_SERV
}
while(0);
if (AXIS_SUCCESS != m_pDZ->FlushInputStream())
{
m_pSZ->setSoapFault(SoapFault::getSoapFault(SF_SOAPCONTENTERROR));
return AXIS_FAIL;
}
pMsg->setPastPivotState(true);
/*
The case clauses in this switch statement have no breaks.
Hence, if Everything up to web service invocation was successful
then all response handlers are invoked. If there was a failure
at some point the response handlers from that point onwards
are invoked.
*/
switch (level)
{
case AE_SERV: //Everything Success.
Status = AXIS_SUCCESS;
//no break;
case AE_SERH: //actual web service handler has failed
//invoke web service specific response handlers
if (m_pSResFChain)
{
m_pSResFChain->Invoke(pMsg);
}
//no break;
case AE_GLH: //web service specific handlers have failed
//invoke global response handlers
if (m_pGResFChain)
{
m_pGResFChain->Invoke(pMsg);
}
//no break;
case AE_TRH: //global handlers have failed
if (m_pTResFChain)
{
m_pTResFChain->Invoke(pMsg);
}
//no break;
case AE_START:;//transport handlers have failed
};
return Status;
}
void ServerAxisEngine::OnFault(MessageData* pMsg)
{
}