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 pr...@apache.org on 2006/02/03 14:34:23 UTC

svn commit: r374667 - in /webservices/axis/trunk/c/src/xml: AxisParseException.cpp xerces/XMLParserXerces.cpp

Author: prestonf
Date: Fri Feb  3 05:34:19 2006
New Revision: 374667

URL: http://svn.apache.org/viewcvs?rev=374667&view=rev
Log:
Update to Xerces parser exceptions to properly catch xerces parser problems and throw a more descriptive message.

Modified:
    webservices/axis/trunk/c/src/xml/AxisParseException.cpp
    webservices/axis/trunk/c/src/xml/xerces/XMLParserXerces.cpp

Modified: webservices/axis/trunk/c/src/xml/AxisParseException.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/xml/AxisParseException.cpp?rev=374667&r1=374666&r2=374667&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/xml/AxisParseException.cpp (original)
+++ webservices/axis/trunk/c/src/xml/AxisParseException.cpp Fri Feb  3 05:34:19 2006
@@ -27,7 +27,6 @@
 	if (pcMessage) 
 	{
 		sMessage = string(pcMessage);
-		getMessageForExceptionCode(iExceptionCode);
 		m_sMessageForExceptionCode = getMessageForExceptionCode(iExceptionCode) + " " + sMessage;
 		setMessage(m_sMessageForExceptionCode.c_str());
 
@@ -48,16 +47,19 @@
 	switch(iExceptionCode)
     {
         case SERVER_PARSE_BUFFER_EMPTY:
-            m_sMessageForExceptionCode = "AxisParseException:Buffer received from the parser is empty";
+            m_sMessageForExceptionCode = "AxisParseException:Buffer received from the parser is empty.  ";
             break;
         case SERVER_PARSE_PARSER_FAILED:
-            m_sMessageForExceptionCode = "AxisParseException:XML_STATUS_ERROR thrown from parser";
+            m_sMessageForExceptionCode = "AxisParseException:XML_STATUS_ERROR thrown from parser.  ";
             break;
         case SERVER_PARSE_TRANSPORT_FAILED:
-            m_sMessageForExceptionCode = "AxisParseException:Error when getting the byte stream from the transport";
+            m_sMessageForExceptionCode = "AxisParseException:Error when getting the byte stream from the transport.  ";
+            break;
+		case CLIENT_SOAP_CONTENT_NOT_SOAP:
+            m_sMessageForExceptionCode = "AxisParseException:SAXParser has failed.  ";
             break;
         default:
-			m_sMessageForExceptionCode = "AxisParseException:Unknown Parse Exception"; 
+			m_sMessageForExceptionCode = "AxisParseException:Unknown Parser Exception.  "; 
     }
     return m_sMessageForExceptionCode;
 }

Modified: webservices/axis/trunk/c/src/xml/xerces/XMLParserXerces.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/xml/xerces/XMLParserXerces.cpp?rev=374667&r1=374666&r2=374667&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/xml/xerces/XMLParserXerces.cpp (original)
+++ webservices/axis/trunk/c/src/xml/xerces/XMLParserXerces.cpp Fri Feb  3 05:34:19 2006
@@ -80,51 +80,88 @@
 const AnyElement* XMLParserXerces::next(bool isCharData)
 {
 	bool bCanParseMore = false;
-        if(!m_bFirstParsed)
-        {
-            m_pParser->parseFirst(*m_pInputSource, m_ScanToken);
-            m_bFirstParsed = true;
-        }
 
-		if(!m_bPeeked) 
+    if( !m_bFirstParsed)
+    {
+		try
 		{
-			m_Xhandler.freeElement();
+			m_pParser->parseFirst(*m_pInputSource, m_ScanToken);
+		}
+		catch( const XMLException& toCatch)
+		{
+			char *	message = XMLString::transcode( toCatch.getMessage());
+
+// Clone the error message before deleting it.
+			char *	pErrorMsg = new char[strlen( message + 1)];
+
+			strcpy( pErrorMsg, message);
+
+			XMLString::release( &message);
+
+			throw AxisParseException( CLIENT_SOAP_CONTENT_NOT_SOAP, pErrorMsg);
+		}
+		catch( const SAXParseException& toCatch)
+		{
+			char *	message = XMLString::transcode( toCatch.getMessage());
+
+// Clone the error message before deleting it.
+			char *	pErrorMsg = new char[strlen( message + 1)];
+
+			strcpy( pErrorMsg, message);
+
+			XMLString::release( &message);
+
+			throw AxisParseException( CLIENT_SOAP_CONTENT_NOT_SOAP, pErrorMsg);
 		}
-        while (true)
+		catch (...)
+		{
+			char *	pErrorMsg = "Unexpected Exception in SAX parser.  Probably no message or the message is not recognised as XML.";
+
+			throw AxisParseException( CLIENT_SOAP_CONTENT_NOT_SOAP, pErrorMsg);
+		}
+
+        m_bFirstParsed = true;
+    }
+
+	if(!m_bPeeked) 
+	{
+		m_Xhandler.freeElement();
+	}
+    while (true)
+    {
+        AnyElement* elem = m_Xhandler.getAnyElement();
+        if (!elem)
         {
-            AnyElement* elem = m_Xhandler.getAnyElement();
-            if (!elem)
-            {
-				//Chinthana:check the peek is called or not
-				if(!m_bPeeked) 
-				{
-					bCanParseMore = m_pParser->parseNext(m_ScanToken);
-				}
-				else
-				{
-					m_bPeeked = false;
-					bCanParseMore = true;
-				}
-				elem = m_Xhandler.getAnyElement();
-				
-				//27/04/2005
+			//Chinthana:check the peek is called or not
+			if(!m_bPeeked) 
+			{
+				bCanParseMore = m_pParser->parseNext(m_ScanToken);
+			}
+			else
+			{
+				m_bPeeked = false;
+				bCanParseMore = true;
+			}
+			elem = m_Xhandler.getAnyElement();
+			
+			//27/04/2005
+        }
+        if (elem)
+        {
+            if (!isCharData && (CHARACTER_ELEMENT == elem->m_type))
+            { /* ignorable white space */
+                m_Xhandler.freeElement();
+                continue;
             }
-            if (elem)
-            {
-                if (!isCharData && (CHARACTER_ELEMENT == elem->m_type))
-                { /* ignorable white space */
-                    m_Xhandler.freeElement();
-                    continue;
-                }
 
-				if( m_bPeeked )
-					m_bPeeked = false;
-                
-				return elem;
-            }
-            else if (AXIS_FAIL == m_Xhandler.getStatus()) return NULL;
-            else if (!bCanParseMore) return NULL;
+			if( m_bPeeked )
+				m_bPeeked = false;
+            
+			return elem;
         }
+        else if (AXIS_FAIL == m_Xhandler.getStatus()) return NULL;
+        else if (!bCanParseMore) return NULL;
+    }
 }
 //Chinthana:New method which peek a head next element 
 //Here always Peek() will call after the first pase done
@@ -223,4 +260,3 @@
 {
     return m_Xhandler.prefix4NS(pcNS);
 }
-