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 ha...@apache.org on 2005/01/04 19:26:24 UTC
cvs commit: ws-axis/c/src/transport/axis2/ipv6 IPV6Channel.cpp
hawkeye 2005/01/04 10:26:24
Modified: c/src/transport/axis2 Axis2Transport.cpp Channel.cpp
Channel.h
c/src/transport/axis2/ipv6 IPV6Channel.cpp
Log:
Added better error messages to AxisTransport2 when it fails to get a connection. This message is put into the Exception. this is a stop-gap as this sort of function should be standard on all. platforms (I've only implemented on windows) and available through the Platform specific macros/classes.
Revision Changes Path
1.35 +2 -2 ws-axis/c/src/transport/axis2/Axis2Transport.cpp
Index: Axis2Transport.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/transport/axis2/Axis2Transport.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- Axis2Transport.cpp 4 Jan 2005 10:39:35 -0000 1.34
+++ Axis2Transport.cpp 4 Jan 2005 18:26:23 -0000 1.35
@@ -201,11 +201,11 @@
m_bReopenConnection = false;
if (!m_pChannel->open ())
{
- int iStringLength = m_pChannel->GetLastError ().length () + 1;
+ int iStringLength = m_pChannel->GetLastErrorMsg ().length () + 1;
const char *pszLastError = new char[iStringLength];
memcpy ((void *) pszLastError,
- m_pChannel->GetLastError ().c_str (), iStringLength);
+ m_pChannel->GetLastErrorMsg ().c_str (), iStringLength);
;
throw
1.11 +34 -114 ws-axis/c/src/transport/axis2/Channel.cpp
Index: Channel.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/transport/axis2/Channel.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Channel.cpp 22 Dec 2004 09:23:10 -0000 1.10
+++ Channel.cpp 4 Jan 2005 18:26:24 -0000 1.11
@@ -35,26 +35,17 @@
*/
Channel::Channel ():m_Sock (INVALID_SOCKET), m_iMsgLength( 0), m_sMsg(NULL), m_lTimeoutSeconds(0)
{
-#ifdef FJPDebug
-printf( ">Channel::Channel()\n");
-#endif
#ifdef WIN32
m_lTimeoutSeconds = 10;
#endif
-#ifdef FJPDebug
-printf( "<Channel::Channel()\n");
-#endif
}
/** Channel::~Channel() Destructor
*/
Channel::~Channel ()
{
-#ifdef FJPDebug
-printf( ">Channel::~Channel()\n");
-#endif
// If the socket value is not invalid, then close the socket before
// deleting the Channel object.
@@ -66,9 +57,6 @@
if (m_sMsg)
delete [] m_sMsg;
-#ifdef FJPDebug
-printf( "<Channel::~Channel()\n");
-#endif
}
/** Channel::setURL( URL) sets the URL for the channel.
@@ -78,9 +66,6 @@
*/
void Channel::setURL(const char* cpURL)
{
-#ifdef FJPDebug
-printf( ">Channel::setURL( const char* cpURL=%s)\n", cpURL);
-#endif
// Set the Channel URL to the new value.
// NB: This will cause problems if the new URL is diferent in type from the
@@ -88,9 +73,6 @@
// problems will occur because each type operates differently.
m_URL.setURL( cpURL);
-#ifdef FJPDebug
-printf( "<Channel::setURL()\n");
-#endif
}
/** Channel::getURL() gets the URL for the channel.
@@ -100,12 +82,6 @@
*/
const char* Channel::getURL()
{
-#ifdef FJPDebug
-printf( ">Channel::getURL()\n");
-#endif
-#ifdef FJPDebug
-printf( "<Channel::getURL() = %s\n", m_URL.getURL());
-#endif
// Return the URL currently assicated with the channel object.
return m_URL.getURL();
@@ -127,9 +103,6 @@
Channel::open () //std::string & p_RemoteNode, unsigned short p_RemoteEnd)
throw (AxisTransportException&)
{
-#ifdef FJPDebug
-printf( ">Channel::open()\n");
-#endif
// if there is an open socket already, close it first
if (m_Sock != INVALID_SOCKET)
closeChannel();
@@ -138,9 +111,6 @@
// then thrown an exeption.
if( !Init())
{
-#ifdef FJPDebug
-printf( "<Channel::open()=exception\n");
-#endif
throw AxisTransportException( SERVER_TRANSPORT_CHANNEL_INIT_ERROR);
}
@@ -162,9 +132,6 @@
// shutting down the channel and then throw an exception.
closeChannel();
-#ifdef FJPDebug
-printf( "<Channel::open()=exception\n");
-#endif
throw AxisTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR);
}
@@ -200,14 +167,45 @@
{
// Cannot open a channel to the remote end, shutting down the
// channel and then throw an exception.
+#ifdef WIN32
+ // Before we do anything else get the last error message;
+ // I'd like to put the getting of the error message into platform specifics but not sure how !
+ // I think it would be nicer to make the platform specifics a class and not just macros.
+ // That way we could have e.g. char* Windows#getLastErrorMessage()
+ long dw = GetLastError();
+#endif
closeChannel();
-#ifdef FJPDebug
-printf( "<Channel::open()=exception\n");
-#endif
+#ifdef WIN32
+ TCHAR szBuf[200];
+ LPVOID lpMsgBuf;
+
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ dw,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0, NULL );
+
+ sprintf(szBuf,
+ "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(), lpMsgBuf, dw);
+
+
+ LocalFree(lpMsgBuf);
+ throw AxisTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR, szBuf);
+#endif
+ // else we don't know how to do this for non-windows platforms
throw AxisTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR);
}
+
}
else
{
@@ -215,16 +213,10 @@
// an exception.
closeChannel();
-#ifdef FJPDebug
-printf( "<Channel::open()=exeption\n");
-#endif
throw AxisTransportException( SERVER_TRANSPORT_SOCKET_CREATE_ERROR);
}
-#ifdef FJPDebug
-printf( "<Channel::open()=true, m_Sock=%d\n", m_Sock);
-#endif
/* Turn off the Nagle algorithm - Patch by Steve Hardy */
@@ -251,9 +243,6 @@
bool Channel::Init ()
{
-#ifdef FJPDebug
-printf( ">Channel::Init()\n");
-#endif
#ifdef WIN32
WSADATA wsaData; // Contains vendor-specific information, such as the
@@ -267,10 +256,6 @@
// mechanism.
m_LastErr = "WinSock DLL not responding.";
-#ifdef FJPDebug
-printf( "<Channel::Init()=false\n");
-#endif
-
return false;
}
else
@@ -292,9 +277,6 @@
closeChannel();
-#ifdef FJPDebug
-printf( "<Channel::Init()=false\n");
-#endif
return false;
}
@@ -304,9 +286,6 @@
/* other OS specific Intitialization goes here */
#endif
-#ifdef FJPDebug
-printf( "<Channel::Init()=true\n");
-#endif
return true;
}
@@ -331,9 +310,6 @@
*/
const Channel &Channel::operator << (const char *msg)
{
-#ifdef FJPDebug
-printf( ">Channel::operator << msg=%s, ", msg);
-#endif
// Check that the Tx/Rx sockets are valid (this will have been done if the
// application has called the open method first.
@@ -341,9 +317,6 @@
{
// Error - Writing cannot be done without having a open socket to
// remote end. Throw an exception.
-#ifdef FJPDebug
-printf( "<Channel::operator << exception\n");
-#endif
throw AxisTransportException( SERVER_TRANSPORT_INVALID_SOCKET);
}
@@ -356,11 +329,6 @@
size = m_iMsgLength;
}
-#ifdef FJPDebug
-printf( "size=%d, m_Sock=%d\n", size, m_Sock);
-
-hexOutput( (char *) msg, size);
-#endif
if( (nByteSent = send( m_Sock, msg, size, MSG_DONTROUTE)) == SOCKET_ERROR)
{
@@ -368,16 +336,10 @@
// throw an exception.
closeChannel();
-#ifdef FJPDebug
-printf( "<Channel::operator << exception\n");
-#endif
throw AxisTransportException(SERVER_TRANSPORT_OUTPUT_STREAMING_ERROR);
}
-#ifdef FJPDebug
-printf( "<Channel::operator <<\n");
-#endif
return *this;
}
@@ -399,9 +361,6 @@
*/
const Channel &Channel::operator >> (std::string & msg)
{
-#ifdef FJPDebug
-printf( ">Channel::operator >> m_Sock=%d\n", m_Sock);
-#endif
msg = "";
@@ -411,9 +370,6 @@
// streaming error on undefined channel; please open the
// channel first
-#ifdef FJPDebug
-printf( "<Channel::operator >> exception=SERVER_TRANSPORT_INVALID_SOCKET\n");
-#endif
throw AxisTransportException( SERVER_TRANSPORT_INVALID_SOCKET);
}
@@ -445,9 +401,6 @@
{
// Error
-#ifdef FJPDebug
-printf( "<Channel::operator >> exception=SERVER_TRANSPORT_TIMEOUT_EXCEPTION\n");
-#endif
// Select SOCKET_ERROR. Channel error while waiting for timeout
throw AxisTransportException( SERVER_TRANSPORT_TIMEOUT_EXCEPTION,
@@ -459,9 +412,6 @@
// Timeout expired - select timeout expired.
// Channel error connection timeout before receving
-#ifdef FJPDebug
-printf( "<Channel::operator >> exception=SERVER_TRANSPORT_TIMEOUT_EXPIRED\n");
-#endif
throw AxisTransportException( SERVER_TRANSPORT_TIMEOUT_EXPIRED,
"Channel error: connection timed out before receving");
@@ -474,9 +424,6 @@
// Recv SOCKET_ERROR, Channel error while getting data
/* closeChannel(); */
-#ifdef FJPDebug
-printf( "<Channel::operator >> exception=SERVER_TRANSPORT_INPUT_STREAMING_ERROR\n");
-#endif
throw AxisTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR,
"Channel error while getting data");
@@ -512,12 +459,6 @@
;//printf ("execution break\n");
}
-#ifdef FJPDebug
-hexOutput( m_sMsg, m_iMsgLength);
-
-printf( "m_iMsgLength=%d\n", m_iMsgLength);
-printf( "<Channel::operator >> msg = %s\n", buf);
-#endif
return *this;
}
@@ -602,15 +543,9 @@
*/
void Channel::closeChannel ()
{
-#ifdef FJPDebug
-printf( ">Channel::closeChannel()\n");
-#endif
if( INVALID_SOCKET == m_Sock) // Check if socket already closed : AXISCPP-185
{
-#ifdef FJPDebug
-printf( "<Channel::closeChannel()\n");
-#endif
return;
}
@@ -628,9 +563,6 @@
#endif
m_Sock = INVALID_SOCKET; // fix for AXISCPP-185
-#ifdef FJPDebug
-printf( "<Channel::closeChannel()\n");
-#endif
}
/**
@@ -651,15 +583,9 @@
*/
void Channel::setTimeout(const long lSeconds)
{
-#ifdef FJPDebug
-printf( ">Channel::setTimeout(const long lSeconds=%d)\n", lSeconds);
-#endif
m_lTimeoutSeconds = lSeconds;
-#ifdef FJPDebug
-printf( "<Channel::setTimeout()\n");
-#endif
}
/**
@@ -669,9 +595,6 @@
*/
int Channel::applyTimeout()
{
-#ifdef FJPDebug
-printf( ">Channel::applyTimeout()\n");
-#endif
fd_set set;
struct timeval timeout;
@@ -685,9 +608,6 @@
timeout.tv_usec = 0;
/* select returns 0 if timeout, 1 if input available, -1 if error. */
-#ifdef FJPDebug
-printf( "<Channel::applyTimeout()\n");
-#endif
return select( FD_SETSIZE, &set, NULL, NULL, &timeout);
}
1.7 +1 -1 ws-axis/c/src/transport/axis2/Channel.h
Index: Channel.h
===================================================================
RCS file: /home/cvs/ws-axis/c/src/transport/axis2/Channel.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Channel.h 30 Nov 2004 10:35:42 -0000 1.6
+++ Channel.h 4 Jan 2005 18:26:24 -0000 1.7
@@ -106,7 +106,7 @@
virtual const Channel& operator << (const char* msg);
/* Return last error (if any). */
- virtual const std::string& GetLastError(){return m_LastErr;}
+ virtual const std::string& GetLastErrorMsg(){return m_LastErr;}
/**
* Set transport timeout.
1.7 +0 -52 ws-axis/c/src/transport/axis2/ipv6/IPV6Channel.cpp
Index: IPV6Channel.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/transport/axis2/ipv6/IPV6Channel.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- IPV6Channel.cpp 22 Dec 2004 09:23:10 -0000 1.6
+++ IPV6Channel.cpp 4 Jan 2005 18:26:24 -0000 1.7
@@ -29,26 +29,14 @@
IPV6Channel::IPV6Channel ()
{
-#ifdef FJPDebug
- printf( ">IPV6Channel::IPV6Channel()\n");
-#endif
#ifdef WIN32
-
m_lTimeoutSeconds = 10;
#endif
-
-#ifdef FJPDebug
- printf( "<IPV6Channel::IPV6Channel()\n");
-#endif
}
IPV6Channel::~IPV6Channel ()
{
-#ifdef FJPDebug
- printf( ">IPV6Channel::~IPV6Channel()\n");
-#endif
-
// If the socket value is not invalid, then close the socket before
// deleting the IPV6Channel object.
if( m_Sock != INVALID_SOCKET)
@@ -56,9 +44,6 @@
closeChannel();
}
-#ifdef FJPDebug
- printf( "<IPV6Channel::~IPV6Channel()\n");
-#endif
}
@@ -80,9 +65,6 @@
IPV6Channel::open () //std::string & p_RemoteNode, unsigned short p_RemoteEnd)
throw (AxisTransportException&)
{
-#ifdef FJPDebug
- printf( ">IPV6Channel::open()\n");
-#endif
// if there is an open socket already, close it first
if (m_Sock != INVALID_SOCKET)
closeChannel();
@@ -91,10 +73,6 @@
// then thrown an exeption.
if( !init())
{
-#ifdef FJPDebug
- printf( "<IPV6Channel::open()=exception\n");
-#endif
-
throw AxisTransportException( SERVER_TRANSPORT_CHANNEL_INIT_ERROR);
}
@@ -112,9 +90,6 @@
int err = getaddrinfo(m_URL.getHostName(), port, &hints, &addrInfo0);
if (err)
{
-#ifdef FJPDebug
- fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(err));
-#endif
throw AxisTransportException( SERVER_TRANSPORT_SOCKET_CREATE_ERROR);
}
@@ -124,9 +99,6 @@
m_Sock = socket(addrInfo->ai_family, addrInfo->ai_socktype, addrInfo->ai_protocol);
if (m_Sock < 0)
{
-#ifdef FJPDebug
- fprintf(stderr, "socket() faild: %d\n", m_Sock);
-#endif
continue;
}
@@ -136,9 +108,6 @@
// channel and then throw an exception.
closeChannel();
-#ifdef FJPDebug
- printf( "<IPV6Channel::open()=exception\n");
-#endif
free (addrInfo0);
throw AxisTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR);
continue;
@@ -155,17 +124,10 @@
// an exception.
closeChannel();
-#ifdef FJPDebug
- printf( "<IPV6Channel::open()=exeption\n");
- fprintf(stderr, "can't connect %s\n", m_URL.getHostName() );
-#endif
throw AxisTransportException( SERVER_TRANSPORT_SOCKET_CREATE_ERROR);
}
-#ifdef FJPDebug
- printf( "<IPV6Channel::open()=true, m_Sock=%d\n", m_Sock);
-#endif
/* Turn off the Nagle algorithm - Patch by Steve Hardy */
@@ -192,9 +154,6 @@
bool IPV6Channel::init ()
{
-#ifdef FJPDebug
- printf( ">IPV6Channel::init()\n");
-#endif
#ifdef WIN32
@@ -209,9 +168,6 @@
// mechanism.
m_LastErr = "WinSock DLL not addrInfoponding.";
-#ifdef FJPDebug
- printf( "<IPV6Channel::init()=false\n");
-#endif
return false;
}
@@ -234,20 +190,12 @@
closeChannel();
-#ifdef FJPDebug
- printf( "<IPV6Channel::init()=false\n");
-#endif
-
return false;
}
}
#else
/* cout << "no need for linux" << endl; */
/* other OS specific Intitialization goes here */
-#endif
-
-#ifdef FJPDebug
- printf( "<IPV6Channel::init()=true\n");
#endif
return true;