webservices/wshttpchanneltransportplugin/src/senhttpchanneltransportplugin.cpp
branchRCL_3
changeset 14 9e96e2676219
parent 10 bf3935de63a1
child 22 c5fabff9b552
--- a/webservices/wshttpchanneltransportplugin/src/senhttpchanneltransportplugin.cpp	Tue Apr 27 17:46:55 2010 +0300
+++ b/webservices/wshttpchanneltransportplugin/src/senhttpchanneltransportplugin.cpp	Tue May 11 17:14:12 2010 +0300
@@ -104,7 +104,8 @@
     iProperties(NULL),
     iConsumerMap(EFalse, ETrue), 
     iSessionMap(EFalse, EFalse), // iConsumerMap deletes the txnIds (using same "new reserved" TInt here!)
-    iStatusCode(0)
+    iStatusCode(0),
+    iIsConnectionFailed(EFalse)
     {
     }
 
@@ -124,6 +125,10 @@
     delete ipCtx;
     ipCtx = NULL;
 
+    // Close the log file and the connection to the server.
+    TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("SenHttpChannel - Log file closed.")));
+    TLSLOG_CLOSE(KSenHttpChannelLogChannelBase);
+
     TLSLOG(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,(_L("Got last data chunk.")));
     TLSLOG_CLOSE(KSenHttpChannelObserverLogChannelBase);
     }
@@ -135,6 +140,10 @@
     TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ConstructL(): log file opened.");
     TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ConstructL - Version 2 [2006-05-09]");
 
+    // Open connection to the file logger server
+    TLSLOG_OPEN(KSenHttpChannelLogChannelBase, KSenHttpChannelLogLevel, KSenHttpChannelLogDir, KSenHttpChannelLogFile);
+    TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("SenHttpChannel - Log file opened")));
+
     if( ipCtx )
         {
         // Attempt to find pre-defined IAP ID from transport context
@@ -455,10 +464,29 @@
 // Method to catch async error responses from httpchannel
 void CSenHttpChannelTransportPlugin::ResponseErrorL(TInt aRequestId, TInt aErrorCode, HBufC8* apErrorBody,CSenHttpTransportProperties* aHttpProperties)
     {
+    TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("CSenHttpChannelTransportPlugin::ResponseErrorL() - aErrorCode [%d]"), aErrorCode));
     CleanupStack::PushL(apErrorBody);
-    iHttpChannel->DisableTimeOutL(aRequestId);
+    if( (aErrorCode < KErrNone) && (apErrorBody == NULL) || aErrorCode == KErrAbort)
+    	{
+    	TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseErrorL() Set iIsConnectionFailed True");
+    	iHttpChannel->ResetIapId();
+    	iHttpChannel->ResetUsedIapId();
+    	iHttpChannel->SetExplicitIapDefined(EFalse);
+    	iIsConnectionFailed = ETrue;
+    	TUint32 zeroIap = 0;
+			TBuf8<128> buf;
+	    buf.AppendFormat(_L8("%u"), zeroIap);
+    	LayeredPropertiesL().SetPropertyL(KIapIdLocalName, buf); //Reset the layered properties in case of wrong IAP
+    	}
+    else
+    	{
+    	iHttpChannel->SetExplicitIapDefined(ETrue);
+    	}	
+    if(iHttpChannel)
+    	{
+    	iHttpChannel->DisableTimeOutL(aRequestId);
+    	}
 #ifdef _SENDEBUG    
-    TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResponseErrorL:");
     TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- Request's txnID: %d"), aRequestId));
     if ( apErrorBody )
         {
@@ -558,11 +586,12 @@
     // ALWAYS HANDLE IAP ID FIRST, SINCE IT *CAN RESET* HTTPCHANNEL!
     
     TUint32 iapId(KErrNone);
-
     retVal = LayeredPropertiesL().IapIdL(iapId);
-    if(retVal==KErrNone)
+    TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- CSenHttpChannelTransportPlugin::ApplyPropertiesL() - iapId [%d]"), iapId));
+	TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- LayeredPropertiesL() retVal [%d]"), retVal)); 
+    if(iIsConnectionFailed)
         {
-        TInt resetPerformed = ResetHttpChannelByIapIdL(iapId);
+		TInt resetPerformed = ResetHttpChannelByIapIdL(0); //Incase of connection error set Iap ID 0
 #ifdef _SENDEBUG
         if(resetPerformed == KErrNone)
             {
@@ -570,6 +599,16 @@
             }
 #endif // _SENDEBUG
         }
+    else if(retVal==KErrNone)
+        {
+       	TInt resetPerformed = ResetHttpChannelByIapIdL(iapId);
+#ifdef _SENDEBUG
+        if(resetPerformed == KErrNone)
+            {
+            TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KNormalLogLevel, _L8("- IAP re-set performed: (%d)"), 0));
+            }
+#endif // _SENDEBUG				
+        }
 
     // Handle ProxyHost and ProxyPort
     TPtrC8 proxyHost;
@@ -621,10 +660,10 @@
 
     TInt retVal(KErrNone);
     TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("- explicitIapIdDefined[%d], effectiveIapId[%d], aIapId[%d]"), explicitIapIdDefined, effectiveIapId, aIapId));
-    if(!explicitIapIdDefined || (explicitIapIdDefined && (effectiveIapId != aIapId) ))
+    if(!explicitIapIdDefined || (explicitIapIdDefined && (effectiveIapId != aIapId) ) || iIsConnectionFailed)
         {
         TLSLOG_L(KSenHttpChannelObserverLogChannelBase,KMinLogLevel,"CSenHttpChannelTransportPlugin::ResetHttpChannel():");
-
+        iIsConnectionFailed = EFalse;
         delete iHttpChannel;
         iHttpChannel = NULL;
         delete iRequester;
@@ -645,6 +684,7 @@
         {
         retVal = KErrAlreadyExists;
         }
+    TLSLOG_FORMAT((KSenHttpChannelObserverLogChannelBase,KMinLogLevel, _L8("CSenHttpChannelTransportPlugin::ResetHttpChannelByIapIdL() - returns [%d]"), retVal));
     return retVal;
     }