webservices/wsstar/wsstarplugin/src/wsstarhttpclient.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:           
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 // INCLUDE FILES
       
    29 #include "wsstarhttpclient.h"
       
    30 #include "SenHttpTransportProperties.h"
       
    31 #include "SenServiceConnection.h" // public error codes
       
    32 #include "sendebug.h"
       
    33 #include "senlogger.h"
       
    34 
       
    35 //---------------------------------------------------------------------------
       
    36 // Creates and returns a new instace of this class.
       
    37 //---------------------------------------------------------------------------
       
    38 //
       
    39 CWSStarHttpClient* CWSStarHttpClient::NewL(
       
    40                                             CSIF& aSIF,
       
    41                                             CSenWSDescription* aInitializer,
       
    42                                             RFileLogger& aLogger)
       
    43     {
       
    44     CWSStarHttpClient* pNew = NewLC(aSIF, aInitializer, aLogger);
       
    45     CleanupStack::Pop();
       
    46     return pNew;
       
    47     }
       
    48 
       
    49 //---------------------------------------------------------------------------
       
    50 // Creates and returns a new instace of this class and leaves the object on the cleanup stack
       
    51 //---------------------------------------------------------------------------
       
    52 //
       
    53 CWSStarHttpClient* CWSStarHttpClient::NewLC(
       
    54                                                         CSIF& aSIF,
       
    55                                                         CSenWSDescription* aInitializer,
       
    56                                                         RFileLogger& aLogger)
       
    57     {
       
    58     CWSStarHttpClient* pNew =
       
    59         new (ELeave) CWSStarHttpClient(
       
    60                     aSIF,
       
    61                     MSenServiceDescription::EWSStarPolicyClient,
       
    62                     aInitializer,
       
    63                     aLogger);
       
    64 
       
    65     CleanupStack::PushL(pNew);
       
    66     pNew->BaseConstructL();
       
    67     return pNew;
       
    68     }
       
    69 
       
    70 //---------------------------------------------------------------------------
       
    71 // Constructor
       
    72 //---------------------------------------------------------------------------
       
    73 //
       
    74 CWSStarHttpClient::CWSStarHttpClient( CSIF& aSIF,
       
    75                                       TDescriptionClassType aType,
       
    76                                       CSenWSDescription* aInitializer,
       
    77                                       RFileLogger& aLogger )
       
    78     : CSenInternalServiceConsumer(aType, aSIF),
       
    79     iInitializer(aInitializer),
       
    80     iLog(aLogger)
       
    81     {
       
    82     }
       
    83 
       
    84 void CWSStarHttpClient::BaseConstructL()
       
    85     {
       
    86     CSenInternalServiceConsumer::ConstructL();
       
    87     iPolicySession = CWSStarServiceSession::NewL(Framework());
       
    88     iPolicySession->AddConsumerL(*this);
       
    89     iPolicySession->SetEndPointL(iInitializer->Endpoint());
       
    90     iPolicySession->InitializeFromL(*iInitializer);
       
    91     ipTransport = Framework().Manager().CreateL(*iPolicySession, NULL);        
       
    92     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarHttpClient::ConstructL");
       
    93     }
       
    94 
       
    95 //---------------------------------------------------------------------------
       
    96 // Destructor
       
    97 //---------------------------------------------------------------------------
       
    98 //
       
    99 CWSStarHttpClient::~CWSStarHttpClient()
       
   100     {
       
   101     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarHttpClient::~CWSStarHttpClient");
       
   102     if( iPolicySession )
       
   103 	    {
       
   104         TRAP_IGNORE( iPolicySession->RemoveConsumerL(*this); )
       
   105     	}
       
   106     delete ipTransport;
       
   107     delete iPolicySession;
       
   108     }
       
   109 
       
   110 
       
   111 //---------------------------------------------------------------------------
       
   112 // The most siginificant method of this class. 
       
   113 //---------------------------------------------------------------------------
       
   114 //
       
   115 TInt CWSStarHttpClient::GetHttpL( const TDesC8& aRequest,
       
   116                                   HBufC8*& apResponse,
       
   117                                   CSenWSDescription* apSD )
       
   118     {
       
   119     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarHttpClient::GetHttpL");
       
   120     TInt retVal(KErrNone);             // for returning error codes
       
   121     if( !iInitializer )
       
   122         {
       
   123         return KErrSenInternal;
       
   124         }
       
   125     TPtrC8 endpoint(iInitializer->Endpoint());    
       
   126 
       
   127     CSenHttpTransportProperties* pHttpProperties = CSenHttpTransportProperties::NewLC();
       
   128     pHttpProperties->SetHttpMethodL(CSenHttpTransportProperties::ESenHttpGet);
       
   129     _LIT8(KAcceptedHeader, "text/xml,text/plain");    
       
   130     pHttpProperties->SetAcceptL(KAcceptedHeader);
       
   131     TUint32 desiredIapId(0);
       
   132    
       
   133     if( apSD )
       
   134         {
       
   135         TInt getIapRetVal = apSD->IapId( desiredIapId );
       
   136         if ( getIapRetVal == KErrNone )
       
   137             {
       
   138             pHttpProperties->SetIapIdL( desiredIapId );
       
   139             }
       
   140         }
       
   141      //limit http timeout, 
       
   142 	pHttpProperties->SetMaxTimeToLiveL(WSStarSession::KMaxHttpTimeOut);
       
   143 	TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("CWSStarHttpClient::GetHttpL - with IAP ID (%d):"), desiredIapId));    
       
   144     HBufC8* pSerializedProperties  = pHttpProperties->AsUtf8L();
       
   145     CleanupStack::PopAndDestroy(pHttpProperties);
       
   146 
       
   147     CleanupStack::PushL(pSerializedProperties);
       
   148     TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel,( pSerializedProperties->Des() ));
       
   149     retVal = ipTransport->SubmitL(endpoint, aRequest, *pSerializedProperties, apResponse, *this);	
       
   150     TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KNormalLogLevel, _L8("CWSStarHttpClient::GetHttpL - SubmitL returned: %d"), retVal));    
       
   151 
       
   152     CleanupStack::PopAndDestroy( pSerializedProperties );
       
   153 
       
   154 #ifdef _SENDEBUG
       
   155     if( apResponse )
       
   156         {
       
   157         TPtrC8 response = apResponse->Des();
       
   158         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,"* * * * * * * * * * * * *");
       
   159         TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel, _L8("CWSStarHttpClient::GetHttpL - response (%d bytes):"), response.Length()));    
       
   160         TLSLOG_ALL(KSenCoreServiceManagerLogChannelBase  , KMaxLogLevel,( response ));
       
   161         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CSenCoreServiceManager::CreateL:");
       
   162         }
       
   163 #endif // _SENDEBUG        
       
   164 
       
   165     if( retVal != KErrNone )
       
   166         {
       
   167         delete apResponse; 
       
   168         apResponse = NULL;
       
   169         }
       
   170     return retVal;
       
   171     }
       
   172 
       
   173 //---------------------------------------------------------------------------
       
   174 // SetStatus
       
   175 //---------------------------------------------------------------------------
       
   176 //
       
   177 
       
   178 void CWSStarHttpClient::SetStatus(TInt /*aStatus */)
       
   179     {
       
   180     }
       
   181 
       
   182 //---------------------------------------------------------------------------
       
   183 // ServiceSession
       
   184 //---------------------------------------------------------------------------
       
   185 //
       
   186 CSenServiceSession* CWSStarHttpClient::ServiceSession()
       
   187     {
       
   188     return iPolicySession;
       
   189     }
       
   190 
       
   191 //---------------------------------------------------------------------------
       
   192 // Obtain Transport using a factory from Core Manager
       
   193 //---------------------------------------------------------------------------
       
   194 //
       
   195 MSenTransport& CWSStarHttpClient::TransportL()
       
   196     {
       
   197     if(!ipTransport)
       
   198         {
       
   199         // Core is capable of working as transport factory, too.
       
   200         // The returned transport instancies may or may not be
       
   201         // ECOM plugins:
       
   202         TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarHttpClient::Instantiating new transport");
       
   203         ipTransport = Framework().Manager().CreateL(*iPolicySession, iPolicySession); 
       
   204         }
       
   205     return *ipTransport;
       
   206     }
       
   207 void CWSStarHttpClient::SetClientSessionL(
       
   208                                                 CWSStarServiceSession* aSession)
       
   209     {
       
   210     TLSLOG_L(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,"CWSStarHttpClient::SetServiceSessionL");
       
   211     // free memory
       
   212     //delete iPolicySession;
       
   213     iPolicySession = aSession;
       
   214     if(iPolicySession)
       
   215         {
       
   216         iPolicySession->AddConsumerL(*this);
       
   217         }
       
   218     }
       
   219 
       
   220 //---------------------------------------------------------------------------
       
   221 // Getter for endpoint
       
   222 //---------------------------------------------------------------------------
       
   223 //
       
   224 TPtrC8 CWSStarHttpClient::Endpoint()
       
   225     {
       
   226     return iPolicySession->Endpoint();
       
   227     }
       
   228 //---------------------------------------------------------------------------
       
   229 // Getter for contract
       
   230 //---------------------------------------------------------------------------
       
   231 //
       
   232 TPtrC8 CWSStarHttpClient::Contract()
       
   233     {
       
   234     return iPolicySession->Contract();
       
   235     }
       
   236 
       
   237 //---------------------------------------------------------------------------
       
   238 // serialie to xml
       
   239 //---------------------------------------------------------------------------
       
   240 //
       
   241 void CWSStarHttpClient::WriteAsXMLToL(RWriteStream& aWriteStream)
       
   242     {
       
   243     iPolicySession->WriteAsXMLToL(aWriteStream);
       
   244     }
       
   245 
       
   246 //---------------------------------------------------------------------------
       
   247 // 
       
   248 //---------------------------------------------------------------------------
       
   249 //
       
   250 void CWSStarHttpClient::SetVersion(const TDesC8* aVersion)
       
   251     {
       
   252     iVersion = aVersion;
       
   253     }
       
   254 //---------------------------------------------------------------------------
       
   255 // 
       
   256 //---------------------------------------------------------------------------
       
   257 //    
       
   258 TBool CWSStarHttpClient::HasSuperClass( TDescriptionClassType aType )
       
   259     {
       
   260     if( aType == MSenServiceDescription::ESenInternalServiceConsumer ) // direct superclass!
       
   261         {
       
   262         // If asked type is the know *direct* father/mother, return true:
       
   263         return ETrue; 
       
   264         } 
       
   265     else
       
   266         {
       
   267         // Otherwise, ask from superclass (chain, recursively)
       
   268         return CSenInternalServiceConsumer::HasSuperClass( aType ); 
       
   269         }
       
   270     }
       
   271 void CWSStarHttpClient::SetDataTrafficDetails( TSenDataTrafficDetails& aDetails) 		
       
   272 	{
       
   273 		iHttpDetails = aDetails;
       
   274 	}
       
   275 void CWSStarHttpClient::DataTrafficDetails( TSenDataTrafficDetails& aDetails) 			
       
   276 	{
       
   277 		aDetails = iHttpDetails;
       
   278 	}
       
   279 
       
   280 // End of file
       
   281 
       
   282