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 na...@apache.org on 2007/02/12 06:58:14 UTC
svn commit: r506306 - in /webservices/axis/trunk/c/src/transport/axis3:
HTTPChannel/HTTPChannel.cpp HTTPChannel/HTTPChannel.hpp
HTTPSSLChannel/HTTPSSLChannel.cpp HTTPSSLChannel/HTTPSSLChannel.hpp
HTTPTransport.cpp IChannel.hpp
Author: nadiramra
Date: Sun Feb 11 21:58:13 2007
New Revision: 506306
URL: http://svn.apache.org/viewvc?view=rev&rev=506306
Log:
AXISCPP-481 - connection close problems
Modified:
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/HTTPSSLChannel/HTTPSSLChannel.hpp
webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp
webservices/axis/trunk/c/src/transport/axis3/IChannel.hpp
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=506306&r1=506305&r2=506306
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.cpp Sun Feb 11 21:58:13 2007
@@ -166,7 +166,7 @@
}
/**
- * HTTPChannel::operator >> (char * msg)
+ * HTTPChannel::readBytes()
*
* This method attempts to read a message from the curently open channel. If
* there is no currently open channel, then the method throws an exception. If
@@ -180,8 +180,8 @@
* recieved message.
*/
-const IChannel & HTTPChannel::
-operator >> (char * msg)
+int HTTPChannel::
+readBytes(char *buf, int bufLen)
{
if (INVALID_SOCKET == m_Sock)
{
@@ -190,8 +190,7 @@
}
int nByteRecv = 0;
- char buf[BUF_SIZE];
- int iBufSize = BUF_SIZE - 10;
+ int iBufSize = bufLen - 10;
// If timeout set then wait for maximum amount of time for data
if( m_lTimeoutSeconds)
@@ -212,7 +211,7 @@
}
// Either timeout was not set or data available before timeout; so read
- nByteRecv = recv( m_Sock, (char *) &buf, iBufSize, 0);
+ nByteRecv = recv( m_Sock, buf, iBufSize, 0);
if (nByteRecv == SOCKET_ERROR)
{
// error on read operation
@@ -229,16 +228,13 @@
// read-side of socket is closed.
}
else if( nByteRecv)
- {
buf[nByteRecv] = '\0';
- memcpy(msg, buf, nByteRecv + 1);
- }
- return *this;
+ return nByteRecv;
}
/**
- * HTTPChannel::operator << (const char * msg)
+ * HTTPChannel::writeBytes()
*
* This method attempts to write a message to the curently open channel. If
* there is no currently open channel, then the method throws an exception. If
@@ -248,9 +244,8 @@
* @param character pointer pointing to the array of character containing the
* message to be transmitted.
*/
-
-const IChannel & HTTPChannel::
-operator << (const char * msg)
+int HTTPChannel::
+writeBytes(const char *buf, int numBytes)
{
if( INVALID_SOCKET == m_Sock)
{
@@ -258,13 +253,12 @@
throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET, m_LastError.c_str());
}
- int size = strlen( msg);
int nByteSent;
#ifdef __OS400__
- if( (nByteSent = send( m_Sock, (char *)msg, size, 0)) == SOCKET_ERROR)
+ if( (nByteSent = send( m_Sock, (char *)buf, numBytes, 0)) == SOCKET_ERROR)
#else
- if( (nByteSent = send( m_Sock, msg, size, 0)) == SOCKET_ERROR)
+ if( (nByteSent = send( m_Sock, buf, numBytes, 0)) == SOCKET_ERROR)
#endif
{
// This must be done first before closing channel in order to get actual error.
@@ -276,7 +270,7 @@
throw HTTPTransportException( SERVER_TRANSPORT_OUTPUT_STREAMING_ERROR, m_LastError.c_str());
}
- return *this;
+ return nByteSent;
}
/**
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=506306&r1=506305&r2=506306
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.hpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPChannel/HTTPChannel.hpp Sun Feb 11 21:58:13 2007
@@ -72,8 +72,8 @@
bool open() throw (HTTPTransportException&);
bool close();
const std::string & GetLastErrorMsg();
- const IChannel & operator >> (char * msg);
- const IChannel & operator << (const char * msg);
+ int readBytes(char *buf, int bufLen);
+ int writeBytes(const char *buf, int numBytes);
void setTimeout( long lSeconds);
void setSocket( unsigned int uiNewSocket);
int getSocket() {return m_Sock;}
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=506306&r1=506305&r2=506306
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp Sun Feb 11 21:58:13 2007
@@ -207,8 +207,8 @@
* recieved message.
*/
-const IChannel & HTTPSSLChannel::
-operator >> (char * msg)
+int HTTPSSLChannel::
+readBytes(char *buf, int bufLen)
{
if (INVALID_SOCKET == m_Sock)
{
@@ -216,9 +216,7 @@
throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET, m_LastError.c_str());
}
- ReadFromSocket( msg);
-
- return *this;
+ return ReadFromSocket( buf );
}
/**
@@ -233,8 +231,8 @@
* message to be transmitted.
*/
-const IChannel & HTTPSSLChannel::
-operator << (const char * msg)
+int HTTPSSLChannel::
+writeBytes(const char *buf, int numBytes)
{
if( INVALID_SOCKET == m_Sock)
{
@@ -242,9 +240,7 @@
throw HTTPTransportException( SERVER_TRANSPORT_INVALID_SOCKET, m_LastError.c_str());
}
- WriteToSocket( msg, strlen( msg));
-
- return *this;
+ return WriteToSocket( buf, numBytes);
}
/**
Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.hpp?view=diff&rev=506306&r1=506305&r2=506306
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.hpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.hpp Sun Feb 11 21:58:13 2007
@@ -74,8 +74,8 @@
bool open() throw (HTTPTransportException&);
bool close();
const std::string & GetLastErrorMsg();
- const IChannel & operator >> (char * msg);
- const IChannel & operator << (const char * msg);
+ int readBytes(char *buf, int bufLen);
+ int writeBytes(const char *buf, int numBytes);
void setTimeout( long lSeconds);
void setSocket( unsigned int uiNewSocket);
int getSocket() {return m_Sock;}
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=506306&r1=506305&r2=506306
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp Sun Feb 11 21:58:13 2007
@@ -34,7 +34,7 @@
#include "../../soap/apr_base64.h"
#include <stdio.h>
-
+
// =================================================================
// In order to parse the HTTP protocol data on an ebcdic system, we
// need to ensure that the various tokens we are looking for to distinguish
@@ -248,7 +248,7 @@
{
char *utf8Buf = NULL; // buffer for ebcdic/utf8 conversions.
- // In preperation for sending the message, calculate the size of the message by using the string length method.
+ // In preperation for sending the message, set Content-Length HTTP header.
char buff[24];
sprintf( buff, "%d", m_strBytesToSend.length ());
this->setTransportProperty ("Content-Length", buff);
@@ -256,33 +256,34 @@
// The header is now complete. The message header and message can now be transmitted.
try
{
+ const char *writeBuffer;
+ int bytesToWrite;
+
+ // Generate HTTP header string
+ writeBuffer = this->getHTTPHeaders ();
+ bytesToWrite = strlen(writeBuffer);
+
+ // Send the data
#ifndef __OS400__
- *m_pActiveChannel << this->getHTTPHeaders ();
- *m_pActiveChannel << this->m_strBytesToSend.c_str ();
+ m_pActiveChannel->writeBytes(writeBuffer, bytesToWrite);
+ m_pActiveChannel->writeBytes(this->m_strBytesToSend.c_str(), m_strBytesToSend.length());
#else
// Ebcdic (OS/400) systems need to convert the data to UTF-8. Note that free()
// is correctly used and should not be changed to delete().
- const char *buf = this->getHTTPHeaders ();
- utf8Buf = toUTF8((char *)buf, strlen(buf)+1);
- *m_pActiveChannel << utf8Buf;
+ utf8Buf = toUTF8((char *)writeBuffer, bytesToWrite+1);
+ m_pActiveChannel->writeBytes(utf8Buf, strlen(utf8Buf));
free(utf8Buf);
utf8Buf = NULL;
utf8Buf = toUTF8((char *)this->m_strBytesToSend.c_str(), this->m_strBytesToSend.length()+1);
- *m_pActiveChannel << utf8Buf;
+ m_pActiveChannel->writeBytes(utf8Buf, strlen(utf8Buf));
free(utf8Buf);
utf8Buf = NULL;
#endif
}
- catch( AxisException & e)
- {
- if (utf8Buf) free(utf8Buf);
- m_strBytesToSend = "";
- m_strHeaderBytesToSend = "";
- throw;
- }
catch(...)
{
- if (utf8Buf) free(utf8Buf);
+ if (utf8Buf)
+ free(utf8Buf);
m_strBytesToSend = "";
m_strHeaderBytesToSend = "";
throw;
@@ -544,18 +545,14 @@
m_iBytesLeft = m_strReceived.length();
- // This bit of code should not be necessary, but just in case...
+ // This bit of code should not be necessary, but just in case...???
if( m_GetBytesState == eWaitingForHTTPHeader)
break;
}
case eSOAPMessageIsChunked:
- {
- // At this point it is assumed that m_strReceived contains the block of unprocessed data.
- // m_iBytesLeft is the length of text/data in m_strReceived is a 'char *' type copy of
- // the m_strReceived string. NB: It is assumed that all of these variables ARE in sync
- // at this point.
-
+ {
+ // We are processing a response that is chunked...
if( m_GetBytesState == eSOAPMessageIsChunked)
{
if( m_iBytesLeft == 0)
@@ -1157,15 +1154,17 @@
void HTTPTransport::
processRootMimeBody()
{
+ int numberOfBytesRead = 0;
+
if( false == m_bReadPastRootMimeHeader)
{
do
{
if( m_strReceived.find( ASCII_S_CRLFCRLF ) == std::string::npos)
{
- m_pszRxBuffer [0] = '\0';
- *m_pActiveChannel >> m_pszRxBuffer;
- m_strReceived += m_pszRxBuffer;
+ numberOfBytesRead = m_pActiveChannel->readBytes(m_pszRxBuffer, BUF_SIZE);
+ if (numberOfBytesRead > 0)
+ m_strReceived += m_pszRxBuffer;
}
}
while( m_strReceived.find( ASCII_S_CRLFCRLF ) == std::string::npos);
@@ -1265,20 +1264,15 @@
void HTTPTransport::
getAttachment( char * pStrAttachment, int * pIntSize, int intAttachmentId)
{
- m_pszRxBuffer [0] = '\0';
- *m_pActiveChannel >> m_pszRxBuffer;
- m_strMimeReceived += m_pszRxBuffer;
-
+ int numberOfBytesRead = 0;
+
do
{
- if( m_strMimeReceived.find( "\r\n\r\n") == std::string::npos)
- {
- m_pszRxBuffer [0] = '\0';
- *m_pActiveChannel >> m_pszRxBuffer;
+ numberOfBytesRead = m_pActiveChannel->readBytes(m_pszRxBuffer, BUF_SIZE);
+ if (numberOfBytesRead > 0)
m_strMimeReceived += m_pszRxBuffer;
- }
}
- while( m_strMimeReceived.find( "\r\n\r\n") == std::string::npos);
+ while( m_strMimeReceived.find( "\r\n\r\n") == std::string::npos );
//now we have found the end of next mime header
processMimeHeader();
@@ -1481,48 +1475,31 @@
// 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.).
- // TODO - need to rewrite to eliminate iteration count since it is prone to problems!
- bool bHTTPHeaderFound = false;
- int iIterationCount = 100;
+ // the end of the HTTP header block (i.e. looks for CR LF CR LF).
+ int numberOfBytesRead = 0;
m_strReceived = "";
+ m_iBytesLeft = 0;
m_pActiveChannel->closeQuietly( 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;
-
- // Add the new message part to the received string.
- m_strReceived += m_pszRxBuffer;
+ numberOfBytesRead = m_pActiveChannel->readBytes(m_pszRxBuffer, BUF_SIZE);
- // Do iteration processing.
- if( strlen( m_pszRxBuffer) > 0)
- iIterationCount = 100;
+ if (numberOfBytesRead > 0)
+ m_strReceived += m_pszRxBuffer;
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)
{
- bHTTPHeaderFound = true;
+ throw HTTPTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR,
+ "Socket connection has been closed.");
}
- }
- 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.");
+ // 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)
+ break;
}
+ while(numberOfBytesRead > 0);
}
void HTTPTransport::
@@ -1618,24 +1595,13 @@
bool HTTPTransport::
getNextDataPacket( const char * pcszExceptionMessage)
{
- int iIterationCount = 100;
bool bDataRead = false;
+ int numberOfBytesRead = 0;
- 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.
+ numberOfBytesRead = m_pActiveChannel->readBytes(m_pszRxBuffer, BUF_SIZE);
- if( bDataRead)
+ if( numberOfBytesRead > 0)
{
m_strReceived += m_pszRxBuffer;
m_iBytesLeft = m_strReceived.length();
@@ -1650,7 +1616,7 @@
}
}
- return bDataRead;
+ return (numberOfBytesRead > 0);
}
int HTTPTransport::
@@ -1698,7 +1664,10 @@
if( m_iBytesLeft > 0)
m_strReceived = m_strReceived.substr( iToCopy);
else
+ {
m_strReceived = "";
+ m_iBytesLeft = 0;
+ }
bTransportInProgress = true;
}
Modified: webservices/axis/trunk/c/src/transport/axis3/IChannel.hpp
URL: http://svn.apache.org/viewvc/webservices/axis/trunk/c/src/transport/axis3/IChannel.hpp?view=diff&rev=506306&r1=506305&r2=506306
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/IChannel.hpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/IChannel.hpp Sun Feb 11 21:58:13 2007
@@ -49,8 +49,8 @@
virtual bool open() throw (HTTPTransportException&)=0;
virtual bool close()=0;
virtual const std::string& GetLastErrorMsg()=0;
- virtual const IChannel& operator >> (char * msg)=0;
- virtual const IChannel& operator << (const char * msg)=0;
+ virtual int readBytes(char *buf, int bufLen)=0;
+ virtual int writeBytes(const char *buf, int numBytes)=0;
virtual int setSecureProperties( const char *) {return true;};
virtual const char * getSecureProperties() {return NULL;};
virtual void setTimeout( long lSeconds)=0;
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org