webservices/wsprovider/src/senhostletresponse.cpp
changeset 0 62f9d29f7211
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 "senhostletresponse.h"
       
    29 
       
    30 #include <SenHttpTransportProperties.h>
       
    31 #include "senvtcptransportproperties.h"
       
    32 #include <SenParser.h>
       
    33 
       
    34 #include <MSenProperties.h>
       
    35 #include <MSenMessage.h>
       
    36 #include "senmessagecontext.h"
       
    37 #include "SenSoapMessage2.h"
       
    38 
       
    39 //using namespace SenContext;
       
    40 
       
    41 EXPORT_C CSenHostletResponse* CSenHostletResponse::NewL(const TInt aRequestId)
       
    42     {
       
    43     CSenHostletResponse* pNew = CSenHostletResponse::NewLC(aRequestId);
       
    44     CleanupStack::Pop();
       
    45     return pNew;
       
    46     }
       
    47 
       
    48 EXPORT_C CSenHostletResponse* CSenHostletResponse::NewLC(const TInt aRequestId)
       
    49     {
       
    50     CSenHostletResponse* pNew = new(ELeave) CSenHostletResponse(aRequestId);
       
    51     CleanupStack::PushL(pNew);
       
    52     pNew->BaseConstructL();
       
    53     return pNew;
       
    54     }
       
    55 
       
    56 void CSenHostletResponse::BaseConstructL()
       
    57     {
       
    58     }
       
    59 
       
    60 CSenHostletResponse::CSenHostletResponse(const TInt aRequestId)
       
    61 : iRequestId(aRequestId),
       
    62   iResponseCode(KErrNone),
       
    63   ipOwnedResponseUtf8(NULL),
       
    64   ipMessageContext(NULL)
       
    65     {
       
    66     }
       
    67     
       
    68 EXPORT_C CSenHostletResponse::~CSenHostletResponse()
       
    69     {
       
    70     delete ipOwnedResponseUtf8;
       
    71     ipOwnedResponseUtf8 = NULL;
       
    72     delete ipMessageContext;
       
    73     ipMessageContext = NULL;
       
    74     }
       
    75 
       
    76 EXPORT_C void CSenHostletResponse::SetResponseUtf8L(const TDesC8& aResponseBodyUtf8,
       
    77                                                     const TInt aResponseCode,
       
    78                                                     MSenProperties* apResponseProperties,
       
    79                                                     MSenMessage* apMessage)
       
    80     {
       
    81     HBufC8* pTemp = aResponseBodyUtf8.AllocL();
       
    82     iResponseCode = aResponseCode;
       
    83     delete ipOwnedResponseUtf8;
       
    84     ipOwnedResponseUtf8 = NULL;
       
    85     ipOwnedResponseUtf8 = pTemp;
       
    86     
       
    87 
       
    88     TInt error(KErrNone);
       
    89     MSenProperties* p = NULL;
       
    90     if( apResponseProperties && apResponseProperties->PropertiesClassType() != MSenProperties::ENotInUse )
       
    91         {
       
    92         p = apResponseProperties->Clone(error);
       
    93         }
       
    94 
       
    95     if( p )
       
    96         {
       
    97         // Create new message context
       
    98         delete ipMessageContext;  
       
    99         ipMessageContext = NULL;
       
   100         MessageContextL( p );
       
   101         }
       
   102     else
       
   103         {
       
   104         MessageContextL();
       
   105         }
       
   106         
       
   107     MSenMessageContext& ctx = MessageContextL();
       
   108     MSenMessage* pMessage = NULL;
       
   109     if( !apMessage ) 
       
   110         {
       
   111         pMessage = CSenSoapMessage2::NewL( ctx ); // ctx holds the transport properties, if such exist
       
   112         ctx.SetMessage(pMessage, ETrue);
       
   113         }
       
   114     else
       
   115         {
       
   116         pMessage = apMessage->CloneL();
       
   117         ctx.SetMessage(pMessage, ETrue);
       
   118         }        
       
   119     
       
   120     // Set the message into context, with possible properties..
       
   121     error = 0; // not used in release builds
       
   122     
       
   123 /*
       
   124     MSenProperties* pResponseProperties = NULL;
       
   125     
       
   126     if( apResponseProperties && apResponseProperties->PropertiesClassType() != MSenProperties::ENotInUse )
       
   127         {
       
   128         switch(apResponseProperties->PropertiesClassType())
       
   129             {
       
   130             case MSenProperties::ENotInUse:
       
   131                 {
       
   132                 break;
       
   133                 }
       
   134                 
       
   135             
       
   136             case MSenProperties::ESenXmlProperties:
       
   137             case MSenProperties::ESenLayeredXmlProperties: // flatten the props
       
   138                 {
       
   139                 pResponseProperties = CSenXmlProperties::NewL(); // iSerializedMessage, *pReader);
       
   140                 break;
       
   141                 }
       
   142             case MSenProperties::ESenTransportProperties:
       
   143             case MSenProperties::ESenLayeredTransportProperties: // flatten the props
       
   144                 {
       
   145                 pResponseProperties = CSenTransportProperties::NewL();
       
   146                 break;
       
   147                 }
       
   148             case MSenProperties::ESenHttpTransportProperties:
       
   149             case MSenProperties::ESenLayeredHttpTransportProperties: // flatten the props
       
   150                 {
       
   151                 pResponseProperties = CSenHttpTransportProperties::NewL();
       
   152                 break;
       
   153                 }
       
   154             case MSenProperties::ESenVtcpTransportProperties:
       
   155             case MSenProperties::ESenLayeredVtcpTransportProperties: // flatten the props
       
   156                 {
       
   157                 pResponseProperties = CSenVtcpTransportProperties::NewL();
       
   158                 break;
       
   159                 }
       
   160             default: 
       
   161                 {
       
   162                 break;
       
   163                 }
       
   164             }
       
   165             
       
   166         if( ipResponseProperties )  
       
   167             {
       
   168             HBufC8* pSerializedProperties = apResponseProperties->AsUtf8LC();
       
   169             if (pSerializedProperties && pSerializedProperties->Length()>0)
       
   170                 {
       
   171                 TRAPD( err, ipResponseProperties->ReadFromL(*pSerializedProperties); ) // suppress any parsing leave
       
   172                 TInt unused(err);
       
   173                 err = unused;
       
   174                 }
       
   175             CleanupStack::PopAndDestroy(pSerializedProperties);
       
   176             }
       
   177         }
       
   178 */
       
   179     }
       
   180 
       
   181 
       
   182 EXPORT_C MSenProperties* CSenHostletResponse::ResponseProperties()
       
   183     {
       
   184     TInt leaveCode(KErrNone);
       
   185     MSenMessageContext* pCtx = NULL;
       
   186     MSenMessage* pMessage = NULL;
       
   187     TRAP( leaveCode, pCtx = &(MessageContextL()); )
       
   188     if( !leaveCode && pCtx )
       
   189         {
       
   190         TRAP( leaveCode, pMessage = pCtx->MessageL(); )
       
   191         //pMessage = pCtx->Message();
       
   192         if( !leaveCode && pMessage )
       
   193             {
       
   194             return pMessage->Properties();
       
   195             }
       
   196         }
       
   197     return NULL; // not found
       
   198     }
       
   199     
       
   200 EXPORT_C MSenMessage* CSenHostletResponse::ResponseMessageL()
       
   201     {
       
   202     TInt leaveCode(KErrNone);
       
   203     MSenMessage* pMsg = NULL;
       
   204     TRAP( leaveCode,  pMsg = MessageContextL().MessageL(); )
       
   205     if( leaveCode == KErrNone )
       
   206         {
       
   207         return pMsg;
       
   208         }
       
   209     leaveCode = 0; // ignored
       
   210     return NULL;        
       
   211     }
       
   212     
       
   213 
       
   214 EXPORT_C HBufC8* CSenHostletResponse::ExtractResponseUtf8()
       
   215     {
       
   216     HBufC8* pResult = ipOwnedResponseUtf8;
       
   217     ipOwnedResponseUtf8 = NULL;
       
   218     return pResult;
       
   219     }
       
   220 
       
   221 
       
   222 EXPORT_C TPtrC8 CSenHostletResponse::ResponseUtf8()
       
   223     {
       
   224     if(ipOwnedResponseUtf8)
       
   225         {
       
   226         return *ipOwnedResponseUtf8;
       
   227         }
       
   228     else
       
   229         {
       
   230         return KNullDesC8();
       
   231         }
       
   232     }
       
   233 
       
   234 EXPORT_C TInt CSenHostletResponse::RequestId() const
       
   235     {
       
   236     return iRequestId;
       
   237     }
       
   238 
       
   239 EXPORT_C TInt CSenHostletResponse::ResponseCode() const
       
   240     {
       
   241     return iResponseCode;
       
   242     }
       
   243 
       
   244 
       
   245 MSenMessageContext& CSenHostletResponse::MessageContextL(MSenProperties* apProperties)
       
   246     {
       
   247     if( !ipMessageContext )
       
   248         {
       
   249         if( apProperties )
       
   250             ipMessageContext = CSenMessageContext::NewL(SenContext::EOutgoing, apProperties);
       
   251         else
       
   252             {
       
   253             CSenXmlProperties* p = CSenXmlProperties::NewL();
       
   254             CleanupStack::PushL(p);
       
   255             ipMessageContext = CSenMessageContext::NewL(SenContext::EOutgoing, p);
       
   256             CleanupStack::Pop(p);
       
   257             }
       
   258         }
       
   259     return *ipMessageContext;
       
   260     }
       
   261     
       
   262     
       
   263 // END OF FILE
       
   264 
       
   265 
       
   266