webservices/wshttpchanneltransportplugin/src/senhttpsyncrequester.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 "senhttpsyncrequester.h"
       
    30 #include "senhttpchannel.h"
       
    31 #include "senlayeredhttptransportproperties.h"
       
    32 
       
    33 // =========================== MEMBER FUNCTIONS ===============================
       
    34 
       
    35 CSenHttpSyncRequester* CSenHttpSyncRequester::NewL(CSenHttpChannel* aHttpChannel)
       
    36     {
       
    37     CSenHttpSyncRequester* pNew = CSenHttpSyncRequester::NewLC(aHttpChannel, NULL);
       
    38     CleanupStack::Pop();
       
    39     return pNew;
       
    40     }
       
    41 
       
    42 CSenHttpSyncRequester* CSenHttpSyncRequester::NewLC(CSenHttpChannel* aHttpChannel)
       
    43     {
       
    44     CSenHttpSyncRequester* pNew = CSenHttpSyncRequester::NewLC(aHttpChannel, NULL);
       
    45     return pNew;
       
    46     }
       
    47 
       
    48 
       
    49 CSenHttpSyncRequester* CSenHttpSyncRequester::NewL(CSenHttpChannel* aHttpChannel,
       
    50                                                    MSenResponseObserver* aParent)
       
    51     {
       
    52     CSenHttpSyncRequester* pNew = CSenHttpSyncRequester::NewLC(aHttpChannel, aParent);
       
    53     CleanupStack::Pop();
       
    54     return pNew;
       
    55     }
       
    56 
       
    57 CSenHttpSyncRequester* CSenHttpSyncRequester::NewLC(CSenHttpChannel* aHttpChannel,
       
    58                                                     MSenResponseObserver* aParent)
       
    59     {
       
    60     CSenHttpSyncRequester* pNew =
       
    61             new (ELeave) CSenHttpSyncRequester(aHttpChannel, aParent);
       
    62     CleanupStack::PushL(pNew);
       
    63     pNew->ConstructL();
       
    64     return pNew;
       
    65     }
       
    66 
       
    67 MSenProperties& CSenHttpSyncRequester::PropertiesL()
       
    68     {
       
    69     return iParentObserver->PropertiesL();
       
    70     }
       
    71 
       
    72 CSenHttpSyncRequester::CSenHttpSyncRequester(CSenHttpChannel* aHttpChannel,
       
    73                                              MSenResponseObserver* aParent)
       
    74 
       
    75 :   CTimer(EPriorityStandard),
       
    76     iHttpChannel(aHttpChannel),
       
    77     iStatusCode(KErrNone),
       
    78     iParentObserver(aParent)
       
    79     {
       
    80     }
       
    81 
       
    82 void CSenHttpSyncRequester::ConstructL()
       
    83     {
       
    84     CTimer::ConstructL();
       
    85     CActiveScheduler::Add(this);
       
    86     isStopped = ETrue;
       
    87     }
       
    88 
       
    89 CSenHttpSyncRequester::~CSenHttpSyncRequester()
       
    90     {
       
    91     delete iContentType;
       
    92     delete iContent;
       
    93     if (!isStopped)
       
    94         {
       
    95         iSchedulerWait.AsyncStop();
       
    96         }
       
    97     }
       
    98 void CSenHttpSyncRequester::DoCancel()
       
    99     {
       
   100     CTimer::DoCancel();
       
   101     }
       
   102 void CSenHttpSyncRequester::RunL()
       
   103     {
       
   104     if (!isStopped)
       
   105         {
       
   106         iStatusCode = KErrTimedOut;
       
   107         iSchedulerWait.AsyncStop();
       
   108         }
       
   109     isStopped = ETrue;
       
   110     }
       
   111 TInt CSenHttpSyncRequester::RunError(TInt aError)
       
   112     {
       
   113     if (!isStopped)
       
   114         {
       
   115         iStatusCode = aError;
       
   116         iSchedulerWait.AsyncStop();
       
   117         }
       
   118     isStopped = ETrue;
       
   119     return aError;
       
   120     }
       
   121 
       
   122 
       
   123 /*
       
   124 // GET
       
   125 TInt CSenHttpSyncRequester::SubmitL(const TDesC8& aRequestUri,
       
   126                                              HBufC8*& aResponseContentType,
       
   127                                              HBufC8*& aResponseContent,
       
   128                                              TInt& aErrorCode)
       
   129     {
       
   130     iStatusCode = KErrNone;
       
   131     TInt submitId = iHttpChannel->SendL(*this, aRequestUri);
       
   132     iSchedulerWait.Start();
       
   133     aResponseContentType = iContentType;
       
   134     iContentType = NULL;
       
   135     aResponseContent = iContent;
       
   136     iContent = NULL;
       
   137     aErrorCode = iStatusCode;
       
   138     return submitId;
       
   139     }
       
   140 */
       
   141 
       
   142 // POST
       
   143 TInt CSenHttpSyncRequester::SubmitL(const TDesC8& aRequestUri,
       
   144                                     CSenLayeredHttpTransportProperties& aProps,
       
   145                                     const TDesC8& aRequestContent,
       
   146                                     HBufC8*& aResponseContentType,
       
   147                                     HBufC8*& aResponseContent,
       
   148                                     TInt& aErrorCode)
       
   149     {
       
   150     if (!isStopped)
       
   151         {
       
   152         iHttpChannel->CancelAllTransactions();
       
   153         iSchedulerWait.AsyncStop();
       
   154         }
       
   155     isStopped = ETrue;
       
   156     iStatusCode = KErrNone;
       
   157     this->Cancel();
       
   158     TInt submitId = iHttpChannel->SendL(*this,
       
   159                                         aRequestUri,
       
   160                                         aRequestContent,
       
   161                                         aProps);
       
   162     
       
   163     TInt timeOut(0);
       
   164     if (aProps.MaxTimeToLiveL(timeOut) == KErrNone)
       
   165         {
       
   166         this->After(timeOut * 1000000);    
       
   167         }
       
   168     
       
   169     isStopped = EFalse;
       
   170     iSchedulerWait.Start();
       
   171     this->Cancel();
       
   172     aResponseContentType = iContentType;
       
   173     iContentType = NULL;
       
   174     aResponseContent = iContent;
       
   175     iContent = NULL;
       
   176     aErrorCode = iStatusCode;
       
   177     return submitId;
       
   178     }
       
   179 
       
   180 
       
   181 void CSenHttpSyncRequester::ResponseReceivedL( TInt /*aId*/, const TAny* aContentType, HBufC8* apContent, CSenHttpTransportProperties* /*aHttpProperties*/ )
       
   182     {
       
   183     iContent = apContent; // transfers ownership of content into _this_ class
       
   184     iContentType = ((HBufC8*)aContentType)->AllocL();
       
   185     if (!isStopped)
       
   186         {
       
   187         iSchedulerWait.AsyncStop();
       
   188         }
       
   189     isStopped = ETrue;
       
   190     }
       
   191 
       
   192 void CSenHttpSyncRequester::ResponseErrorL( TInt aId, TInt aError, HBufC8* apErrorBody, CSenHttpTransportProperties* aHttpProperties  )
       
   193     {
       
   194     iStatusCode = aError;
       
   195     iContentType = NULL;
       
   196 
       
   197     if (iParentObserver)
       
   198         {
       
   199         //iContent = NULL;      To fix EPSK-76XFAN
       
   200         iParentObserver->ResponseErrorL( aId, aError, apErrorBody,  aHttpProperties);
       
   201         iContent = apErrorBody;  // To fix EPSK-76XFAN
       
   202         }
       
   203     else
       
   204         {
       
   205         iContent = apErrorBody;
       
   206         }    
       
   207         
       
   208     if (!isStopped)
       
   209         {
       
   210         iSchedulerWait.AsyncStop();
       
   211         }
       
   212     isStopped = ETrue;
       
   213     }
       
   214 
       
   215 // Propagate the http status code to remote service consumer
       
   216 void CSenHttpSyncRequester::StateChanged(TInt aRequestId, TInt aState)
       
   217 	{
       
   218     if (iParentObserver)
       
   219         {
       
   220         iParentObserver->StateChanged(aRequestId, aState);
       
   221         }	
       
   222 	}
       
   223 
       
   224 void CSenHttpSyncRequester::SetTrafficDetails(TSenDataTrafficDetails& aDetails) 
       
   225 	{
       
   226     if (iParentObserver)
       
   227         {
       
   228         iParentObserver->SetTrafficDetails(aDetails);
       
   229         }		
       
   230 	}
       
   231 
       
   232 
       
   233 //////////////////////////////////////////////////////////////////////////
       
   234 
       
   235 /*
       
   236 TInt CSenHttpSyncRequester::SubmitL(const TDesC8& aRequestUri,
       
   237                                     const TDesC8* aRequestContentType,
       
   238                                     MSenElement& aMessage, //SOAP envelope
       
   239                                     HBufC8*& aResponseContentType,
       
   240                                     HBufC8*& aResponseContent,
       
   241                                     TInt& aErrorCode)
       
   242     {
       
   243     iStatusCode = KErrNone;
       
   244 
       
   245 
       
   246     TInt submitId = iHttpChannel->SubmitL(*this,
       
   247                                         aRequestUri,
       
   248                                         aRequestContentType,
       
   249                                         aMessage);
       
   250     iSchedulerWait.Start();
       
   251     aResponseContentType = iContentType;
       
   252     iContentType = NULL;
       
   253     aResponseContent = iContent;
       
   254     iContent = NULL;
       
   255     aErrorCode = iStatusCode;
       
   256     return submitId;
       
   257     }
       
   258 */
       
   259 
       
   260 //  End of File
       
   261 
       
   262