You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by na...@apache.org on 2006/11/28 06:38:12 UTC
svn commit: r479917 - in /webservices/axis/trunk/c/src: common/ engine/
engine/client/ platforms/aix/ platforms/hp-ux/ platforms/os400/
platforms/unix/ platforms/windows/ soap/ transport/axis3/
transport/axis3/HTTPChannel/ transport/axis3/HTTPSSLChanne...
Author: nadiramra
Date: Mon Nov 27 21:38:11 2006
New Revision: 479917
URL: http://svn.apache.org/viewvc?view=rev&rev=479917
Log:
AXISCPP-943 and AXISCPP-923. Memory leaks when throwing exceptions and exception
messages not informative or correct.
Modified:
webservices/axis/trunk/c/src/common/AxisConfigException.h
webservices/axis/trunk/c/src/common/AxisGenException.h
webservices/axis/trunk/c/src/engine/AxisEngineException.h
webservices/axis/trunk/c/src/engine/HandlerLoader.cpp
webservices/axis/trunk/c/src/engine/SOAPTransportFactory.cpp
webservices/axis/trunk/c/src/engine/XMLParserFactory.cpp
webservices/axis/trunk/c/src/engine/client/ClientAxisEngine.cpp
webservices/axis/trunk/c/src/platforms/aix/PlatformSpecificAIX.hpp
webservices/axis/trunk/c/src/platforms/hp-ux/PlatformSpecificHP-UX.hpp
webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.cpp
webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.hpp
webservices/axis/trunk/c/src/platforms/unix/PlatformSpecificUnix.hpp
webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.cpp
webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.hpp
webservices/axis/trunk/c/src/soap/AxisSoapException.h
webservices/axis/trunk/c/src/transport/axis3/ChannelFactory.cpp
webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.cpp
webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.hpp
webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp
webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp
webservices/axis/trunk/c/src/transport/axis3/HTTPTransportException.hpp
webservices/axis/trunk/c/src/xml/AxisParseException.h
Modified: webservices/axis/trunk/c/src/common/AxisConfigException.h
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/common/AxisConfigException.h?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/common/AxisConfigException.h (original)
+++ webservices/axis/trunk/c/src/common/AxisConfigException.h Mon Nov 27 21:38:11 2006
@@ -37,7 +37,7 @@
}
// constructor
- AxisConfigException(const AxisConfigException& e): AxisException(e) { }
+ AxisConfigException(const AxisException& e): AxisException(e) { }
// destructor
virtual ~AxisConfigException() throw() { }
Modified: webservices/axis/trunk/c/src/common/AxisGenException.h
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/common/AxisGenException.h?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/common/AxisGenException.h (original)
+++ webservices/axis/trunk/c/src/common/AxisGenException.h Mon Nov 27 21:38:11 2006
@@ -36,7 +36,7 @@
{
setMessage(iExceptionCode, "AxisGenException:", pcMessage);
}
- AxisGenException(const AxisGenException& e): AxisException (e) { }
+ AxisGenException(const AxisException& e): AxisException (e) { }
virtual ~AxisGenException() throw() { }
};
Modified: webservices/axis/trunk/c/src/engine/AxisEngineException.h
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/engine/AxisEngineException.h?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/engine/AxisEngineException.h (original)
+++ webservices/axis/trunk/c/src/engine/AxisEngineException.h Mon Nov 27 21:38:11 2006
@@ -35,7 +35,7 @@
{
setMessage(iExceptionCode, "AxisEngineException:", pcMessage);
}
- AxisEngineException(const AxisEngineException& e): AxisException (e) { }
+ AxisEngineException(const AxisException& e): AxisException (e) { }
virtual ~AxisEngineException() throw() { }
};
Modified: webservices/axis/trunk/c/src/engine/HandlerLoader.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/engine/HandlerLoader.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/engine/HandlerLoader.cpp (original)
+++ webservices/axis/trunk/c/src/engine/HandlerLoader.cpp Mon Nov 27 21:38:11 2006
@@ -25,7 +25,7 @@
#pragma warning (disable : 4786)
#endif
-
+// !!! Must be first thing in file !!!
#include "../platforms/PlatformAutoSense.hpp"
#include "HandlerLoader.h"
@@ -90,21 +90,11 @@
if (!pHandlerInfo->m_Handler)
{
- AXISTRACE1("SERVER_ENGINE_LIBRARY_LOADING_FAILED", CRITICAL);
-
- long dwError = GETLASTERROR
- string * message = PLATFORM_GET_ERROR_MESSAGE( dwError);
- char fullMessage[1024];
- sprintf(fullMessage,
- "Failed to load handler within server engine: \n \
- Error Message='%s'\
- Error Code='%d'\n \
- Load lib error='%s' \n",
- message->c_str(), (int) dwError, PLATFORM_LOADLIB_ERROR);
+ // get load lib error information
+ string sFullMessage = "Failed to load handler library " +
+ pHandlerInfo->m_sLib + ". " + PLATFORM_LOADLIB_ERROR;
- delete( message);
-
- throw AxisEngineException(SERVER_ENGINE_LIBRARY_LOADING_FAILED, fullMessage);
+ throw AxisEngineException(SERVER_ENGINE_LIBRARY_LOADING_FAILED, sFullMessage.c_str());
}
return AXIS_SUCCESS;
@@ -138,18 +128,23 @@
if (AXIS_SUCCESS == loadLib (pHandlerInfo))
{
pHandlerInfo->m_Create =
- (CREATE_OBJECT) PLATFORM_GETPROCADDR(pHandlerInfo->m_Handler,
- CREATE_FUNCTION);
- pHandlerInfo->m_Delete =
- (DELETE_OBJECT) PLATFORM_GETPROCADDR(pHandlerInfo->m_Handler,
- DELETE_FUNCTION);
+ (CREATE_OBJECT) PLATFORM_GETPROCADDR(pHandlerInfo->m_Handler, CREATE_FUNCTION);
+
+ if (pHandlerInfo->m_Create)
+ pHandlerInfo->m_Delete =
+ (DELETE_OBJECT) PLATFORM_GETPROCADDR(pHandlerInfo->m_Handler,DELETE_FUNCTION);
if (!pHandlerInfo->m_Create || !pHandlerInfo->m_Delete)
{
+ // get load lib error information
+ string sFullMessage = "Failed to resolve to handler procedures in library " +
+ pHandlerInfo->m_sLib + ". " + PLATFORM_LOADLIB_ERROR;
+
+ // Unload library - this must be done after obtaining error info above
unloadLib (pHandlerInfo);
+
delete pHandlerInfo;
//unlock ();
- AXISTRACE1 ("Library loading failed", CRITICAL);
throw AxisEngineException(SERVER_ENGINE_LIBRARY_LOADING_FAILED);
}
else // success
@@ -159,8 +154,7 @@
}
else
{
- //unlock ();
- AXISTRACE1 ("Library loading failed", CRITICAL);
+ // dead code - will never be reached, need to remove.
throw AxisEngineException(SERVER_ENGINE_LIBRARY_LOADING_FAILED);
}
}
Modified: webservices/axis/trunk/c/src/engine/SOAPTransportFactory.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/engine/SOAPTransportFactory.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/engine/SOAPTransportFactory.cpp (original)
+++ webservices/axis/trunk/c/src/engine/SOAPTransportFactory.cpp Mon Nov 27 21:38:11 2006
@@ -59,15 +59,19 @@
if (!loadLib())
{
m_Create = (CREATE_OBJECT1) PLATFORM_GETPROCADDR(m_LibHandler, CREATE_FUNCTION1);
- m_Delete = (DELETE_OBJECT1) PLATFORM_GETPROCADDR(m_LibHandler, DELETE_FUNCTION1);
+ if (m_Create)
+ m_Delete = (DELETE_OBJECT1) PLATFORM_GETPROCADDR(m_LibHandler, DELETE_FUNCTION1);
if (!m_Create || !m_Delete)
{
+ // get load lib error information
+ string sFullMessage = "Failed to resolve to SOAP transport procedures in library " +
+ string(m_pcLibraryPath) + ". " + PLATFORM_LOADLIB_ERROR;
+
+ // Unload library - this must be done after obtaining error info above
unloadLib();
- AXISTRACE1("SERVER_ENGINE_LOADING_TRANSPORT_FAILED", CRITICAL);
- char *s = new char[strlen(m_pcLibraryPath)+1];
- strcpy(s,m_pcLibraryPath);
- throw AxisEngineException(SERVER_ENGINE_LOADING_TRANSPORT_FAILED, s);
+
+ throw AxisEngineException(SERVER_ENGINE_LOADING_TRANSPORT_FAILED, sFullMessage.c_str());
}
#ifdef ENABLE_AXISTRACE
// Load function to do lib level inits
@@ -86,10 +90,8 @@
}
else
{
- AXISTRACE1("SERVER_ENGINE_LOADING_TRANSPORT_FAILED", CRITICAL);
- char *s = new char[strlen(m_pcLibraryPath)+1];
- strcpy(s,m_pcLibraryPath);
- throw AxisEngineException(SERVER_ENGINE_LOADING_TRANSPORT_FAILED, s);
+ // dead code - will never be reached, need to remove.
+ throw AxisEngineException(SERVER_ENGINE_LOADING_TRANSPORT_FAILED);
}
return AXIS_SUCCESS;
}
@@ -110,7 +112,7 @@
{
SOAPTransport* pTpt = NULL;
m_Create(&pTpt);
- pTpt->setProtocol(eProtocol);
+ pTpt->setProtocol(eProtocol);
return pTpt;
}
@@ -125,20 +127,11 @@
if (!m_LibHandler)
{
- AXISTRACE1("SERVER_ENGINE_LOADING_TRANSPORT_FAILED", CRITICAL);
- long dwError = GETLASTERROR
- string * message = PLATFORM_GET_ERROR_MESSAGE( dwError);
- char fullMessage[1024];
- sprintf(fullMessage,
- "Failed to load transport within server engine: \n \
- Error Message='%s'\
- Error Code='%d'\n \
- Load lib error='%s' \n",
- message->c_str(), (int) dwError, PLATFORM_LOADLIB_ERROR);
+ // get load lib error information
+ string sFullMessage = "Failed to load transport library " +
+ string(m_pcLibraryPath) + ". " + PLATFORM_LOADLIB_ERROR;
- delete( message);
-
- throw AxisEngineException(SERVER_ENGINE_LOADING_TRANSPORT_FAILED, fullMessage);
+ throw AxisEngineException(SERVER_ENGINE_LOADING_TRANSPORT_FAILED, sFullMessage.c_str());
}
return AXIS_SUCCESS;
}
Modified: webservices/axis/trunk/c/src/engine/XMLParserFactory.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/engine/XMLParserFactory.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/engine/XMLParserFactory.cpp (original)
+++ webservices/axis/trunk/c/src/engine/XMLParserFactory.cpp Mon Nov 27 21:38:11 2006
@@ -57,14 +57,19 @@
if (!loadLib())
{
m_Create = (CREATE_OBJECT2) PLATFORM_GETPROCADDR(m_LibHandler, CREATE_FUNCTION2);
- m_Delete = (DELETE_OBJECT2) PLATFORM_GETPROCADDR(m_LibHandler, DELETE_FUNCTION2);
+ if (m_Create)
+ m_Delete = (DELETE_OBJECT2) PLATFORM_GETPROCADDR(m_LibHandler, DELETE_FUNCTION2);
+
if (!m_Create || !m_Delete)
{
+ // get load lib error information
+ string sFullMessage = "Failed to resolve to XML Parser procedures in library " +
+ string(m_pcLibraryPath) + ". " + PLATFORM_LOADLIB_ERROR;
+
+ // Unload library - this must be done after obtaining error info above
unloadLib();
- char *s = new char[strlen(m_pcLibraryPath)+1];
- strcpy(s,m_pcLibraryPath);
- AxisTrace::traceLine("Server engine failed to load XML Parser");
- throw AxisEngineException(SERVER_ENGINE_LOADING_PARSER_FAILED, s);
+
+ throw AxisEngineException(SERVER_ENGINE_LOADING_PARSER_FAILED, sFullMessage.c_str());
}
else
{
@@ -80,12 +85,8 @@
}
else
{
- char *s = new char[strlen(m_pcLibraryPath)+1];
- strcpy(s,m_pcLibraryPath);
- AxisTrace::traceLine("Server engine failed to load XML Parser: ");
- AxisTrace::traceLine(s);
-
- throw AxisEngineException(SERVER_ENGINE_LOADING_PARSER_FAILED, s);
+ // dead code - will never be reached, need to remove.
+ throw AxisEngineException(SERVER_ENGINE_LOADING_PARSER_FAILED);
}
return AXIS_SUCCESS;
}
@@ -123,20 +124,11 @@
if (!m_LibHandler)
{
- long dwError = GETLASTERROR
- string * message = PLATFORM_GET_ERROR_MESSAGE( dwError);
- char fullMessage[5024];
- sprintf(fullMessage,
- "Failed to load parser '%s' within server engine: \n \
- Error Message='%s'\n\
- Error Code='%d'\n \
- Load lib error='%s' \n",
- m_pcLibraryPath, message->c_str(), (int) dwError, PLATFORM_LOADLIB_ERROR);
-
- delete( message);
+ // get load lib error information
+ string sFullMessage = "Failed to load XML Parser library " +
+ string(m_pcLibraryPath) + ". " + PLATFORM_LOADLIB_ERROR;
- AxisTrace::traceLine(fullMessage);
- throw AxisEngineException(SERVER_ENGINE_LOADING_PARSER_FAILED, fullMessage);
+ throw AxisEngineException(SERVER_ENGINE_LOADING_PARSER_FAILED, sFullMessage.c_str());
}
return AXIS_SUCCESS;
Modified: webservices/axis/trunk/c/src/engine/client/ClientAxisEngine.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/engine/client/ClientAxisEngine.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/engine/client/ClientAxisEngine.cpp (original)
+++ webservices/axis/trunk/c/src/engine/client/ClientAxisEngine.cpp Mon Nov 27 21:38:11 2006
@@ -142,11 +142,9 @@
{
/* Throw a AxisGenException here instead of rethrowing the original exception because
* the original exception may be an transport exception which will go out of scope when
- * the transport library is unloaded. The original exception will delete its own message
- * storage, so the false as the last parameter tells AxisGenException not to try to
- * delete it.
+ * the transport library is unloaded.
*/
- throw AxisGenException(e.getExceptionCode(), const_cast<char*>(e.what()));
+ throw AxisGenException(e);
}
return Status;
}
Modified: webservices/axis/trunk/c/src/platforms/aix/PlatformSpecificAIX.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/platforms/aix/PlatformSpecificAIX.hpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/platforms/aix/PlatformSpecificAIX.hpp (original)
+++ webservices/axis/trunk/c/src/platforms/aix/PlatformSpecificAIX.hpp Mon Nov 27 21:38:11 2006
@@ -47,7 +47,7 @@
#define PLATFORM_UNLOADLIB lt_dlclose
#define PLATFORM_GETPROCADDR lt_dlsym
#define PLATFORM_LOADLIBEXIT lt_dlexit
- #define PLATFORM_LOADLIB_ERROR lt_dlerror()
+ #define PLATFORM_LOADLIB_ERROR string(lt_dlerror())
#else
#include <dlfcn.h>
#define DLHandler void*
@@ -57,7 +57,7 @@
#define PLATFORM_UNLOADLIB dlclose
#define PLATFORM_GETPROCADDR dlsym
#define PLATFORM_LOADLIBEXIT()
- #define PLATFORM_LOADLIB_ERROR dlerror()
+ #define PLATFORM_LOADLIB_ERROR string(dlerror())
#endif
@@ -78,7 +78,7 @@
#include <sys/timeb.h>
#include <pthread.h>
#include <unistd.h>
-#define PLATFORM_SLEEP(x) sleep(0);
+#define PLATFORM_SLEEP(x) sleep(x)
@@ -88,16 +88,16 @@
* and that it returns a long
* @return long the lsat error message for this thread
*/
-#define GETLASTERROR errno;
+#define GETLASTERROR errno
/**
* From the last error number get a sensible std::string representing it
* @param errorNumber the error Number you are trying to get a message for
- * @return the error message. NOTE: The caller is responsible for deleting the returned string
+ * @return the error message.
*/
#include <string>
-#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) new string(strerror(errorNumber));
+#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) string(strerror(errorNumber))
/**
* Platform specific method to obtain current thread ID
Modified: webservices/axis/trunk/c/src/platforms/hp-ux/PlatformSpecificHP-UX.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/platforms/hp-ux/PlatformSpecificHP-UX.hpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/platforms/hp-ux/PlatformSpecificHP-UX.hpp (original)
+++ webservices/axis/trunk/c/src/platforms/hp-ux/PlatformSpecificHP-UX.hpp Mon Nov 27 21:38:11 2006
@@ -19,6 +19,7 @@
#if !defined(_PLATFORM_SPECIFIC_HPUX_HPP)
#define _PLATFORM_SPECIFIC_HPUX_HPP
+#include <string>
// =============================================================
// Default paths to shared library/DLLs and files
@@ -47,7 +48,7 @@
#define PLATFORM_UNLOADLIB lt_dlclose
#define PLATFORM_GETPROCADDR lt_dlsym
#define PLATFORM_LOADLIBEXIT lt_dlexit
- #define PLATFORM_LOADLIB_ERROR lt_dlerror()
+ #define PLATFORM_LOADLIB_ERROR string(lt_dlerror())
#else
#include <dlfcn.h>
#define DLHandler void*
@@ -58,7 +59,7 @@
#define PLATFORM_UNLOADLIB dlclose
#define PLATFORM_GETPROCADDR dlsym
#define PLATFORM_LOADLIBEXIT()
- #define PLATFORM_LOADLIB_ERROR dlerror()
+ #define PLATFORM_LOADLIB_ERROR string(dlerror())
#endif
@@ -80,7 +81,7 @@
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
-#define PLATFORM_SLEEP(x) sleep(0);
+#define PLATFORM_SLEEP(x) sleep(x)
/**
* Get the last error code from the system.
@@ -88,15 +89,14 @@
* and that it returns a long
* @return long the lsat error message for this thread
*/
-#define GETLASTERROR errno;
+#define GETLASTERROR errno
/**
* From the last error number get a sensible std::string representing it
* @param errorNumber the error Number you are trying to get a message for
- * @return the error message. NOTE: The caller is responsible for deleting the returned string
+ * @return the error message.
*/
-#include <string>
-#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) new string(strerror(errorNumber));
+#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) string(strerror(errorNumber))
/**
* Platform specific method to obtain current thread ID
Modified: webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.cpp (original)
+++ webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.cpp Mon Nov 27 21:38:11 2006
@@ -30,10 +30,12 @@
#include <except.h>
#include <iconv.h> // iconv_t, iconv()
#include <qtqiconv.h> // QtqCode_T, QtqIconvOpen()
-
+#include <errno.h>
typedef int HMODULE;
+static char *dlErrorMessage = NULL;
+
/*
* ==========================================
* dlopen()
@@ -43,6 +45,7 @@
void * os400_dlopen(const char *file)
{
Qus_EC_t err = { sizeof(err), 0};
+ dlErrorMessage = NULL;
// Assume symbolic link, if error, assume actual path
char dllPath[4*1024+1];
@@ -68,7 +71,10 @@
Qp0lCvtPathToQSYSObjName(pathName,&qsys_info,"QSYS0100",sizeof(Qp0l_QSYS_Info_t), 0, &err);
if (err.Bytes_Available)
+ {
+ dlErrorMessage = "Path to shared library not valid.";
return NULL;
+ }
// blank pad object name and library in order to use on rslvsp().
char objectName[11];
@@ -94,7 +100,10 @@
actInfoLen = sizeof(activationInfo);
QleActBndPgm (&sysP,&handle,&activationInfo,&actInfoLen,&err);
if (err.Bytes_Available)
+ {
+ dlErrorMessage = "Unable to activate shared library.";
return NULL;
+ }
// Return the dlopen object.
void *returnHandle = malloc(sizeof(HMODULE));
@@ -102,6 +111,7 @@
return returnHandle;
LBL_RSLV_EH:
+ dlErrorMessage = "Unable to resolve to shared library.";
return NULL;
}
@@ -115,6 +125,7 @@
int exportType;
Qus_EC_t err = {sizeof(err),0 };
+ dlErrorMessage = NULL;
#pragma exception_handler (LBL_RSLV_EH, 0,_C1_ALL,_C2_MH_ESCAPE |_C2_MH_FUNCTION_CHECK, _CTLA_HANDLE)
@@ -123,13 +134,17 @@
QleGetExp ((int *)handle,0,0,(char *)name,&symbolAddress,&exportType,&err);
if (err.Bytes_Available)
+ {
+ dlErrorMessage = "Unable to resolve to procedure in shared library.";
return NULL;
+ }
return symbolAddress;
#pragma disable_handler
LBL_RSLV_EH:
+ dlErrorMessage = "Unable to resolve to procedure in shared library.";
return NULL;
}
@@ -142,11 +157,24 @@
*/
int os400_dlclose(void *handle)
{
+ dlErrorMessage = NULL;
*(int *)handle = -1;
free(handle);
return 0;
}
+/*
+ * ==========================================
+ * dlclose()
+ * Close a dlopen() object.
+ * ==========================================
+ */
+char * os400_dlerror()
+{
+ char *retError = dlErrorMessage;
+ dlErrorMessage = NULL;
+ return retError;
+}
/* ---------------------------------------------------------------------------------*/
/* ---------------------------------------------------------------------------------*/
Modified: webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.hpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.hpp (original)
+++ webservices/axis/trunk/c/src/platforms/os400/PlatformSpecificOS400.hpp Mon Nov 27 21:38:11 2006
@@ -19,6 +19,16 @@
#define _PLATFORM_SPECIFIC_OS400_HPP
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <time.h> // strftime(), localtime()
+#include <sys/time.h> // gettimeofday()
+#include <unistd.h> // access()
+#include <string>
+
// =============================================================
// Default paths to shared library/DLLs and files
// =============================================================
@@ -47,11 +57,12 @@
#define PLATFORM_UNLOADLIB os400_dlclose
#define PLATFORM_GETPROCADDR os400_dlsym
#define PLATFORM_LOADLIBEXIT()
-#define PLATFORM_LOADLIB_ERROR strerror(errno)
+#define PLATFORM_LOADLIB_ERROR string(os400_dlerror())
extern void *os400_dlopen(const char *);
extern void *os400_dlsym(void *, const char *);
extern int os400_dlclose(void *);
+extern char *os400_dlerror();
// =============================================================
// National Language Support
@@ -78,7 +89,7 @@
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
-#define PLATFORM_SLEEP(x) sleep(0);
+#define PLATFORM_SLEEP(x) sleep(x)
/**
@@ -87,16 +98,16 @@
* and that it returns a long
* @return long the lsat error message for this thread
*/
-#define GETLASTERROR errno;
+#define GETLASTERROR errno
/**
* From the last error number get a sensible std::string representing it
* @param errorNumber the error Number you are trying to get a message for
- * @return the error message. NOTE: The caller is responsible for deleting the returned string
+ * @return the error message.
*/
#include <string>
-#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) new string(strerror(errorNumber));
+#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) string(strerror(errorNumber))
/**
* Platform specific method to obtain current thread ID
@@ -139,6 +150,22 @@
#define PRINTF_LONGLONG_FORMAT_SPECIFIER_CHARS "lld"
#define PRINTF_UNSIGNED_LONGLONG_FORMAT_SPECIFIER "%llu"
#define PRINTF_UNSIGNED_LONGLONG_FORMAT_SPECIFIER_CHARS "llu"
+
+/**
+ * For debugging
+ */
+static void traceData(void *d, int length)
+{
+ char logFile[1024];
+ sprintf(logFile, "/tmp/axis.log");
+ FILE *fh = fopen(logFile, "ab, codepage=819");
+ setvbuf(fh, NULL, _IOFBF, (size_t)(4*1024));
+ fwrite(d, 1, length, fh);
+ fwrite("\x0d\x0a\x2b\x2b\x2b\x2b\x2b\x2b\x0d\x0a", 1, 10, fh);
+ fflush(fh);
+ fclose(fh);
+}
+
#endif
Modified: webservices/axis/trunk/c/src/platforms/unix/PlatformSpecificUnix.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/platforms/unix/PlatformSpecificUnix.hpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/platforms/unix/PlatformSpecificUnix.hpp (original)
+++ webservices/axis/trunk/c/src/platforms/unix/PlatformSpecificUnix.hpp Mon Nov 27 21:38:11 2006
@@ -19,6 +19,7 @@
#if !defined(_PLATFORM_SPECIFIC_UNIX_HPP)
#define _PLATFORM_SPECIFIC_UNIX_HPP
+#include <string>
// =============================================================
// Default paths to shared library/DLLs and files
@@ -47,7 +48,7 @@
#define PLATFORM_UNLOADLIB lt_dlclose
#define PLATFORM_GETPROCADDR lt_dlsym
#define PLATFORM_LOADLIBEXIT lt_dlexit
- #define PLATFORM_LOADLIB_ERROR lt_dlerror()
+ #define PLATFORM_LOADLIB_ERROR string(lt_dlerror())
#else
#include <dlfcn.h>
#define DLHandler void*
@@ -58,7 +59,7 @@
#define PLATFORM_UNLOADLIB dlclose
#define PLATFORM_GETPROCADDR dlsym
#define PLATFORM_LOADLIBEXIT()
- #define PLATFORM_LOADLIB_ERROR dlerror()
+ #define PLATFORM_LOADLIB_ERROR string(dlerror())
#endif
@@ -79,7 +80,7 @@
#include <sys/timeb.h>
#include <unistd.h>
#include <errno.h>
-#define PLATFORM_SLEEP(x) sleep(0);
+#define PLATFORM_SLEEP(x) sleep(x)
/**
* Get the last error code from the system.
@@ -87,15 +88,14 @@
* and that it returns a long
* @return long the lsat error message for this thread
*/
-#define GETLASTERROR errno;
+#define GETLASTERROR errno
/**
* From the last error number get a sensible std::string representing it
* @param errorNumber the error Number you are trying to get a message for
- * @return the error message. NOTE: The caller is responsible for deleting the returned string
+ * @return the error message.
*/
-#include <string>
-#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) new string(strerror(errorNumber));
+#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) string(strerror(errorNumber))
/**
* Platform specific method to obtain current thread ID
Modified: webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.cpp (original)
+++ webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.cpp Mon Nov 27 21:38:11 2006
@@ -21,9 +21,8 @@
-std::string* getPlatformErrorMessage(long errorNumber)
+std::string getPlatformErrorMessage(long errorNumber)
{
- std::string* returningString = new std::string();
LPVOID lpMsgBuf;
FormatMessage(
@@ -35,7 +34,7 @@
(LPTSTR) &lpMsgBuf,
0, NULL );
- returningString->append((LPTSTR)lpMsgBuf);
+ std::string returningString((LPTSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
return returningString;
Modified: webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.hpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.hpp (original)
+++ webservices/axis/trunk/c/src/platforms/windows/PlatformSpecificWindows.hpp Mon Nov 27 21:38:11 2006
@@ -19,6 +19,9 @@
#if !defined( _PLATFORM_SPECIFIC_WINDOWS_HPP )
#define _PLATFORM_SPECIFIC_WINDOWS_HPP
+// Disable: C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
+#pragma warning (disable : 4290)
+
//#define _WIN32_WINNT 0x0400
#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
#include <windows.h>
@@ -58,7 +61,7 @@
#define PLATFORM_UNLOADLIB FreeLibrary
#define PLATFORM_GETPROCADDR GetProcAddress
#define PLATFORM_LOADLIBEXIT()
-#define PLATFORM_LOADLIB_ERROR ""
+#define PLATFORM_LOADLIB_ERROR PLATFORM_GET_ERROR_MESSAGE(GetLastError())
// =============================================================
// National Language Support
@@ -73,7 +76,7 @@
// =============================================================
// Miscellaneous
// =============================================================
-#define PLATFORM_SLEEP(x) Sleep(0);
+#define PLATFORM_SLEEP(x) Sleep(x)
/**
* Get the last error code from the system.
@@ -81,14 +84,14 @@
* and that it returns a long
* @return long the lsat error message for this thread
*/
-#define GETLASTERROR GetLastError();
+#define GETLASTERROR GetLastError()
/**
* From the last error number get a sensible std::string representing it
* @param errorNumber the error Number you are trying to get a message for
* @return the error message. NOTE: The caller is responsible for deleting the returned string
*/
-#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) getPlatformErrorMessage(errorNumber);
+#define PLATFORM_GET_ERROR_MESSAGE(errorNumber) getPlatformErrorMessage(errorNumber)
/**
* type to be used for 64bit integers
@@ -116,7 +119,7 @@
#define PLATFORM_GET_TIME_IN_MILLIS _ftime
#define PLATFORM_TIMEB _timeb
-std::string* getPlatformErrorMessage(long errorNumber);
+std::string getPlatformErrorMessage(long errorNumber);
HMODULE callLoadLib(LPCTSTR lib);
Modified: webservices/axis/trunk/c/src/soap/AxisSoapException.h
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/soap/AxisSoapException.h?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/soap/AxisSoapException.h (original)
+++ webservices/axis/trunk/c/src/soap/AxisSoapException.h Mon Nov 27 21:38:11 2006
@@ -37,7 +37,7 @@
}
// constructor
- AxisSoapException(const AxisSoapException& e): AxisException (e) { }
+ AxisSoapException(const AxisException& e): AxisException (e) { }
// destructor
virtual ~AxisSoapException() throw() { }
Modified: webservices/axis/trunk/c/src/transport/axis3/ChannelFactory.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/ChannelFactory.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/ChannelFactory.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/ChannelFactory.cpp Mon Nov 27 21:38:11 2006
@@ -72,39 +72,37 @@
if( !sLibHandler)
{
- long dwError = GETLASTERROR
- string * message = PLATFORM_GET_ERROR_MESSAGE( dwError);
- char fullMessage[1024];
- sprintf(fullMessage,
- "Failed to load transport channel within server engine: \n \
- Error Message='%s'\
- Error Code='%d'\n \
- Load lib error='%s' \n",
- message->c_str(), (int) dwError, PLATFORM_LOADLIB_ERROR);
+ // get load lib error information
+ string sFullMessage = "Failed to load transport channel library " +
+ string(pcLibraryName) + ". " + PLATFORM_LOADLIB_ERROR;
- delete( message);
-
- throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, fullMessage);
+ throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, sFullMessage.c_str());
}
else
{
- CREATE_OBJECT3 sCreate = (CREATE_OBJECT3) PLATFORM_GETPROCADDR( sLibHandler, CREATE_FUNCTION3);
- DELETE_OBJECT3 sDelete = (DELETE_OBJECT3) PLATFORM_GETPROCADDR( sLibHandler, DELETE_FUNCTION3);
+ CREATE_OBJECT3 sCreate = (CREATE_OBJECT3)NULL;
+ DELETE_OBJECT3 sDelete = (DELETE_OBJECT3)NULL;
+
+ sCreate = (CREATE_OBJECT3) PLATFORM_GETPROCADDR( sLibHandler, CREATE_FUNCTION3);
+ if (sCreate)
+ sDelete = (DELETE_OBJECT3) PLATFORM_GETPROCADDR( sLibHandler, DELETE_FUNCTION3);
if (!sCreate || !sDelete)
{
+ // get load lib error information
+ string sFullMessage = "Failed to resolve to transport channel procedures in library " +
+ string(pcLibraryName) + ". " + PLATFORM_LOADLIB_ERROR;
+
+ // Unload library - this must be done after obtaining error info above
PLATFORM_UNLOADLIB( sLibHandler);
- char * pszErrorInfo = new char[ strlen( pcLibraryName) + 1];
- strcpy( pszErrorInfo, pcLibraryName);
-
if( eChannelType == UnsecureChannel)
{
- throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, pszErrorInfo);
+ throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, sFullMessage.c_str());
}
else
{
- throw HTTPTransportException( SERVER_TRANSPORT_LOADING_SSLCHANNEL_FAILED, pszErrorInfo);
+ throw HTTPTransportException( SERVER_TRANSPORT_LOADING_SSLCHANNEL_FAILED, sFullMessage.c_str());
}
}
@@ -203,38 +201,37 @@
pCh->m_Library = PLATFORM_LOADLIB( pcLibraryName);
if( !pCh->m_Library)
{
+ // get load lib error information
+ string sFullMessage = "Failed to pre-load transport channel library " +
+ string(pcLibraryName) + ". " + PLATFORM_LOADLIB_ERROR;
+
delete pCh;
-
- long dwError = GETLASTERROR
- string * message = PLATFORM_GET_ERROR_MESSAGE( dwError);
- char fullMessage[1024];
- sprintf(fullMessage,
- "Failed to load transport channel within server engine: \n \
- Error Message='%s'\
- Error Code='%d'\n \
- Load lib error='%s' \n",
- message->c_str(), (int) dwError, PLATFORM_LOADLIB_ERROR);
- delete( message);
-
- throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, fullMessage);
+ throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, sFullMessage.c_str());
}
pCh->m_Create = (CREATE_OBJECT3) PLATFORM_GETPROCADDR( pCh->m_Library, CREATE_FUNCTION3);
- pCh->m_Delete = (DELETE_OBJECT3) PLATFORM_GETPROCADDR( pCh->m_Library, DELETE_FUNCTION3);
+ if (pCh->m_Create)
+ pCh->m_Delete = (DELETE_OBJECT3) PLATFORM_GETPROCADDR( pCh->m_Library, DELETE_FUNCTION3);
+
if (!pCh->m_Create || !pCh->m_Delete)
{
+ // get load lib error information
+ string sFullMessage = "Failed to resolve to transport channel procedures in library " +
+ string(pcLibraryName) + ". " + PLATFORM_LOADLIB_ERROR;
+
+ // Unload library - this must be done after obtaining error info above
PLATFORM_UNLOADLIB( pCh->m_Library);
+
delete pCh;
- char * pszErrorInfo = new char[ strlen( pcLibraryName) + 1];
- strcpy( pszErrorInfo, pcLibraryName);
+
if( type == UnsecureChannel)
{
- throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, pszErrorInfo);
+ throw HTTPTransportException( SERVER_TRANSPORT_LOADING_CHANNEL_FAILED, sFullMessage.c_str());
}
else
{
- throw HTTPTransportException( SERVER_TRANSPORT_LOADING_SSLCHANNEL_FAILED, pszErrorInfo);
+ throw HTTPTransportException( SERVER_TRANSPORT_LOADING_SSLCHANNEL_FAILED, sFullMessage.c_str());
}
}
Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.cpp Mon Nov 27 21:38:11 2006
@@ -60,11 +60,7 @@
HTTPChannel::
~HTTPChannel()
{
- // If the socket value is not invalid, then close the socket before
- // deleting the Channel object.
- if( m_Sock != INVALID_SOCKET)
- CloseChannel();
-
+ CloseChannel();
StopSockets();
}
@@ -127,15 +123,13 @@
{
bool bSuccess = (bool) AXIS_FAIL;
- if( m_Sock != INVALID_SOCKET)
- CloseChannel();
+ CloseChannel();
m_LastError = "No Errors";
if( (bSuccess = OpenChannel()) != AXIS_SUCCESS)
{
- throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR,
- (char *) m_LastError.c_str());
+ throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR, m_LastError.c_str());
}
return bSuccess;
@@ -153,11 +147,7 @@
bool HTTPChannel::
close()
{
- if( m_Sock != INVALID_SOCKET)
- CloseChannel();
-
- m_Sock = INVALID_SOCKET;
-
+ CloseChannel();
return AXIS_SUCCESS;
}
@@ -195,66 +185,54 @@
{
if (INVALID_SOCKET == m_Sock)
{
- // Error - Reading cannot be done without having a open socket Input
- // streaming error on undefined channel; please open the
- // channel first
-
- m_LastError = "No open socket to read from.";
-
- throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET,
- (char *) m_LastError.c_str());
+ m_LastError = "Unable to perform read operation.";
+ throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET, m_LastError.c_str());
}
int nByteRecv = 0;
char buf[BUF_SIZE];
int iBufSize = BUF_SIZE - 10;
- //assume timeout not set; set default tatus to OK
- int iTimeoutStatus = 1;
-
- //check if timeout set
+ // If timeout set then wait for maximum amount of time for data
if( m_lTimeoutSeconds)
{
- iTimeoutStatus = applyTimeout();
- }
+ int iTimeoutStatus = applyTimeout();
- // Handle timeout outcome
- if( iTimeoutStatus < 0)
- {
- // Error
- m_LastError = "Channel error while waiting for timeout";
-
- // Select SOCKET_ERROR. Channel error while waiting for timeout
- throw HTTPTransportException( SERVER_TRANSPORT_TIMEOUT_EXCEPTION,
- (char *) m_LastError.c_str());
- }
-
- if( iTimeoutStatus == 0)
- {
- // Timeout expired - select timeout expired.
- // Channel error connection timeout before receiving
- m_LastError = "Channel error: connection timed out before receiving";
-
- throw HTTPTransportException( SERVER_TRANSPORT_TIMEOUT_EXPIRED,
- (char *) m_LastError.c_str());
+ // Handle timeout outcome
+ if( iTimeoutStatus < 0)
+ {
+ throw HTTPTransportException( SERVER_TRANSPORT_TIMEOUT_EXCEPTION, m_LastError.c_str());
+ }
+
+ if( iTimeoutStatus == 0)
+ {
+ m_LastError = "Read operation timed-out while waiting for data.";
+ throw HTTPTransportException( SERVER_TRANSPORT_TIMEOUT_EXPIRED, m_LastError.c_str() );
+ }
}
// Either timeout was not set or data available before timeout; so read
-
- if( (nByteRecv = recv( m_Sock, (char *) &buf, iBufSize, 0)) == SOCKET_ERROR)
+ nByteRecv = recv( m_Sock, (char *) &buf, iBufSize, 0);
+ if (nByteRecv == SOCKET_ERROR)
{
- ReportError( "Channel error", "while reading data");
-
+ // error on read operation
+ ReportError();
CloseChannel();
if( !bNoExceptionOnForceClose)
{
- throw HTTPTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR,
- (char *) m_LastError.c_str());
+ throw HTTPTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR, m_LastError.c_str());
}
}
-
- if( nByteRecv)
+ else if ( 0 == nByteRecv )
+ {
+ // read-side of socket is closed - anytime we come down expecting to read something
+ // and read-side is closed means that there must be a parsing bug in http transport level.
+ m_LastError = "Remote side of socket has been closed.";
+ CloseChannel();
+ throw HTTPTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR, m_LastError.c_str());
+ }
+ else if( nByteRecv)
{
buf[nByteRecv] = '\0';
memcpy(msg, buf, nByteRecv + 1);
@@ -278,17 +256,10 @@
const IChannel & HTTPChannel::
operator << (const char * msg)
{
- // Check that the Tx/Rx sockets are valid (this will have been done if the
- // application has called the open method first.
if( INVALID_SOCKET == m_Sock)
{
- // Error - Writing cannot be done without having a open socket to
- // remote end. Throw an exception.
-
- m_LastError = "No valid socket open";
-
- throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET,
- (char *) m_LastError.c_str());
+ m_LastError = "No valid socket to perform write operation.";
+ throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET, m_LastError.c_str());
}
int size = strlen( msg);
@@ -300,14 +271,13 @@
if( (nByteSent = send( m_Sock, msg, size, 0)) == SOCKET_ERROR)
#endif
{
- // Output streaming error while writing data. Close the channel and
- // throw an exception.
+ // This must be done first before closing channel in order to get actual error.
+ ReportError();
+
+ // Close the channel and throw an exception.
CloseChannel();
- ReportError( "Channel error", "while writing data");
-
- throw HTTPTransportException( SERVER_TRANSPORT_OUTPUT_STREAMING_ERROR,
- (char *) m_LastError.c_str());
+ throw HTTPTransportException( SERVER_TRANSPORT_OUTPUT_STREAMING_ERROR, m_LastError.c_str());
}
return *this;
@@ -470,49 +440,37 @@
paiAddrInfo->ai_protocol);
if( m_Sock < 0)
- {
continue;
- }
if( connect( m_Sock, paiAddrInfo->ai_addr, paiAddrInfo->ai_addrlen) < 0)
{
- // Cannot open a channel to the remote end, shutting down the
- // channel and then throw an exception.
- // Before we do anything else get the last error message;
- long dwError = GETLASTERROR
+ // This must be done first thing to get proper error. Generate full message.
+ ReportError();
+ char buffer[100];
+ sprintf(buffer, "%d", m_URL.getPort());
+ string fullMessage = "Failed to open connection to server at host " +
+ string(m_URL.getHostName()) +
+ " and port " + string(buffer) + ". " + m_LastError;
CloseChannel();
freeaddrinfo( paiAddrInfo0);
- string * message = PLATFORM_GET_ERROR_MESSAGE( dwError);
- char fullMessage[600];
- sprintf(fullMessage,
- "Failed to open connection to server: \n \
- hostname='%s'\n\
- port='%d'\n\
- Error Message='%s'\
- Error Code='%d'\n",
- m_URL.getHostName(), m_URL.getPort(), message->c_str(), (int) dwError);
-
- delete( message);
+ m_LastError = fullMessage;
- throw HTTPTransportException( CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED,
- fullMessage);
+ throw HTTPTransportException( CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED, m_LastError.c_str());
}
break;
}
- // Samisa: free addrInfo0 - no longer needed
freeaddrinfo( paiAddrInfo0);
+ // If couldn't create socket, close the channel and throw an exception.
if( m_Sock < 0)
{
- // Sockets error Couldn't create socket. Close the channel and throw
- // an exception.
+ ReportError();
CloseChannel();
-
- throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CREATE_ERROR);
+ throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CREATE_ERROR, m_LastError.c_str());
}
bSuccess = AXIS_SUCCESS;
@@ -520,8 +478,7 @@
#else // IPV6 not defined
if( (m_Sock = socket( PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
- m_LastError = "Could not Create a socket.";
-
+ ReportError();
return bSuccess;
}
@@ -536,12 +493,8 @@
// Attempt to bind the client to the client socket.
if( bind( m_Sock, (struct sockaddr *) &clAddr, sizeof( clAddr)) == SOCKET_ERROR)
{
- // Error whilst binding. Cannot open a channel to the remote end,
- // shutting down the channel and then throw an exception.
+ ReportError();
CloseChannel();
-
- m_LastError = "Error whilst binding. Cannot open a channel to the remote end,";
-
return bSuccess;
}
@@ -591,34 +544,22 @@
// Attempt to connect to the remote server.
if( connect( m_Sock, (struct sockaddr *) &svAddr, sizeof (svAddr)) == SOCKET_ERROR)
{
- // Cannot open a channel to the remote end, shutting down the
- // channel and then throw an exception.
+ // This must be done first thing to get proper error. Generate full message.
+ ReportError();
+ char buffer[100];
+ sprintf(buffer, "%d", m_URL.getPort());
+ string fullMessage = "Failed to open connection to server at host " +
+ string(m_URL.getHostName()) +
+ " and port " + string(buffer) + ". " + m_LastError;
- // Before we do anything else get the last error message;
- long dw = GETLASTERROR
CloseChannel();
-
- string* message = PLATFORM_GET_ERROR_MESSAGE(dw);
-
- char fullMessage[600];
- sprintf(fullMessage,
- "Failed to open connection to server: \n \
- hostname='%s'\n\
- port='%d'\n\
- Error Message='%s'\
- Error Code='%d'\n",
- m_URL.getHostName(), m_URL.getPort(), message->c_str(), dw);
-
- delete(message);
m_LastError = fullMessage;
return bSuccess;
}
else
- {
bSuccess = AXIS_SUCCESS;
- }
#endif // IPV6
@@ -633,7 +574,6 @@
*/
int one = 1;
-
setsockopt( m_Sock, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof( int));
return bSuccess;
@@ -651,14 +591,14 @@
void HTTPChannel::
CloseChannel()
{
- if( INVALID_SOCKET != m_Sock) // Check if socket already closed : AXISCPP-185
+ if( INVALID_SOCKET != m_Sock)
{
#ifdef WIN32
closesocket( m_Sock);
#else
::close( m_Sock);
#endif
- m_Sock = INVALID_SOCKET; // fix for AXISCPP-185
+ m_Sock = INVALID_SOCKET;
}
}
@@ -760,19 +700,21 @@
timeout.tv_usec = 0;
/* select returns 0 if timeout, 1 if input available, -1 if error. */
- return select( FD_SETSIZE, &set, NULL, NULL, &timeout);
+ int rc = select( FD_SETSIZE, &set, NULL, NULL, &timeout);
+
+ if (rc < 0)
+ ReportError();
+
+ return rc;
}
void HTTPChannel::
-ReportError( char * szText1, char * szText2)
+ReportError()
{
- long dwMsg = GETLASTERROR
- string * sMsg = PLATFORM_GET_ERROR_MESSAGE( dwMsg);
- char szMsg[600];
-
- sprintf( szMsg, "%s %d %s: '%s'\n", szText1, (int) dwMsg, szText2, sMsg->c_str());
-
- m_LastError = szMsg;
+ long dwError = GETLASTERROR;
+ char pcErr[100];
+ sprintf(pcErr,"Error is %d - ",(int)dwError);
+ m_LastError = string(pcErr) + PLATFORM_GET_ERROR_MESSAGE(dwError);
}
void HTTPChannel::
Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.hpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.hpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.hpp Mon Nov 27 21:38:11 2006
@@ -90,7 +90,7 @@
bool StartSockets();
void StopSockets();
int applyTimeout();
- void ReportError( char * szText1, char * szText2);
+ void ReportError();
private:
URL m_URL; // URL
Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp Mon Nov 27 21:38:11 2006
@@ -13,9 +13,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "HTTPSSLChannel.hpp"
+// !!! Must be first thing in file !!!
#include "../../../platforms/PlatformAutoSense.hpp"
+#include "HTTPSSLChannel.hpp"
+
+
/**
* cert_verify_callback( int ok, X509_STORE_CTX * ctx)
*
@@ -25,8 +28,8 @@
static int cert_verify_callback( int ok, X509_STORE_CTX * ctx)
{
- X509 * err_cert;
- char buf[256];
+ X509 * err_cert;
+ char buf[256];
err_cert = X509_STORE_CTX_get_current_cert( ctx);
X509_NAME_oneline( X509_get_subject_name( err_cert), buf, 256);
@@ -41,33 +44,34 @@
*
*/
-HTTPSSLChannel::HTTPSSLChannel()
+HTTPSSLChannel::
+HTTPSSLChannel()
{
- m_LastError = "No Errors";
+ m_LastError = "No Errors";
- m_Sock = INVALID_SOCKET;
+ m_Sock = INVALID_SOCKET;
- m_bUseProxy = false;
+ m_bUseProxy = false;
m_strProxyHost = "";
m_uiProxyPort = 0;
#ifdef WIN32
- m_lTimeoutSeconds = 10;
+ m_lTimeoutSeconds = 10;
#else
- m_lTimeoutSeconds = 0;
+ m_lTimeoutSeconds = 0;
#endif
- bNoExceptionOnForceClose = false;
+ bNoExceptionOnForceClose = false;
- if( !StartSockets())
- {
- throw HTTPTransportException( SERVER_TRANSPORT_CHANNEL_INIT_ERROR);
- }
+ if( !StartSockets())
+ {
+ throw HTTPTransportException( SERVER_TRANSPORT_CHANNEL_INIT_ERROR);
+ }
- OpenSSL_Initialise();
+ OpenSSL_Initialise();
- m_sslContext = NULL;
- m_sslHandle = NULL;
+ m_sslContext = NULL;
+ m_sslHandle = NULL;
}
/**
@@ -77,18 +81,12 @@
*
*/
-HTTPSSLChannel::~HTTPSSLChannel()
+HTTPSSLChannel::
+~HTTPSSLChannel()
{
- OpenSSL_Close();
-
-// If the socket value is not invalid, then close the socket before
-// deleting the Channel object.
- if( m_Sock != INVALID_SOCKET)
- {
- CloseChannel();
- }
-
- StopSockets();
+ OpenSSL_Close();
+ CloseChannel();
+ StopSockets();
}
/**
@@ -99,7 +97,8 @@
* @return char * containing the URL associated with the open socket
*/
-const char * HTTPSSLChannel::getURL()
+const char * HTTPSSLChannel::
+getURL()
{
return m_URL.getURL();
}
@@ -112,7 +111,8 @@
* @param const char * containing the new URL
*/
-void HTTPSSLChannel::setURL( const char * cpURL)
+void HTTPSSLChannel::
+setURL( const char * cpURL)
{
m_URL.setURL( cpURL);
}
@@ -125,7 +125,8 @@
* @return URL & current URL object
*/
-URL & HTTPSSLChannel::getURLObject()
+URL & HTTPSSLChannel::
+getURLObject()
{
return m_URL;
}
@@ -142,26 +143,23 @@
* returned flag will only be returned on a successful outcome).
*/
-bool HTTPSSLChannel::open() throw (HTTPTransportException&)
+bool HTTPSSLChannel::
+open() throw (HTTPTransportException&)
{
- bool bSuccess = (bool) AXIS_FAIL;
+ bool bSuccess = (bool) AXIS_FAIL;
- if( m_Sock != INVALID_SOCKET)
- {
- CloseChannel();
- }
+ CloseChannel();
- m_LastError = "No Errors";
+ m_LastError = "No Errors";
- if( (bSuccess = OpenChannel()) != AXIS_SUCCESS)
- {
- throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR,
- (char *) m_LastError.c_str());
- }
+ if( (bSuccess = OpenChannel()) != AXIS_SUCCESS)
+ {
+ throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR,m_LastError.c_str());
+ }
- bSuccess = OpenSSL_Open();
+ bSuccess = OpenSSL_Open();
- return bSuccess;
+ return bSuccess;
}
/**
@@ -173,16 +171,11 @@
* of closing the channel.
*/
-bool HTTPSSLChannel::close()
+bool HTTPSSLChannel::
+close()
{
- if( m_Sock != INVALID_SOCKET)
- {
- CloseChannel();
- }
-
- m_Sock = INVALID_SOCKET;
-
- return AXIS_SUCCESS;
+ CloseChannel();
+ return AXIS_SUCCESS;
}
/**
@@ -193,9 +186,10 @@
* @return string containing last error.
*/
-const std::string & HTTPSSLChannel::GetLastErrorMsg()
+const std::string & HTTPSSLChannel::
+GetLastErrorMsg()
{
- return m_LastError;
+ return m_LastError;
}
/**
@@ -213,20 +207,18 @@
* recieved message.
*/
-const IChannel & HTTPSSLChannel::operator >> (char * msg)
+const IChannel & HTTPSSLChannel::
+operator >> (char * msg)
{
if (INVALID_SOCKET == m_Sock)
{
- // Socket not opened!
- m_LastError = "No open socket to read from.";
-
- throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET,
- (char *) m_LastError.c_str());
+ m_LastError = "Unable to perform read operation.";
+ throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET, m_LastError.c_str());
}
ReadFromSocket( msg);
- return *this;
+ return *this;
}
/**
@@ -241,24 +233,18 @@
* message to be transmitted.
*/
-const IChannel & HTTPSSLChannel::operator << (const char * msg)
+const IChannel & HTTPSSLChannel::
+operator << (const char * msg)
{
-// Check that the Tx/Rx sockets are valid (this will have been done if the
-// application has called the open method first.
if( INVALID_SOCKET == m_Sock)
{
-// Error - Writing cannot be done without having a open socket to
-// remote end. Throw an exception.
-
- m_LastError = "No valid socket open";
-
- throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET,
- (char *) m_LastError.c_str());
+ m_LastError = "Unable to perform write operation.";
+ throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET, m_LastError.c_str());
}
- WriteToSocket( msg, strlen( msg));
+ WriteToSocket( msg, strlen( msg));
- return *this;
+ return *this;
}
/**
@@ -269,7 +255,8 @@
* @param long containing timeout value in seconds
*/
-void HTTPSSLChannel::setTimeout( long lSeconds)
+void HTTPSSLChannel::
+setTimeout( long lSeconds)
{
m_lTimeoutSeconds = lSeconds;
}
@@ -282,25 +269,26 @@
* @param unsigned int containing the new server socket.
*/
-void HTTPSSLChannel::setSocket( unsigned int uiNewSocket)
+void HTTPSSLChannel::
+setSocket( unsigned int uiNewSocket)
{
m_Sock = uiNewSocket;
}
/**
* HTTPSSLChannel::setTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type,
- * const char * value)
+ * const char * value)
*
* The following list can be set using this property:-
- * SOAPACTION_HEADER - No action
- * SERVICE_URI - No action
- * OPERATION_NAME - No action
- * SOAP_MESSAGE_LENGTH - No action
- * TRANSPORT_PROPERTIES - No action
- * SECURE_PROPERTIES - No action
- * DLL_NAME - No action
- * CHANNEL_HTTP_SSL_DLL_NAME - No action
- * CHANNEL_HTTP_DLL_NAME - No action
+ * SOAPACTION_HEADER - No action
+ * SERVICE_URI - No action
+ * OPERATION_NAME - No action
+ * SOAP_MESSAGE_LENGTH - No action
+ * TRANSPORT_PROPERTIES - No action
+ * SECURE_PROPERTIES - No action
+ * DLL_NAME - No action
+ * CHANNEL_HTTP_SSL_DLL_NAME - No action
+ * CHANNEL_HTTP_DLL_NAME - No action
*
* @param AXIS_TRANSPORT_INFORMATION_TYPE contains the type of property to be
* set.
@@ -308,35 +296,37 @@
* @return boolean flag indicating success of the alteration.
*/
-bool HTTPSSLChannel::setTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type, const char* value)
+bool HTTPSSLChannel::
+setTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type, const char* value)
{
- bool bSuccess = false;
+ bool bSuccess = false;
- return bSuccess;
+ return bSuccess;
}
/**
* HTTPSSLChannel::getTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type)
*
* The following list can be retrieved using this property:-
- * SOAPACTION_HEADER - No action
- * SERVICE_URI - No action
- * OPERATION_NAME - No action
- * SOAP_MESSAGE_LENGTH - No action
- * TRANSPORT_PROPERTIES - No action
- * SECURE_PROPERTIES - No action
- * DLL_NAME - No action
- * CHANNEL_HTTP_SSL_DLL_NAME - No action
- * CHANNEL_HTTP_DLL_NAME - No action
+ * SOAPACTION_HEADER - No action
+ * SERVICE_URI - No action
+ * OPERATION_NAME - No action
+ * SOAP_MESSAGE_LENGTH - No action
+ * TRANSPORT_PROPERTIES - No action
+ * SECURE_PROPERTIES - No action
+ * DLL_NAME - No action
+ * CHANNEL_HTTP_SSL_DLL_NAME - No action
+ * CHANNEL_HTTP_DLL_NAME - No action
*
* @param AXIS_TRANSPORT_INFORMATION_TYPE contains the type of property to be
* recovered.
* @return const char * contains the value for the requested type.
*/
-const char * HTTPSSLChannel::getTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type)
+const char * HTTPSSLChannel::
+getTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type)
{
- return NULL;
+ return NULL;
}
/**
@@ -345,10 +335,11 @@
* Setup he proxy values to be used by the channel.
*
* @param const char * containing the name of the proxy host.
- * unsigned int containing the proxy port value.
+ * unsigned int containing the proxy port value.
*/
-void HTTPSSLChannel::setProxy (const char *pcProxyHost, unsigned int uiProxyPort)
+void HTTPSSLChannel::
+setProxy (const char *pcProxyHost, unsigned int uiProxyPort)
{
m_strProxyHost = pcProxyHost;
m_uiProxyPort = uiProxyPort;
@@ -356,8 +347,8 @@
}
// +--------------------------------------------------------------------------+
-// | Protected methods |
-// | ----------------- |
+// | Protected methods |
+// | ----------------- |
// +--------------------------------------------------------------------------+
/**
@@ -369,28 +360,28 @@
* @return
*/
-bool HTTPSSLChannel::OpenChannel()
+bool HTTPSSLChannel::
+OpenChannel()
{
-// This method is common to all channel implementations
- bool bSuccess = (bool) AXIS_FAIL;
+ bool bSuccess = (bool) AXIS_FAIL;
-// Create the Client (Rx) side first.
+ // Create the Client (Rx) side first.
#ifdef IPV6
- struct addrinfo aiHints;
- struct addrinfo * paiAddrInfo;
- struct addrinfo * paiAddrInfo0;
+ struct addrinfo aiHints;
+ struct addrinfo * paiAddrInfo;
+ struct addrinfo * paiAddrInfo0;
// hints is used after zero cleared
memset( &aiHints, 0, sizeof( aiHints));
- aiHints.ai_family = PF_UNSPEC; // This allows the sockets code to use
- // whatever socket family is available.
+ aiHints.ai_family = PF_UNSPEC; // This allows the sockets code to use
+ // whatever socket family is available.
aiHints.ai_socktype = SOCK_STREAM;
char szPort[7];
- const char * pszHost = m_URL.getHostName();
- unsigned int uiPort = m_URL.getPort();
+ const char * pszHost = m_URL.getHostName();
+ unsigned int uiPort = m_URL.getPort();
if( m_bUseProxy)
{
@@ -408,40 +399,32 @@
for( paiAddrInfo = paiAddrInfo0; paiAddrInfo; paiAddrInfo = paiAddrInfo->ai_next)
{
m_Sock = socket( paiAddrInfo->ai_family,
- paiAddrInfo->ai_socktype,
- paiAddrInfo->ai_protocol);
+ paiAddrInfo->ai_socktype,
+ paiAddrInfo->ai_protocol);
if( m_Sock < 0)
- {
continue;
- }
if( connect( m_Sock, paiAddrInfo->ai_addr, paiAddrInfo->ai_addrlen) < 0)
{
// Cannot open a channel to the remote end, shutting down the
// channel and then throw an exception.
// Before we do anything else get the last error message;
- long dw = GETLASTERROR
+ long dwError = GETLASTERROR;
- CloseChannel();
+ CloseChannel();
freeaddrinfo( paiAddrInfo0);
-
- string * message = PLATFORM_GET_ERROR_MESSAGE( dw);
- char fullMessage[600];
-
- sprintf( fullMessage,
- "Failed to open connection to server: \n \
- hostname='%s'\n\
- port='%d'\n\
- Error Message='%s'\
- Error Code='%d'\n",
- m_URL.getHostName(), m_URL.getPort(), message->c_str(), (int) dw);
-
- delete( message);
- throw HTTPTransportException( CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED,
- fullMessage);
+ char pcErr[64], pcPort[64];
+ sprintf(pcErr,"%d - ",(int)dwError);
+ sprintf(pcPort,"%d",(int)m_URL.getPort());
+
+ string fullMessage = "Failed to open connection to server " +
+ string(m_URL.getHostName()) + " at port " + string(pcPort) +
+ ". Error " + string(pcErr) + PLATFORM_GET_ERROR_MESSAGE( dwError );
+
+ throw HTTPTransportException( CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED, fullMessage.c_str());
}
break;
@@ -459,101 +442,87 @@
throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CREATE_ERROR);
}
- bSuccess = AXIS_SUCCESS;
+ bSuccess = AXIS_SUCCESS;
#else // IPV6 not defined
if( (m_Sock = socket( PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
- {
- m_LastError = "Could not Create a socket.";
+ {
+ m_LastError = "Could not Create a socket.";
+
+ return bSuccess;
+ }
+
+ // If the transport was initilised, then create client and server sockets.
+ sockaddr_in clAddr;
+
+ clAddr.sin_family = AF_INET; // AF_INET (address family Internet).
+ clAddr.sin_port = 0; // No Specify Port required.
+ clAddr.sin_addr.s_addr = INADDR_ANY;
+
+ // Attempt to bind the client to the client socket.
+ if( bind( m_Sock, (struct sockaddr *) &clAddr, sizeof( clAddr)) == SOCKET_ERROR)
+ {
+ CloseChannel();
+ m_LastError = "Error whilst binding. Cannot open a channel to the remote end.";
+ return bSuccess;
+ }
- return bSuccess;
- }
+ // Although the above fragment makes use of the bind() API, it would be
+ // just as effective to skip over this call as there are no specific
+ // local port ID requirements for this client. The only advantage that
+ // bind() offers is the accessibility of the port which the system
+ // chose via the .sin_port member of the cli_addr structure which will
+ // be set upon success of the bind() call.
+
+ // Create the Server (Tx) side.
+
+ sockaddr_in svAddr;
+ struct hostent * pHostEntry = NULL;
+ const char * host = m_URL.getHostName();
+ unsigned int port = m_URL.getPort();
-// If the transport was initilised, then create client and server sockets.
- sockaddr_in clAddr;
+ if( m_bUseProxy)
+ {
+ port = m_uiProxyPort;
+ host = m_strProxyHost.c_str();
+ }
- clAddr.sin_family = AF_INET; // AF_INET (address family Internet).
- clAddr.sin_port = 0; // No Specify Port required.
- clAddr.sin_addr.s_addr = INADDR_ANY;
-
-// Attempt to bind the client to the client socket.
- if( bind( m_Sock, (struct sockaddr *) &clAddr, sizeof( clAddr)) == SOCKET_ERROR)
- {
-// Error whilst binding. Cannot open a channel to the remote end,
-// shutting down the channel and then throw an exception.
- CloseChannel();
-
- m_LastError = "Error whilst binding. Cannot open a channel to the remote end,";
-
- return bSuccess;
- }
-
-// Although the above fragment makes use of the bind() API, it would be
-// just as effective to skip over this call as there are no specific
-// local port ID requirements for this client. The only advantage that
-// bind() offers is the accessibility of the port which the system
-// chose via the .sin_port member of the cli_addr structure which will
-// be set upon success of the bind() call.
-
-// Create the Server (Tx) side.
-
- sockaddr_in svAddr;
- struct hostent * pHostEntry = NULL;
- const char * host = m_URL.getHostName();
- unsigned int port = m_URL.getPort();
-
- if( m_bUseProxy)
- {
- port = m_uiProxyPort;
- host = m_strProxyHost.c_str();
- }
-
- svAddr.sin_family = AF_INET;
- svAddr.sin_port = htons( port);
-
-// Probably this is the host-name of the server we are connecting to...
- if( (pHostEntry = gethostbyname( host)))
- {
- svAddr.sin_addr.s_addr = ((struct in_addr *) pHostEntry->h_addr)->s_addr;
- }
- else
- {
-// No this is the IP address
- svAddr.sin_addr.s_addr = inet_addr( host);
- }
-
-// Attempt to connect to the remote server.
- if( connect( m_Sock, (struct sockaddr *) &svAddr, sizeof (svAddr)) == SOCKET_ERROR)
- {
-// Cannot open a channel to the remote end, shutting down the
-// channel and then throw an exception.
-
-// Before we do anything else get the last error message;
- long dw = GETLASTERROR
- CloseChannel();
-
-
- string* message = PLATFORM_GET_ERROR_MESSAGE(dw);
-
- char fullMessage[600];
- sprintf(fullMessage,
- "Failed to open connection to server: \n \
- hostname='%s'\n\
- port='%d'\n\
- Error Message='%s'\
- Error Code='%d'\n",
- m_URL.getHostName(), m_URL.getPort(), message->c_str(), dw);
-
- delete(message);
-
- m_LastError = fullMessage;
-
- return bSuccess;
- }
- else
- {
- bSuccess = AXIS_SUCCESS;
- }
+ svAddr.sin_family = AF_INET;
+ svAddr.sin_port = htons( port);
+
+ // Probably this is the host-name of the server we are connecting to...
+ if( (pHostEntry = gethostbyname( host)))
+ {
+ svAddr.sin_addr.s_addr = ((struct in_addr *) pHostEntry->h_addr)->s_addr;
+ }
+ else
+ {
+ // No this is the IP address
+ svAddr.sin_addr.s_addr = inet_addr( host);
+ }
+
+ // Attempt to connect to the remote server.
+ if( connect( m_Sock, (struct sockaddr *) &svAddr, sizeof (svAddr)) == SOCKET_ERROR)
+ {
+ long dwError = GETLASTERROR;
+ CloseChannel();
+
+ char pcErr[64], pcPort[64];
+ sprintf(pcErr,"%d - ",(int)dwError);
+ sprintf(pcPort,"%d",(int)m_URL.getPort());
+
+ string fullMessage = "Failed to open connection to server " +
+ string(m_URL.getHostName()) + " at port " + string(pcPort) +
+ ". Error " + string(pcErr) + PLATFORM_GET_ERROR_MESSAGE( dwError );
+
+ m_LastError = fullMessage;
+
+ return bSuccess;
+ }
+ else
+ {
+ bSuccess = AXIS_SUCCESS;
+ }
#endif // IPV6
@@ -583,17 +552,18 @@
* @return
*/
-void HTTPSSLChannel::CloseChannel()
+void HTTPSSLChannel::
+CloseChannel()
{
- if( INVALID_SOCKET != m_Sock) // Check if socket already closed : AXISCPP-185
- {
+ if( INVALID_SOCKET != m_Sock)
+ {
#ifdef WIN32
- closesocket( m_Sock);
+ closesocket( m_Sock);
#else
- ::close( m_Sock);
+ ::close( m_Sock);
#endif
- m_Sock = INVALID_SOCKET; // fix for AXISCPP-185
- }
+ m_Sock = INVALID_SOCKET;
+ }
}
/**
@@ -605,48 +575,47 @@
* @return
*/
-bool HTTPSSLChannel::StartSockets()
+bool HTTPSSLChannel::
+StartSockets()
{
- bool bSuccess = false;
+ bool bSuccess = false;
#ifdef WIN32
- WSADATA wsaData; // Contains vendor-specific information, such as the
- // maximum number of sockets available and the maximum
- // datagram size.
+ WSADATA wsaData; // Contains vendor-specific information, such as the
+ // maximum number of sockets available and the maximum
+ // datagram size.
-// wsaData filled by Windows Sockets DLLs.
+ // wsaData filled by Windows Sockets DLLs.
if( WSAStartup( WS_VERSION_REQD, &wsaData))
{
-// Error - Could not setup underlying Windows socket transport mechanism.
- m_LastError = "WinSock DLL not responding.";
+ m_LastError = "WinSock DLL not responding.";
}
else
{
-// Query to see whether the available version matches what is required
- if ((LOBYTE( wsaData.wVersion) < WS_VERSION_MAJOR()) ||
- (LOBYTE( wsaData.wVersion) == WS_VERSION_MAJOR() &&
- HIBYTE( wsaData.wVersion) < WS_VERSION_MINOR()))
- {
-// Error - Underlying Windows socket transport version is not compatible with what is required.
- char szErrorBuffer[100];
-
- sprintf( szErrorBuffer,
- "Windows Sockets version %d.%d is not supported by winsock2.dll",
- LOBYTE( wsaData.wVersion),
- HIBYTE( wsaData.wVersion));
-
- m_LastError = szErrorBuffer;
-
- StopSockets();
- }
- else
- {
- bSuccess = true;
- }
+ // Query to see whether the available version matches what is required
+ if ((LOBYTE( wsaData.wVersion) < WS_VERSION_MAJOR()) ||
+ (LOBYTE( wsaData.wVersion) == WS_VERSION_MAJOR() &&
+ HIBYTE( wsaData.wVersion) < WS_VERSION_MINOR()))
+ {
+ // Error - Underlying Windows socket transport version is not compatible with what is required.
+ char szErrorBuffer[100];
+
+ sprintf( szErrorBuffer,
+ "Windows Sockets version %d.%d is not supported by winsock2.dll",
+ LOBYTE( wsaData.wVersion),
+ HIBYTE( wsaData.wVersion));
+
+ m_LastError = szErrorBuffer;
+
+ StopSockets();
+ }
+ else
+ {
+ bSuccess = true;
+ }
}
#else
- /* cout << "no need for linux" << endl; */
/* other OS specific Intitialization goes here */
- bSuccess = true;
+ bSuccess = true;
#endif
return bSuccess;
@@ -661,10 +630,11 @@
* @return
*/
-void HTTPSSLChannel::StopSockets()
+void HTTPSSLChannel::
+StopSockets()
{
#ifdef WIN32
- WSACleanup();
+ WSACleanup();
#endif // WIN32
}
@@ -674,10 +644,11 @@
* @return int
*/
-int HTTPSSLChannel::applyTimeout()
+int HTTPSSLChannel::
+applyTimeout()
{
- fd_set set;
- struct timeval timeout;
+ fd_set set;
+ struct timeval timeout;
// Initialize the file descriptor set.
FD_ZERO( &set);
@@ -699,7 +670,8 @@
* @return int
*/
-int HTTPSSLChannel::ReadFromSocket( char * pszRxBuffer)
+int HTTPSSLChannel::
+ReadFromSocket( char * pszRxBuffer)
{
int nByteRecv = 0;
@@ -708,21 +680,30 @@
if(nByteRecv < 0)
{
// failed SSL_read
- if( !bNoExceptionOnForceClose)
- {
- OpenSSL_SetSecureError( SSL_get_error( m_sslHandle, nByteRecv));
- }
+ if( !bNoExceptionOnForceClose)
+ {
+ OpenSSL_SetSecureError( SSL_get_error( m_sslHandle, nByteRecv));
+ }
OpenSSL_Close();
- close();
- m_Sock = INVALID_SOCKET; // fix for AXISCPP-185
+ close();
+ m_Sock = INVALID_SOCKET; // fix for AXISCPP-185
}
- else
+ else if ( 0 == nByteRecv )
+ {
+ // read-side of socket is closed - anytime we come down expecting to read something
+ // and read-side is closed means that there must be a parsing bug in http transport level.
+ OpenSSL_Close();
+ close();
+ m_LastError = "Remote side of socket has been closed.";
+ throw HTTPTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR, m_LastError.c_str());
+ }
+ else
{
*(pszRxBuffer + nByteRecv) = '\0';
}
- return nByteRecv;
+ return nByteRecv;
}
/**
@@ -733,9 +714,10 @@
* @return int
*/
-int HTTPSSLChannel::WriteToSocket( const char * psTxBuffer, int iSize)
+int HTTPSSLChannel::
+WriteToSocket( const char * psTxBuffer, int iSize)
{
- int nByteSent;
+ int nByteSent;
nByteSent = SSL_write( m_sslHandle, (char *) psTxBuffer, iSize);
@@ -747,7 +729,7 @@
OpenSSL_Close();
}
- return nByteSent;
+ return nByteSent;
}
/**
@@ -758,13 +740,14 @@
* @return int
*/
-void HTTPSSLChannel::OpenSSL_Initialise()
+void HTTPSSLChannel::
+OpenSSL_Initialise()
{
-// Lets get nice error messages
- SSL_load_error_strings();
+ // Lets get nice error messages
+ SSL_load_error_strings();
-// Setup all the global SSL stuff
- SSLeay_add_ssl_algorithms();
+ // Setup all the global SSL stuff
+ SSLeay_add_ssl_algorithms();
}
/**
@@ -775,11 +758,12 @@
* @return int
*/
-bool HTTPSSLChannel::OpenSSL_Open()
+bool HTTPSSLChannel::
+OpenSSL_Open()
{
- SSL_METHOD * req_method = SSLv23_client_method();
- bool bSuccess = (bool) AXIS_FAIL;
- int iSSLErrorIndex = 0;
+ SSL_METHOD * req_method = SSLv23_client_method();
+ bool bSuccess = (bool) AXIS_FAIL;
+ int iSSLErrorIndex = 0;
m_sslContext = SSL_CTX_new( req_method);
@@ -787,45 +771,45 @@
{
iSSLErrorIndex = ERR_get_error();
-// OpenSSL documents that this must be at least 120 bytes long.
- char szSSLErrorBuffer[120];
+ // OpenSSL documents that this must be at least 120 bytes long.
+ char szSSLErrorBuffer[120];
ERR_error_string( iSSLErrorIndex, szSSLErrorBuffer);
- m_LastError = szSSLErrorBuffer;
+ m_LastError = szSSLErrorBuffer;
OpenSSL_Close();
throw HTTPTransportException( CLIENT_SSLCHANNEL_CONTEXT_CREATE_ERROR,
- szSSLErrorBuffer);
+ szSSLErrorBuffer);
}
SSL_CTX_set_verify( m_sslContext,
- SSL_VERIFY_NONE, // SSL_VERIFY_PEER
- cert_verify_callback);
+ SSL_VERIFY_NONE, // SSL_VERIFY_PEER
+ cert_verify_callback);
-// Lets make an SSL structure
+ // Lets make an SSL structure
m_sslHandle = SSL_new( m_sslContext);
SSL_set_connect_state( m_sslHandle);
-// pass the raw socket into the SSL layers
+ // pass the raw socket into the SSL layers
SSL_set_fd( m_sslHandle, m_Sock);
iSSLErrorIndex = SSL_connect( m_sslHandle);
-// 1 is fine
-// 0 is "not successful but was shut down controlled"
-// <0 is "handshake was not successful, because a fatal error occurred"
- if( iSSLErrorIndex <= 0)
- {
- OpenSSL_SetSecureError( iSSLErrorIndex);
- }
- else
- {
- bSuccess = (bool) AXIS_SUCCESS;
- }
+ // 1 is fine
+ // 0 is "not successful but was shut down controlled"
+ // <0 is "handshake was not successful, because a fatal error occurred"
+ if( iSSLErrorIndex <= 0)
+ {
+ OpenSSL_SetSecureError( iSSLErrorIndex);
+ }
+ else
+ {
+ bSuccess = (bool) AXIS_SUCCESS;
+ }
- return bSuccess;
+ return bSuccess;
}
/**
@@ -836,7 +820,8 @@
* @return int
*/
-int HTTPSSLChannel::OpenSSL_Close()
+int HTTPSSLChannel::
+OpenSSL_Close()
{
if( m_sslHandle)
{
@@ -853,7 +838,7 @@
m_sslContext = NULL;
}
- return 0;
+ return 0;
}
/**
@@ -864,12 +849,13 @@
* @return int
*/
-void HTTPSSLChannel::OpenSSL_SetSecureError( int iError)
+void HTTPSSLChannel::
+OpenSSL_SetSecureError( int iError)
{
switch( iError)
{
- case SSL_ERROR_NONE: // this is not an error
- case SSL_ERROR_ZERO_RETURN: // no more data
+ case SSL_ERROR_NONE: // this is not an error
+ case SSL_ERROR_ZERO_RETURN: // no more data
break;
case SSL_ERROR_WANT_READ:
@@ -884,56 +870,55 @@
OpenSSL_Close();
- m_LastError = "SSL_ERROR_SYSCALL";
+ m_LastError = "SSL_ERROR_SYSCALL";
- throw HTTPTransportException( CLIENT_SSLCHANNEL_ERROR,
- (char *) m_LastError.c_str());
-
- break;
+ throw HTTPTransportException( CLIENT_SSLCHANNEL_ERROR, m_LastError.c_str());
+ break;
}
case SSL_ERROR_SSL:
{
-// A failure in the SSL library occurred, usually a protocol error. The
-// OpenSSL error queue contains more information on the error.
- int sslerror = ERR_get_error();
+ // A failure in the SSL library occurred, usually a protocol error. The
+ // OpenSSL error queue contains more information on the error.
+ int sslerror = ERR_get_error();
-// OpenSSL documents that this must be at least 120 bytes long.
+ // OpenSSL documents that this must be at least 120 bytes long.
char error_buffer[120];
ERR_error_string( sslerror, error_buffer);
OpenSSL_Close();
- m_LastError = error_buffer;
+ m_LastError = error_buffer;
throw HTTPTransportException( CLIENT_SSLCHANNEL_ERROR, error_buffer);
- break;
+ break;
}
default:
-// openssl/ssl.h says "look at error stack/return value/errno"
+ // openssl/ssl.h says "look at error stack/return value/errno"
{
-// A failure in the SSL library occurred, usually a protocol error. The
-// OpenSSL error queue contains more information on the error.
+ // A failure in the SSL library occurred, usually a protocol error. The
+ // OpenSSL error queue contains more information on the error.
int sslerror = ERR_get_error();
-// OpenSSL documents that this must be at least 120 bytes long.
+ // OpenSSL documents that this must be at least 120 bytes long.
char error_buffer[120];
ERR_error_string( sslerror, error_buffer);
OpenSSL_Close();
- m_LastError = error_buffer;
+ m_LastError = error_buffer;
throw HTTPTransportException( CLIENT_SSLCHANNEL_ERROR, error_buffer);
}
}
}
-void HTTPSSLChannel::closeQuietly( bool bNoExceptionOnForceClose_Update)
+void HTTPSSLChannel::
+closeQuietly( bool bNoExceptionOnForceClose_Update)
{
- bNoExceptionOnForceClose = bNoExceptionOnForceClose_Update;
+ bNoExceptionOnForceClose = bNoExceptionOnForceClose_Update;
}
Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp Mon Nov 27 21:38:11 2006
@@ -119,13 +119,8 @@
~HTTPTransport()
{
delete [] m_pcEndpointUri;
- m_pcEndpointUri = NULL;
-
delete m_pChannelFactory;
- m_pChannelFactory = NULL;
-
delete [] m_pszRxBuffer;
- m_pszRxBuffer = NULL;
}
/*
@@ -220,15 +215,8 @@
if( m_pActiveChannel->open() != AXIS_SUCCESS)
{
- int iStringLength = m_pActiveChannel->GetLastErrorMsg().length() + 1;
- const char * pszLastError = new char[iStringLength];
-
- memcpy( (void *) pszLastError,
- m_pActiveChannel->GetLastErrorMsg().c_str(),
- iStringLength);
-
throw HTTPTransportException( CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED,
- (char *) pszLastError);
+ m_pActiveChannel->GetLastErrorMsg().c_str());
}
}
return AXIS_SUCCESS;
@@ -292,13 +280,6 @@
utf8Buf = NULL;
#endif
}
- catch( HTTPTransportException & e)
- {
- if (utf8Buf) free(utf8Buf);
- m_strBytesToSend = "";
- m_strHeaderBytesToSend = "";
- throw;
- }
catch( AxisException & e)
{
if (utf8Buf) free(utf8Buf);
@@ -1512,13 +1493,8 @@
// not be assumed that the HTTP header will be read in one block, thus there
// must be processing that first identifies the beginning of the HTTP header
// block (i.e. looks for 'HTTP') and then additional processing that identifies
- // the end of the HTTP header block (i.e. looks for CR LF CR LF). To stop the
- // search becoming 'stuck' because of an incomplete, corrupt or unexpected
- // message an iteration count has been added (this could become configurable if
- // the user needs to remove this feature if the server is particularily slow,
- // etc.).
+ // the end of the HTTP header block (i.e. looks for CR LF CR LF).
bool bHTTPHeaderFound = false;
- int iIterationCount = 100;
m_strReceived = "";
@@ -1533,12 +1509,6 @@
// Add the new message part to the received string.
m_strReceived += m_pszRxBuffer;
- // Do iteration processing.
- if( strlen( m_pszRxBuffer) > 0)
- iIterationCount = 100;
- else
- iIterationCount--;
-
// Check for beginning and end of HTTP header.
if( m_strReceived.find( ASCII_S_HTTP) != std::string::npos &&
m_strReceived.find( ASCII_S_CRLFCRLF) != std::string::npos)
@@ -1546,14 +1516,7 @@
bHTTPHeaderFound = true;
}
}
- while( !bHTTPHeaderFound && iIterationCount > 0);
-
- // If the HTTP header was not found in the given number of iterations then throw an exception.
- if( iIterationCount == 0)
- {
- throw HTTPTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR,
- "Timed out waiting for HTTP header message.");
- }
+ while(!bHTTPHeaderFound);
}
void HTTPTransport::
@@ -1644,39 +1607,27 @@
{
m_GetBytesState = eWaitingForHTTPHeader;
- m_strResponseHTTPStatusMessage = std::string( "\n Server sent HTTP error: '") +
+ m_strResponseHTTPStatusMessage = std::string( "Server sent HTTP error: '") +
m_strResponseHTTPStatusMessage + std::string("'\n");
- throw HTTPTransportException( SERVER_TRANSPORT_HTTP_EXCEPTION,
- const_cast <char *> (m_strResponseHTTPStatusMessage.c_str()));
+ throw HTTPTransportException( SERVER_TRANSPORT_HTTP_EXCEPTION, m_strResponseHTTPStatusMessage.c_str());
}
}
bool HTTPTransport::
getNextDataPacket( const char * pcszExceptionMessage)
{
- int iIterationCount = 100;
bool bDataRead = false;
- do
- {
- // Read whatever part of the response message that has arrived at the active channel socket.
- m_pszRxBuffer[0] = '\0';
- *m_pActiveChannel >> m_pszRxBuffer;
-
- // Do iteration processing.
- if( strlen( m_pszRxBuffer) == 0)
- iIterationCount--;
- else
- bDataRead = true;
- }
- while( !bDataRead && iIterationCount > 0);
+ // Read whatever part of the response message that has arrived at the active channel socket.
+ m_pszRxBuffer[0] = '\0';
+ *m_pActiveChannel >> m_pszRxBuffer;
- if( bDataRead)
+ if( strlen( m_pszRxBuffer) > 0)
{
m_strReceived += m_pszRxBuffer;
-
m_iBytesLeft = m_strReceived.length();
+ bDataRead = true;
}
else if( m_strReceived.length() == 0)
{
@@ -1684,12 +1635,7 @@
if( pcszExceptionMessage != NULL && strlen( pcszExceptionMessage) > 0)
{
- int iStringLength = strlen( pcszExceptionMessage) + 1;
- const char * pszLastError = new char[iStringLength];
-
- memcpy( (void *) pszLastError, pcszExceptionMessage, iStringLength);
-
- throw HTTPTransportException( SERVER_TRANSPORT_HTTP_EXCEPTION, (char *) pszLastError);
+ throw HTTPTransportException( SERVER_TRANSPORT_HTTP_EXCEPTION, pcszExceptionMessage);
}
}
Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPTransportException.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/HTTPTransportException.hpp?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPTransportException.hpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPTransportException.hpp Mon Nov 27 21:38:11 2006
@@ -38,7 +38,7 @@
}
// constructor
- HTTPTransportException(const HTTPTransportException& e): AxisException (e) { }
+ HTTPTransportException(const AxisException& e): AxisException (e) { }
// destructor
virtual ~HTTPTransportException() throw() { }
Modified: webservices/axis/trunk/c/src/xml/AxisParseException.h
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/xml/AxisParseException.h?view=diff&rev=479917&r1=479916&r2=479917
==============================================================================
--- webservices/axis/trunk/c/src/xml/AxisParseException.h (original)
+++ webservices/axis/trunk/c/src/xml/AxisParseException.h Mon Nov 27 21:38:11 2006
@@ -35,7 +35,7 @@
setMessage(iExceptionCode, "AxisParseException:", pcMessage);
}
- AxisParseException(const AxisParseException& e): AxisException(e) { }
+ AxisParseException(const AxisException& e): AxisException(e) { }
virtual ~AxisParseException() throw() { }
};
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org