applayerprotocols/httptransportfw/Test/Integration/src/testexplicitsessionstep.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <es_enum.h>
       
    17 #include "testexplicitsessionstep.h"
       
    18 
       
    19 _LIT8(KProxy, "10.29.23.12:9003");
       
    20 
       
    21 CTestExplicitSessionStep::CTestExplicitSessionStep()
       
    22 	{
       
    23 	SetTestStepName(KTestExplicitSessionStep); 
       
    24 	}
       
    25 
       
    26 
       
    27 CTestExplicitSessionStep::~CTestExplicitSessionStep()
       
    28 	{
       
    29 	}
       
    30 	
       
    31 
       
    32 void CTestExplicitSessionStep::StartClientL()
       
    33 	{
       
    34 	TPtrC uri;
       
    35 	TInt iap = 0;
       
    36 	
       
    37     if (!GetStringFromConfig(ConfigSection(), KIniUri, uri) ||
       
    38     	!GetIntFromConfig(ConfigSection(), KIAP, iap)
       
    39     	)
       
    40 		{
       
    41 		ERR_PRINTF3(_L("Problem in reading values from ini.			\
       
    42 						\nExpected fields are: \n%S\n%d"
       
    43 					  ),&KIniUri, iap);
       
    44 		SetTestStepResult(EFail);
       
    45 		return;
       
    46 		}
       
    47 
       
    48 	TBuf8<256> url8;
       
    49 	url8.Copy(uri);
       
    50 	TUriParser8 uriP; 
       
    51 	uriP.Parse( url8 );
       
    52 
       
    53 	iExplicitSession.OpenL(uriP, iap);
       
    54 	iSession = iExplicitSession.HTTPSession();
       
    55 	RStringPool strP = iSession.StringPool();
       
    56 	
       
    57 /*
       
    58 	THTTPHdrVal val;
       
    59 	RHTTPConnectionInfo cF = iSession.ConnectionInfo();
       
    60 	cF.Property(strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), val);
       
    61 	RConnection* conn = reinterpret_cast<RConnection*>(val.Int());
       
    62 	TConnectionInfoBuf buf;
       
    63 	conn->GetConnectionInfo(1, buf);
       
    64 	TInt iapId = buf().iIapId;	
       
    65 */	
       
    66 	
       
    67 	RStringF method;
       
    68 	iSession.ConnectionInfo().SetPropertyL(iSess.StringPool().StringF(HTTP::EProxyUsage,RHTTPSession::GetTable()), iSess.StringPool().StringF(HTTP::EUseProxy,RHTTPSession::GetTable()));
       
    69 	RStringF proxy = iSession.StringPool().OpenFStringL(KProxy());
       
    70 	CleanupClosePushL(proxy);
       
    71 	iSession.ConnectionInfo().SetPropertyL(iSession.StringPool().StringF(HTTP::EProxyAddress,RHTTPSession::GetTable()), proxy);
       
    72 	CleanupStack::PopAndDestroy(&proxy);
       
    73 
       
    74 	
       
    75 	method = strP.StringF(HTTP::EGET,RHTTPSession::GetTable());		
       
    76 	TRAPD(err,InvokeHttpMethodL(url8, method));
       
    77 	if (err != KErrNone)
       
    78 		{
       
    79 		ERR_PRINTF2(_L("Teststep Failed: Leave occured in CTestExplicitSessionStep::InvokeHttpMethodL: %D\n"
       
    80 					  ),err
       
    81 				   );
       
    82 		SetTestStepResult(EFail);
       
    83 		}
       
    84 	method.Close(); 
       
    85 	iExplicitSession.CancelStart();
       
    86 	RHTTPSession ss = iExplicitSession();
       
    87 	iExplicitSession.Close();
       
    88 
       
    89 	iExplicitSession.OpenL(uriP, iap, EFalse);
       
    90 	TRequestStatus iStatus = KRequestPending;
       
    91 	iExplicitSession.StartConnection(iStatus);
       
    92 	iExplicitSession.Close();
       
    93 	
       
    94 	iExplicitSession.OpenL(uriP, iap);
       
    95 	iExplicitSession.Close();
       
    96 	
       
    97 	TRAP(err, iExplicitSession.OpenL(uriP, KConnectionTypeDefault));
       
    98 	iStatus = KRequestPending;
       
    99 	iExplicitSession.StartConnection(iStatus);
       
   100 	iExplicitSession.Close();
       
   101 	}
       
   102 
       
   103 
       
   104 void CTestExplicitSessionStep::InvokeHttpMethodL(const TDesC8& aUri, RStringF aMethod)
       
   105 	{
       
   106 	TUriParser8 uri; 
       
   107 	uri.Parse( aUri );
       
   108 	
       
   109 	iTrans = iSession.OpenTransactionL(uri, *this, aMethod);
       
   110 	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
       
   111 
       
   112 	iTrans.SubmitL();
       
   113 	CActiveScheduler::Start();
       
   114 	}
       
   115 
       
   116 
       
   117 void CTestExplicitSessionStep::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
   118 	{
       
   119 	switch (aEvent.iStatus)
       
   120 		{
       
   121 		case THTTPEvent::EGotResponseHeaders:
       
   122 			{
       
   123 			RHTTPResponse resp = aTransaction.Response();
       
   124 			TInt status = resp.StatusCode();
       
   125 			RStringF statusStr = resp.StatusText();
       
   126 			TBuf<32> statusStr16;
       
   127 			statusStr16.Copy(statusStr.DesC());
       
   128 			INFO_PRINTF3(_L("Status: %D (%S)\n"),status, &statusStr16);
       
   129 
       
   130 			if (resp.HasBody() && (status >= 200) && (status < 300) && (status != 204))
       
   131 				{
       
   132 				TInt dataSize = resp.Body()->OverallDataSize();
       
   133 				if (dataSize >= 0)
       
   134 					INFO_PRINTF2(_L("Response body size is %d\n"), dataSize);
       
   135 				else
       
   136 					INFO_PRINTF1(_L("Response body size is unknown\n"));
       
   137 				}
       
   138 			} break;
       
   139 		case THTTPEvent::EGotResponseBodyData:
       
   140 			{
       
   141 			MHTTPDataSupplier* respBody;
       
   142 			respBody = aTransaction.Response().Body();
       
   143 			INFO_PRINTF1(_L("Receiving response body...\n"));
       
   144 			
       
   145 			TPtrC8 bodyData;
       
   146 			respBody->GetNextDataPart(bodyData);
       
   147 			respBody->ReleaseData();
       
   148 			} break;
       
   149 		case THTTPEvent::EResponseComplete:
       
   150 			{
       
   151 			INFO_PRINTF1(_L("\nTransaction Complete\n"));
       
   152 			} break;
       
   153 		case THTTPEvent::ESucceeded:
       
   154 			{
       
   155 			INFO_PRINTF1(_L("Transaction Successful\n"));
       
   156 			aTransaction.Close();
       
   157 			CActiveScheduler::Stop();
       
   158 			} break;
       
   159 		case THTTPEvent::EFailed:
       
   160 			{
       
   161 			INFO_PRINTF1(_L("Transaction Failed\n"));
       
   162 			aTransaction.Close();
       
   163 			CActiveScheduler::Stop();
       
   164 			} break;
       
   165 		case THTTPEvent::ERedirectedPermanently:
       
   166 			{
       
   167 			INFO_PRINTF1(_L("Permanent Redirection\n"));
       
   168 			} break;
       
   169 		case THTTPEvent::ERedirectedTemporarily:
       
   170 			{
       
   171 			INFO_PRINTF1(_L("Temporary Redirection\n"));
       
   172 			} break;
       
   173 		case THTTPEvent::ERedirectRequiresConfirmation:
       
   174  			{
       
   175 			INFO_PRINTF1(_L("Redirect requires confirmation\n"));
       
   176  			aTransaction.Close();
       
   177  			CActiveScheduler::Stop();
       
   178  			} break;
       
   179 		default:
       
   180 			{
       
   181 			INFO_PRINTF2(_L("<unrecognised event: %D>\n"), aEvent.iStatus);
       
   182 			if (aEvent.iStatus < 0)
       
   183 				{
       
   184 				aTransaction.Close();
       
   185 				CActiveScheduler::Stop();
       
   186 				}
       
   187 			} break;
       
   188 		}
       
   189 	}
       
   190 
       
   191 
       
   192 TInt CTestExplicitSessionStep::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/)
       
   193 	{
       
   194 	INFO_PRINTF2(_L("MHFRunError fired with error code %D\n"), aError);
       
   195 	return KErrNone;
       
   196 	}