×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    235

    Question getting error -19 in MHFRunL THttpEvent astatus

    Here is the code . I am using SDK 2 fp3 and my diagonistic window too is not opening somehow . An IAP list gets loaded and Connectl and DoPostL gets executed . The strangest thing is that this bit of code is functional in SDk3 fp1 .

    Code:
    /*
    
    // INCLUDE FILES
    // Class include
    
    #include <HttpStringConstants.h>// HTTP
    #include <msvids.h>				// KMsvGlobalInBoxIndexEntryId
    #include <txtrich.h>			// CRichText
    #include <mtclreg.h>			// CClientMtmRegistry
    #include <mtclbase.h>			// CBaseMtm
    #include <commdb.h>				// CCommsDatabase
    #include <commdbconnpref.h>		// TCommDbConnPref
    #include <es_enum.h>			// TConnectionInfoV2Buf
    #include <eikenv.h>
    #include "PMHttpEngine.h"
    #include "PM.pan"
    #include <AknexGrid.rsg>
    #include "Response.h"
    #include "PMConnectionOpener.h"
    
    //Constants
    _LIT8(KUserAgent, "..");
    _LIT8(KAccept, "*/*");
    _LIT8(KContentTypeForm, "application/x-www-form-urlencoded\0");
    //_LIT8(KUrlFetchStocks, "http://%S/symbiantest.asp");
    _LIT8(KUrlFetchStocks, "http://..");
    _LIT8(KUrlFetchTicker, "http://..");
    _LIT8(KUsername, "username");
    _LIT8(KPassword, "password");
    _LIT(KIapNotSet, "IAP not selected");
    _LIT(KServerNotSet, "Server name not set");
    _LIT(KUserNotSet, "Set username and/or password");
    _LIT(KSmsUpdateMessage, "PortfolioManagerUpdate");
    // ================= MEMBER FUNCTIONS =======================
    
    	
    CPMHttpEngine* CPMHttpEngine::NewL()
    	{
    	CPMHttpEngine* self = new (ELeave) CPMHttpEngine();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	CleanupStack::Pop(self);
    	return self;
    	}
    	
    void CPMHttpEngine::ConstructL()
    	{
    	User::LeaveIfError(iSockServ.Connect());
    	User::LeaveIfError(iConnection.Open(iSockServ));
    	iConnOpener = CPMConnectionOpener::NewL(iConnection,*this);
    
    	iMsvSession = CMsvSession::OpenAsyncL(*this);
    	
    	iHttpSession.OpenL();
    		
    	LoadIapsL();
    	
    	// no IAPs defined in the device.
    	if (iIAPs.Count() == 0)
    		{
    		CEikonEnv::Static()->LeaveWithInfoMsg(R_PM_NO_IAPS_DEFINED);
    		}
    	}
    		
    void CPMHttpEngine::SetTransactionObserver(MTransactionObserver *aObserver)
    	{
    		iTransactionObserver=aObserver;
    	
    	}
    		
    void CPMHttpEngine::SetConnectionSettingsL(const TDesC& aServerName,
    										   const TDesC& aUsername, 
    										   const TDesC& aPassword)
    	{
    	iUsername.Copy(aUsername);
    	iPassword.Copy(aPassword);
    	iServer.Copy(aServerName);
    	delete iGetTasksForm;
    	iGetTasksForm = NULL;
    	
    	// if username and password are set, create an "HTML form".
    	if (0 < iUsername.Length() && 0 < aPassword.Length())
    		{
    		iGetTasksForm = CHTTPFormEncoder::NewL();
    		iGetTasksForm->AddFieldL(KUsername, iUsername);
    		iGetTasksForm->AddFieldL(KPassword, iPassword);
    		}
    	}
    
    	
    void CPMHttpEngine::SetIap(const TUint32& aId)
    	{
    	iIap = aId;
    	}
    	
    TBool CPMHttpEngine::IapSet() const
    	{
    	if (iIap == 0)
    		{
    		return EFalse;
    		}
    	else
    		{
    		return ETrue;
    		}
    	}
    
    void CPMHttpEngine::SetHeaderL(RHTTPHeaders aHeaders, 
    							 		TInt aHdrField, 
    							 		const TDesC8& aHdrValue)
    	{
    	RStringF valStr = iHttpSession.StringPool().OpenFStringL(aHdrValue);
    	CleanupClosePushL(valStr);
    	THTTPHdrVal val(valStr);
    	aHeaders.SetFieldL(iHttpSession.StringPool().StringF(aHdrField,	RHTTPSession::GetTable()), val);
    	CleanupStack::PopAndDestroy(&valStr);
    	}
    
    	
    TBool CPMHttpEngine::CheckAndReportErrorsL()
    	{
    	if (!IapSet())
    		{
    		iTransactionObserver->ErrorL(KIapNotSet);
    		return ETrue;
    		}
    		
    	if (iServer.Length() == 0)
    		{
    		iTransactionObserver->ErrorL(KServerNotSet);
    		return ETrue;
    		}
    
    	return EFalse;
    	}
    
    
    void CPMHttpEngine::FetchStocksL()
    	{
    	// Till Here
    	ResetData();
    	iUrl.Format(KUrlFetchStocks, &iServer);
    		iMode=1;	
    	iHttpForm = iGetTasksForm;
    
    	// open up a (GPRS) connection and post the form.
    	ConnectL();
    	}
    		
    void CPMHttpEngine::FetchTickerL()
    	{
    	 // Till Here
    	ResetData();
    	iUrl.Format(KUrlFetchTicker, &iServer);
    	iMode=0;	
    	iHttpForm = iGetTasksForm;
    
    	// open up a (GPRS) connection and post the form.
    	ConnectL();
    	}
    		
    void CPMHttpEngine::ConnectL()
    	{
    	// this functionality is not applicable for the emulator
    	#ifndef __WINS__ 
    	
    	TBool connected = EFalse;
    	
    	// Lets first check are we already connected.
    	TUint connectionCount;
    	User::LeaveIfError(iConnection.EnumerateConnections(connectionCount));
    	TPckgBuf<TConnectionInfoV2> connectionInfo; 
    	for (TUint i = 1; i <= connectionCount; i++)
    		{
    		User::LeaveIfError(iConnection.GetConnectionInfo(i, connectionInfo));
    		if (connectionInfo().iIapId == iIap)
    			{
    			connected = ETrue;
    			break;
    			}
    		}
    	
    	// Not yet connected, start connection
    	if (!connected)
    		{
    		//Define preferences for connection
    		TCommDbConnPref prefs;
    		prefs.SetIapId(iIap);
    		prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    
    		//Start Connection
    		iOpeningConnection = ETrue;
    		iTransactionObserver->OpeningConnectionL();
    		iConnOpener->OpenConnection(prefs);
    		return;
    		}
    
    	//Set properties for the HTTP session
    	RStringPool strP = iHttpSession.StringPool();
    	RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo();
    	connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSockServ.Handle()) );
    	TInt connPtr = REINTERPRET_CAST(TInt, &iConnection);
    	connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) );
    	
    	#endif // __WINS__
    	DoPostL();
    	}
    	
    void CPMHttpEngine::ConnectionCreated(const TInt& aError)
    	{
    	iOpeningConnection = EFalse;
    	if (aError != KErrNone)
    		{
    		TRAPD(error, iTransactionObserver->FailedL(aError))
    		PanicIfError(error);
    		}
    	else
    		{
    		TRAPD(error,
    			//Set properties for the HTTP session
    			RStringPool strP = iHttpSession.StringPool();
    			RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo();
    			connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSockServ.Handle()) );
    			TInt connPtr = REINTERPRET_CAST(TInt, &iConnection);
    			connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) );
    			DoPostL();
    			)
    		PanicIfError(error);
    		}
    	}
    
    void CPMHttpEngine::DoPostL(/*const TDesC& connectUrl*/)
    	{
    	/*TBuf8<connectUrl.Length()> buf8;
    	buf8.Copy(connectUrl);*/
    	TUriParser8 uri;
    //	User::LeaveIfError(uri.Parse(buf8));
    	User::LeaveIfError(uri.Parse(iUrl));
    			
    		RStringF method = iHttpSession.StringPool().StringF(HTTP::EGET, RHTTPSession::GetTable());
    		iTransaction = iHttpSession.OpenTransactionL(uri, *this, method);
    	
    		RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    	SetHeaderL(hdr, HTTP::EAccept, KAccept);
    		iTransaction.SubmitL();
    
    	iRunning = ETrue;
    	if (iHttpForm == iGetTasksForm)
    		{
    		iTransactionObserver->ConnectingToServerL(ETrue);
    		}
    	else
    		{
    		iTransactionObserver->ConnectingToServerL(EFalse);
    		}
    	}
    
    void CPMHttpEngine::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
    	{
    ////////////////////////Error here///////////////
    	switch (aEvent.iStatus) 
    		{
    		case THTTPEvent::EGotResponseHeaders:
    			{
    			
    			RHTTPResponse resp = aTransaction.Response();
    			TInt status = resp.StatusCode();
    			RStringF statusStr = resp.StatusText();
    			TBuf<32> statusStr16;
    			statusStr16.Copy(statusStr.DesC());
    			// iUtils.Test().Printf(_L("Status: %d (%S)\n"), status, &statusStr16);    *** Shrikanta ***
    
    			}
    			break;
    
    		case THTTPEvent::EGotResponseBodyData:
    			{
    			MHTTPDataSupplier* body = aTransaction.Response().Body();
    			TPtrC8 dataChunk;			
    			body->GetNextDataPart(dataChunk);
    			body->ReleaseData();
    			WriteDataL(dataChunk);
    			}
    			break;
    
    		// Indicates that header & body of response is completely received.
    		case THTTPEvent::EResponseComplete:
    			{
    				
    			}
    			break;
    		
    		// Indicates that transaction succeeded.
    		case THTTPEvent::ESucceeded:
    			{
    			iTransaction.Close();
    			iRunning = EFalse;
    			
    			CResponse* response = CResponse::NewLC(iMode);
    			
    			TRAPD(error,
    			response->InputDataL(*iReceivedData);
    			iTransactionObserver->SuccessL(*response);
    			CheckRefreshL();)
    			PanicIfError(error);
    
    			CleanupStack::PopAndDestroy(response);
    
    
    				
    			}
    			break;
    
    		// Transaction completed with failure.
    		case THTTPEvent::EFailed:
    			{			 
    			iTransaction.Close();
    			iRunning = EFalse;
    
    			// After transaction has been closed, leaves are no 
    			// longer handled by the calling active object.
    			TRAPD(error,
    			iTransactionObserver->FailedL(0);
    			CheckRefreshL();)
    			PanicIfError(error);
    			}
    			break;
    
    		default:
    						{
    			if (aEvent.iStatus < 0)
    				{
    								iTransaction.Close();
    				iRunning = EFalse;
    				
    								TRAPD(error,
    				iTransactionObserver->FailedL(aEvent.iStatus);
    				CheckRefreshL();)
    				PanicIfError(error);
    				} 
    			else 
    				{
    				// Other events are not errors (e.g. permanent and temporary
    				// redirections)
    				}
    			}
    			break;
    		}
    	}
    	
    TInt CPMHttpEngine::MHFRunError(	TInt aError, 
    										RHTTPTransaction /*aTransaction*/, 
    										const THTTPEvent& /*aEvent*/)
    	{
    	// only report about the error.
    	TRAPD(error, iTransactionObserver->FailedL(aError);)
    	return error;
    	}

  2. #2
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    235

    Question Re: getting error -19 in MHFRunL THttpEvent astatus

    rest of the class is here
    Code:
    void CPMHttpEngine::CancelTransaction()
    	{
    	// if we are opening up a GPRS connection.
    	if (iOpeningConnection)
    		{
    		iConnOpener->Cancel();
    		TRAPD(error, iTransactionObserver->CancelledL())
    		PanicIfError(error);
    		return;
    		}
    		
    	
    	if(!iRunning) 
    		return;
    
    		iTransaction.Close();
    
    	iRunning = EFalse;
    	TRAPD(	error,
    			iTransactionObserver->CancelledL());
    	PanicIfError(error);
    	}
    
    void CPMHttpEngine::WriteDataL(const TDesC8& aData)
    	{
    	// some data already received
    	if (iReceivedData)
    		{
    		iReceivedData = iReceivedData->ReAllocL(iReceivedData->Length() + aData.Length());
    		HBufC* newData = HBufC::NewLC(aData.Length());
    		newData->Des().Copy(aData);
    		iReceivedData->Des() += newData->Des();
    		CleanupStack::PopAndDestroy(newData);
    		}
    	// no data yet received.
    	else
    		{
    		iReceivedData = HBufC::NewL(aData.Length());
    		iReceivedData->Des().Copy(aData);
    		}
    	}
    
    void CPMHttpEngine::ResetData()
    	{
    	delete iReceivedData;
    	iReceivedData = NULL;
    	}
    	
    void CPMHttpEngine::CheckRefreshL()
    	{
    	// if HTTP transaction is running, don't fetch tasks.
    	if (iRunning)
    		{
    		return;
    		}
    		
    	if (iDoRefresh)
    		{
    		iDoRefresh = EFalse;
    		FetchStocksL();
    		}
    	}
    
    
    void CPMHttpEngine::SetAutomaticUpdateL(const TBool& aOn)
    	{
    	iAutomaticUpdate = aOn;
    	if (iAutomaticUpdate)
    		{
    		CheckRefreshL();
    		}
    	}
    
    	
    void CPMHttpEngine::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
    	{
    	switch (aEvent)
    		{
    		case EMsvServerReady:
    			if (!iMsvEntry)
    				{
    				iMsvEntry = CMsvEntry::NewL(*iMsvSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
    				}
    			break;
    			
    		case EMsvEntriesCreated:
    			if (*(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId)
    				{
    				CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
    
    				iMsvEntry->SetEntryL(entries->At(0));
    				TMsvEntry msvEntry(iMsvEntry->Entry());
    				msvEntry.SetVisible(EFalse);
    
    				CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL(*iMsvSession);
    				CleanupStack::PushL(mtmReg);
    				CBaseMtm* smsMtm = mtmReg->NewMtmL(msvEntry.iMtm);
    				smsMtm->SwitchCurrentEntryL(entries->At(0));
    				smsMtm->LoadMessageL();
    				TBool CorrectSms = EFalse;
    				
    				// received SMS message is a 'Task manager update' SMS.
    				if (smsMtm->Body().Read(0,KSmsUpdateMessage().Length()).Compare(KSmsUpdateMessage)==0)
    					{
    					msvEntry.SetUnread(EFalse);
    					CorrectSms = ETrue;
    					}
    				// not a 'Task manager update' SMS, show it to user.
    				else
    					{
    					msvEntry.SetVisible(ETrue);
    					}
    					
    				iMsvEntry->ChangeL(msvEntry);
    
    				CleanupStack::PopAndDestroy(smsMtm);
    
    				// if received SMS message was a 'Task Manager update' SMS.
    				if (CorrectSms)
    					{
    					// delete the received SMS message for it is not intended for the user to read.
    					iMsvEntry->DeleteL(entries->At(0));
    					
    					// if an HTTP transaction is running or program is in the background or busy. 
    					// Don't fetch tasks yet.
    					if (iRunning || !iAutomaticUpdate)
    						{
    						iDoRefresh = ETrue;
    						}
    					// HTTP transaction is not running, fetch tasks.
    					else
    						{
    						FetchStocksL();
    						}
    					}
    				}
    			break;
    			
    			default:
    			break;
    		}
    	}
    	
    void CPMHttpEngine::LoadIapsL()
    	{
    	// open commdb
    	CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
    	CleanupStack::PushL(commDb);
    
    	// open IAP table
    	CCommsDbTableView* commView = commDb->OpenIAPTableViewMatchingBearerSetLC(ECommDbBearerCSD|ECommDbBearerGPRS,ECommDbConnectionDirectionOutgoing);
    	
    	// search all IAPs
    	if (commView->GotoFirstRecord() == KErrNone)
    		{
    		do
    			{
    			TIap iap;
    			commView->ReadTextL(TPtrC(COMMDB_NAME), iap.iName);
    			commView->ReadUintL(TPtrC(COMMDB_ID), iap.iId);
    			User::LeaveIfError(iIAPs.Append(iap));
    			}
    		while (commView->GotoNextRecord() == KErrNone);
    		}
    	CleanupStack::PopAndDestroy(/*commView*/);
    	CleanupStack::PopAndDestroy(/*commDb*/);
    	}
    RArray<TIap>& CPMHttpEngine::Iaps() 
    	{
    	return iIAPs;
    	}
    and had been called as
    Code:
    iEngine = CPMHttpEngine::NewL();
       iEngine->SetTransactionObserver(iGridView->idatapuller);
       iEngine->FetchTickerL();
    in 3rd ed FP3 functional as
    Code:
    #ifdef __SERIES60_30__
       User::LeaveIfError( iEikonEnv->FsSession().CreatePrivatePath( EDriveC ) );
    	User::LeaveIfError( iEikonEnv->FsSession().SetSessionToPrivate( EDriveC ) );
    #endif	
       iEngine = CPMHttpEngine::NewL();
       iEngine->SetTransactionObserver(iGridView->idatapuller);
       iEngine->FetchTickerL();
    I have also tried reusing SDK3 codes but is of no avail .

Similar Threads

  1. THTTPEvent status code -11118 ???
    By jatal in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2010-10-11, 13:08
  2. THTTPEvent error code 10001
    By ytchmp in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2008-03-10, 09:21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×