×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Brisbane, Australia
    Posts
    158

    http crash at end of transaction

    Hi,
    I have modelled my http connection off the symbian http client example.
    The connection works, and I even receive information back from the server.
    The problem is that once ESucceeded in MHFRunl completes, the application crashes.

    Here is part of AppUi ConstructL where i instantiate reviewView - the view to display downloaded text. and pass reviewView to iClient the http engine.
    Code:
    iReviewView = CScanItReviewView::NewL();
    
    iClient = CScanItHttpEngine::NewL(*iReviewView);
    Here is part of AppUi handleCommand where i handle EGet:
    Code:
    case EClientGet:
    		{
    		// Issue HTTP post to engine
    		iClient->CancelTransaction();
    
    		// Query uri and data to post
    		_LIT8(KUri, "http://mel.our-lan.com/?barcode=");
    		TBuf8<KDefaultBufferSize> uri8(KUri);
    					
    		iReviewView->ResetL();
    		TBuf8<20> barcode = iReviewView->getBarcode();
    
    		uri8.Append(barcode);
    		
    		// Start transaction
    		iClient->IssueHTTPGetL(uri8);
    		}
    Here is handleCommand from the download view (allows u to select which download you would like). I activate the reviewView if index=0 and then make AppUi handle EGet command in ReviewView's activate function as seen further below.
    Code:
    void CScanItDownloadView::HandleCommandL( TInt aCommand )
        {
    
        if ( aCommand == EAknSoftkeyCancel )
            {
            AppUi()->ActivateLocalViewL( TUid::Uid( EScanItView1Id ) );
            }
        else if (aCommand == EAknSoftkeySelect || aCommand == EKeyOK) 
        	{
        	TInt index = iContainer->GetListIndexL();
        	if (index == 0)
        		{
        		__LOGSTR_TOFILE("download view review command");
        		const TUid KMsgId = {3};
        		AppUi()->ActivateLocalViewL(TUid::Uid(EScanItReviewViewId), KMsgId, barcode);
       		
    			}
        	else if (index == 1)
        		{
    
        		}
        	}
        else
            {
            AppUi()->HandleCommandL( aCommand );
            }
        }
    ReviewView is pretty much empty at the moment as I am just trying to get http working first. Here is ReviewView's activate (DownloadView switches to reviewView when list index = 0):
    Code:
    void CScanItReviewView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
                                        TUid /*aCustomMessageId*/,
                                        const TDesC8& aCustomMessage )
        {
        __LOGSTR_TOFILE("review activate");
        if (!iContainer)
    		{
    		iContainer = CScanItReviewContainer::NewL(ClientRect());
    		iContainer->SetMopParent(this);
    		AppUi()->AddToStackL(*this, iContainer);
    		}
        barcode = aCustomMessage;
    
        AppUi()->HandleCommandL(EClientGet);
    }
    Last edited by s4028469; 2007-10-07 at 07:03.

  2. #2
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Brisbane, Australia
    Posts
    158

    Re: http crash at end of transaction

    and finally here is my http engine which is the same as the orignal nokia http client:
    Code:
    ....
    
    void CScanItHttpEngine::ConstructL()
    	{
    
    	// Open RHTTPSession with default protocol ("HTTP/TCP")
    	TRAPD(err, iSession.OpenL());
    	if(err != KErrNone) 
    		{
    		// Most common error; no access point configured, and session creation
    		// leaves with KErrNotFound.
    		_LIT(KErrMsg,
    			"Cannot create session. Is internet access point configured?");
    		_LIT(KExitingApp, "Exiting app.");
    		CEikonEnv::Static()->InfoWinL(KErrMsg, KExitingApp);
    		User::Leave(err);
    		}
    
    	// Install this class as the callback for authentication requests. When
    	// page requires authentication the framework calls GetCredentialsL to get
    	// user name and password.
    	InstallAuthenticationL(iSession);
    
    	}
    
    void CScanItHttpEngine::SetHeaderL(RHTTPHeaders aHeaders,
    							 TInt aHdrField,
    							 const TDesC8& aHdrValue)
    	{
    	RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
    	CleanupClosePushL(valStr);
    	THTTPHdrVal val(valStr);
    	aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,
    		RHTTPSession::GetTable()), val);
    	CleanupStack::PopAndDestroy(); // valStr
    	valStr.Close();
    	}
    
    void CScanItHttpEngine::IssueHTTPGetL(const TDesC8& aUri)
    	{
    	SetupConnectionL();	
    		
    	// Parse string to URI (as defined in RFC2396)
    	TUriParser8 uri;
    	uri.Parse(aUri);
    
    	// Get request method string for HTTP GET
    	RStringF method = iSession.StringPool().StringF(HTTP::EGET,
    		RHTTPSession::GetTable());
    
    	// Open transaction with previous method and parsed uri. This class will
    	// receive transaction events in MHFRunL and MHFRunError.
    	iTransaction = iSession.OpenTransactionL(uri, *this, method);
    	method.Close();
    	
    	// Set headers for request; user agent and accepted content type
    	RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    	SetHeaderL(hdr, HTTP::EAccept, KAccept);
    
    	// Submit the transaction. After this the framework will give transaction
    	// events via MHFRunL and MHFRunError.
    	iTransaction.SubmitL();
    
    	iRunning = ETrue;
    	_LIT(KConnecting,"Connecting...");
    	iObserver.ClientEvent(KConnecting);
    	}
    
    void CScanItHttpEngine::CancelTransaction()
    	{
    	if(!iRunning)
    		return;
    
    	__LOGSTR_TOFILE("cancel");
    	// Close() also cancels transaction (Cancel() can also be used but
    	// resources allocated by transaction must be still freed with Close())
    	iTransaction.Close();
    
    	// Not running anymore
    	iRunning = EFalse;
    	_LIT(KTransactionCancelled, "Transaction cancelled");
    	iObserver.ClientEvent(KTransactionCancelled);
    	}
    
    void CScanItHttpEngine::MHFRunL(RHTTPTransaction aTransaction,
    						  const THTTPEvent& aEvent)
    	{
    	switch (aEvent.iStatus)
    		{
    		__LOGSTR_TOFILE("switch");
    		case THTTPEvent::EGotResponseHeaders:
    			{
    			__LOGSTR_TOFILE("httpengine gotResponseHeaders");
    			// HTTP response headers have been received. Use
    			// aTransaction.Response() to get the response. However, it's not
    			// necessary to do anything with the response when this event occurs.
    
    			// Get HTTP status code from header (e.g. 200)
    			RHTTPResponse resp = aTransaction.Response();
    			TInt status = resp.StatusCode();
    
    			// Get status text (e.g. "OK")
    			TBuf<KStatustextBufferSize> statusText;
    			statusText.Copy(resp.StatusText().DesC());
    
    			TBuf<KDefaultBufferSize> text;
    			_LIT(KHeaderReceived, "Header received. Status: %d %S");
    			text.Format(KHeaderReceived, status, &statusText);
    			iObserver.ClientEvent(text);
    			}
    			break;
    
    		case THTTPEvent::EGotResponseBodyData:
    			{
    			__LOGSTR_TOFILE("httpengine gotResponsebody");
    			// Part (or all) of response's body data received. Use
    			// aTransaction.Response().Body()->GetNextDataPart() to get the actual
    			// body data.
    	
    			// Get the body data supplier
    			MHTTPDataSupplier* body = aTransaction.Response().Body();
    			TPtrC8 dataChunk;
    
    			// GetNextDataPart() returns ETrue, if the received part is the last
    			// one.
    			TBool isLast = body->GetNextDataPart(dataChunk);
    			iObserver.ClientBodyReceived(dataChunk);
    
    			TBuf<KInfotextBufferSize> text;
    			_LIT(KBodyPartReceived, "%d bytes received... ");
    			text.Format(KBodyPartReceived, dataChunk.Length());
    			iObserver.ClientEvent(text);
    
    			// NOTE: isLast may not be ETrue even if last data part received.
    			// (e.g. multipart response without content length field)
    			// Use EResponseComplete to reliably determine when body is completely
    			// received.
    			if (isLast)
    				{
    				_LIT(KBodyReceived,"Body received");
    				iObserver.ClientEvent(KBodyReceived);
    				}
    
    			// Always remember to release the body data.
    			body->ReleaseData();
    			}
    			break;
    
    		case THTTPEvent::EResponseComplete:
    			{
    			__LOGSTR_TOFILE("httpengine transaction complete");
    			// Indicates that header & body of response is completely received.
    			// No further action here needed.
    			_LIT(KTransactionComplete, "Transaction Complete");
    			iObserver.ClientEvent(KTransactionComplete);
    			}
    			break;
    
    		case THTTPEvent::ESucceeded:
    			{
    			// Indicates that transaction succeeded.
    			_LIT(KTransactionSuccessful, "Transaction Successful");
    			iObserver.ClientEvent(KTransactionSuccessful);
    			
    			// Transaction can be closed now. It's not needed anymore.
    			//aTransaction.Cancel();
    			aTransaction.Close();
    			iRunning = EFalse;
    			__LOGSTR_TOFILE("succeed")
    			}
    			break;
    
    		case THTTPEvent::EFailed:
    			{
    			// Transaction completed with failure.
    			_LIT(KTransactionFailed, "Transaction Failed");
    			iObserver.ClientEvent(KTransactionFailed);
    			aTransaction.Close();
    			iRunning = EFalse;
    			}
    			break;
    
    		default:
    			// There are more events in THTTPEvent, but they are not usually
    			// needed. However, event status smaller than zero should be handled
    			// correctly since it's error.
    			{
    			__LOGSTR_TOFILE("default");
    			
    			TBuf<KInfotextBufferSize> text;
    			if (aEvent.iStatus < 0)
    				{
    				_LIT(KErrorStr, "Error: %d");
    				text.Format(KErrorStr, aEvent.iStatus);
    				// Just close the transaction on errors
    				aTransaction.Close();
    				iRunning = EFalse;
    				} 
    			else 
    				{
    				// Other events are not errors (e.g. permanent and temporary
    				// redirections)
    				_LIT(KUnrecognisedEvent, "Unrecognised event: %d");
    				text.Format(KUnrecognisedEvent, aEvent.iStatus);
    				}
    			iObserver.ClientEvent(text);
    			}
    			break;
    		}
    	}
    
    TInt CScanItHttpEngine::MHFRunError(TInt aError,
    							  RHTTPTransaction /*aTransaction*/,
    							  const THTTPEvent& /*aEvent*/)
    	{
    	// Just notify about the error and return KErrNone.
    	TBuf<KInfotextBufferSize>	text;
    	_LIT(KRunError, "MHFRunError: %d");
    	text.Format(KRunError, aError);
    	iObserver.ClientEvent(text);
    	__LOGSTR_TOFILE("MHF error");
    	return KErrNone;
    	}
    
    
    TBool CScanItHttpEngine::GetNextDataPart(TPtrC8& aDataPart)
    	{
    	if(iPostData)
    		{
    		// Provide pointer to next chunk of data (return ETrue, if last chunk)
    		// Usually only one chunk is needed, but sending big file could require
    		// loading the file in small parts.
    		aDataPart.Set(iPostData->Des());
    		}
    	return ETrue;
    	}
    
    
    void CScanItHttpEngine::ReleaseData()
    	{
    	// It's safe to delete iPostData now.
    	if (iPostData)
    		{
    		delete iPostData;
    		iPostData = NULL;
    		}
    	}
    
    TInt CScanItHttpEngine::Reset()
    	{
    	// Nothing needed since iPostData still exists and contains all the data.
    	// (If a file is used and read in small parts we should seek to beginning
    	// of file and provide the first chunk again in GetNextDataPart() )
    	return KErrNone;
    	}
    
    TInt CScanItHttpEngine::OverallDataSize()
    	{
    	if(iPostData)
    		return iPostData->Length();
    	else
    		return KErrNotFound ;
    	}
    void CScanItHttpEngine::SetupConnectionL()
        {
        if( iConnectionSetupDone )
            return;
        
        iConnectionSetupDone = ETrue;
        
        //open socket server and start the connection
        User::LeaveIfError(iSocketServ.Connect());
        User::LeaveIfError(iConnection.Open(iSocketServ));
        
        // open the IAP communications database 
    	CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
    	CleanupStack::PushL(commDB);
    
    	// initialize a view 
    	CCommsDbConnectionPrefTableView* commDBView = 
    	commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown);
    
    	// go to the first record 
    	User::LeaveIfError(commDBView->GotoFirstRecord());
    
    	// Declare a prefTableView Object.
    	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
    
    	// read the connection preferences 
    	commDBView->ReadConnectionPreferenceL(pref);
    	TUint32 iapID = pref.iBearer.iIapId; 
    
    	// pop and destroy the IAP View 
    	CleanupStack::PopAndDestroy(commDBView);
    
    	// pop and destroy the database object
    	CleanupStack::PopAndDestroy(commDB);
    
    	// Now we have the iap Id. Use it to connect for the connection.
    	// Create a connection preference variable.
    	TCommDbConnPref connectPref;
    
    	// setup preferences 
    	connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    	connectPref.SetDirection(ECommDbConnectionDirectionUnknown);
    	connectPref.SetBearerSet(ECommDbBearerGPRS);
    	//Sets the CommDb ID of the IAP to use for this connection
    	connectPref.SetIapId(iapID);
        
        User::LeaveIfError(iConnection.Start(connectPref));
    	
        //set the sessions connection info
        RStringPool strPool = iSession.StringPool();
        RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
        
        //to use our socket server and connection
        connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
            RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );
    
        connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
            RHTTPSession::GetTable() ), 
            THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) );
        }

  3. #3
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Brisbane, Australia
    Posts
    158

    Re: http crash at end of transaction

    I get a USER 42 crash

  4. #4
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Brisbane, Australia
    Posts
    158

    Re: http crash at end of transaction

    I cannot see where any of the following has even been used in this http code:

    This panic is raised by a number of RHeap member functions, AllocLen(), Free(), FreeZ(), ReAlloc(), ReAllocL(), Adjust() and AdjustL() when a pointer passed to these functions does not point to a valid cell.


    are there any other reasons for a USER 42

  5. #5
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Brisbane, Australia
    Posts
    158

    Re: http crash at end of transaction

    USER 42 error was actually caused by previous code but doesn't cause a crash until http use.

    so if u get a user 42 crash from http, make sure u haven't got a prior user 42 error (even if your application isn't crashing before that point)

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: http crash at end of transaction

    s4028469 said:
    USER 42 error was actually caused by previous code but doesn't cause a crash until http use.

    so if u get a user 42 crash from http, make sure u haven't got a prior user 42 error (even if your application isn't crashing before that point)


    so what kind of code can leads to USER 42 error

Similar Threads

  1. want to override the default IAP dialog
    By vasant21 in forum Symbian
    Replies: 0
    Last Post: 2006-07-21, 11:45
  2. Problem: 10 Bluetooth Ports simultaneously
    By Alco Fresh in forum Symbian
    Replies: 1
    Last Post: 2006-07-03, 12:05
  3. SocketServer panics with Des16Align after complete HTTP transaction
    By d_wasser in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2005-01-19, 16:22
  4. Http Transaction without PopUp
    By deepikamulani in forum Symbian
    Replies: 1
    Last Post: 2004-07-13, 12:18
  5. Http connection crash on Ngage
    By anderspanders in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-11-20, 11:39

Posting Permissions

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