webservices/wshttpchanneltransportplugin/src/senmtomtxnstate.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 // INCLUDE FILES
       
    26 #include <http.h>
       
    27 
       
    28 #include "senmtomtxnstate.h"
       
    29 #include "senhttpchannel.h"
       
    30 #include "sendebug.h"
       
    31 #include "senlogger.h"
       
    32 
       
    33 
       
    34 // =========================== MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // ----------------------------------------------------------------------------
       
    37 // CSenMtomTxnState::CSenMtomTxnState
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CSenMtomTxnState::CSenMtomTxnState(MSenResponseObserver& aObserver)
       
    43     : CSenMultiPartTxnState(aObserver)
       
    44    	{
       
    45     }
       
    46     
       
    47 CSenMtomTxnState* CSenMtomTxnState::NewL(MSenResponseObserver& aObserver,
       
    48                           		     	 const TDesC8* aUri,
       
    49                                    		 const TDesC8& aSoapAction,
       
    50                                    		 CSenSoapEnvelope2& aSoapEnvelope2)
       
    51                                    		 
       
    52     {
       
    53     CSenMtomTxnState* pNew = NewLC( aObserver, aUri, aSoapAction,
       
    54                                 	aSoapEnvelope2);
       
    55     CleanupStack::Pop(pNew);
       
    56     return pNew;
       
    57     }
       
    58 
       
    59 CSenMtomTxnState* CSenMtomTxnState::NewLC(MSenResponseObserver& aObserver,
       
    60                                   		  const TDesC8* aUri,
       
    61                                   		  const TDesC8& aSoapAction,
       
    62                                   		  CSenSoapEnvelope2& aSoapEnvelope2)
       
    63    
       
    64     {
       
    65     CSenMtomTxnState* pNew = new (ELeave) CSenMtomTxnState(aObserver);;
       
    66     CleanupStack::PushL(pNew);
       
    67     pNew->ConstructL(aUri, aSoapAction, aSoapEnvelope2);
       
    68     return pNew;
       
    69     }
       
    70 
       
    71 
       
    72 void CSenMtomTxnState::ConstructL(const TDesC8* aUri,
       
    73                          	      const TDesC8& aSoapAction,
       
    74                          	      CSenSoapEnvelope2& aSoapEnvelope2)
       
    75     {
       
    76     
       
    77     __ASSERT_ALWAYS(aUri != NULL,
       
    78                     User::Panic(KRequestUriNullPanicText,
       
    79                                 CSenHttpChannel::ERequestUriNull));
       
    80     iRequestUri = aUri->AllocL();
       
    81     iSoapAction.CreateL(aSoapAction.Length());
       
    82     iSoapAction.Copy(aSoapAction);
       
    83     
       
    84     if(!&aSoapEnvelope2)
       
    85 		{
       
    86 		iHasRequestBody = EFalse;
       
    87 		User::Panic(KMultiPartNoRequestMessagePanicText, SenMultiPartUtils::EMultiPartNoRequestMessage);
       
    88 		}
       
    89     TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("CSenMtomTxnState::ConstructL")));
       
    90       	
       
    91    	iMessage = &aSoapEnvelope2; // not owned
       
    92    	RSenDocument doc = aSoapEnvelope2.AsDocumentL();
       
    93  	doc.GetDataContainerList(iBinaryDataList);
       
    94 
       
    95  	iCountDataParts = 3 + iBinaryDataList.Count()*2; //how many parts there are in XOP 
       
    96 	iHasRequestBody = ETrue;
       
    97     }
       
    98     
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // creates HTTP content type header for XOP message
       
   102 //
       
   103 // HTTP content type header for SOAP v1.1 should be the next:
       
   104 // Content-Type: Multipart/Related;boundary=MIME_boundary;type="application/xop+xml";
       
   105 // start="<>"; start-info="text/xml"
       
   106 //
       
   107 // HTTP content type header for SOAP v1.2 should be the next:
       
   108 // Content-Type: Multipart/Related;boundary=MIME_boundary;type="application/xop+xml";
       
   109 // start="<>";start-info="application/soap+xml"
       
   110 //
       
   111 // Note: 1.it's one line without return carrige
       
   112 //       2."boundary" is generated as <rundomNumber>
       
   113 //       3."start" is generated as <randomNumber>@<homeTime>
       
   114 //       4."actionVal12" = SoapAction from transport properties
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CSenMtomTxnState::SetContentTypeHeaderL(const RHTTPSession aSession, RHTTPHeaders aHeaders)
       
   118 	{
       
   119 	_LIT8(KMultipartRelated,"Multipart/Related");	//CodeScannerWarning
       
   120 	_LIT8(KBoundry,"boundary");
       
   121 	_LIT8(KType,"type");
       
   122 	_LIT8(KStart,"start");
       
   123 	_LIT8(KStartInfo,"start-info");
       
   124     _LIT8(KApplicationXop,"\"application/xop+xml\"");
       
   125     _LIT8(KApplicationSoap,"\"application/soap+xml\"");
       
   126     _LIT8(KTextXml,"\"text/xml\"");
       
   127     _LIT8(KSlashLessthan,"\"<");
       
   128 	_LIT8(KSlashGreaterthan,">\"");
       
   129 	SenMultiPartUtils::GenerateRandomRootCidL(iRootCid);
       
   130 	RBuf8 rootCid(NULL);
       
   131 	rootCid.ReAllocL(4+iRootCid.Length());
       
   132 	CleanupClosePushL(rootCid);
       
   133     rootCid.Append(KSlashLessthan);
       
   134 	rootCid.Append(iRootCid);
       
   135 	rootCid.Append(KSlashGreaterthan);
       
   136 	 
       
   137 	SenMultiPartUtils::GenerateRandomBoundaryL(iMimeBoundaryOut);
       
   138 
       
   139 	RStringF multipartRelated = aSession.StringPool().OpenFStringL(KMultipartRelated);
       
   140 	RStringF boundary         = aSession.StringPool().OpenFStringL(KBoundry);
       
   141 	RStringF boundaryVal      = aSession.StringPool().OpenFStringL(iMimeBoundaryOut);
       
   142 	RStringF type             = aSession.StringPool().OpenFStringL(KType);
       
   143 	RStringF typeVal          = aSession.StringPool().OpenFStringL(KApplicationXop);
       
   144 	RStringF start            = aSession.StringPool().OpenFStringL(KStart);
       
   145 	RStringF startVal         = aSession.StringPool().OpenFStringL(rootCid);
       
   146 	RStringF startInfo        = aSession.StringPool().OpenFStringL(KStartInfo);
       
   147 	RStringF startInfoVal11   = aSession.StringPool().OpenFStringL(KTextXml);
       
   148 	RStringF startInfoVal12   = aSession.StringPool().OpenFStringL(KApplicationSoap);
       
   149 	
       
   150 	CleanupStack::PopAndDestroy(&rootCid);
       
   151 	
       
   152 	THTTPHdrVal contentTypeVal(multipartRelated);
       
   153 	THTTPHdrVal boundVal(boundaryVal);
       
   154 	THTTPHdrVal tVal(typeVal);
       
   155 	THTTPHdrVal stVal(startVal);
       
   156 	
       
   157 	THTTPHdrVal stInfoVal;
       
   158 
       
   159 	switch (((CSenSoapEnvelope2*)iMessage)->SoapVersion())
       
   160 		{
       
   161  		case ESOAP11:
       
   162 			{
       
   163 			stInfoVal = startInfoVal11;
       
   164 			break;
       
   165 			}
       
   166 		case ESOAP12:
       
   167 			{
       
   168 			stInfoVal = startInfoVal12;	
       
   169 			break;
       
   170 			}
       
   171 		default:
       
   172 			{
       
   173         	User::Panic(KMultiPartSoapVersionInvalidPanicText, SenMultiPartUtils::EMultiPartSoapVersionInvalid);			}			
       
   174 		    }
       
   175 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   176 					   contentTypeVal, boundary, boundVal);
       
   177 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   178 				       contentTypeVal, type, tVal);
       
   179 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   180 					   contentTypeVal, start, stVal);
       
   181 	aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   182 					   contentTypeVal, startInfo, stInfoVal);
       
   183 
       
   184 					   
       
   185     if (((CSenSoapEnvelope2*)iMessage)->SoapVersion() == ESOAP12)
       
   186         {
       
   187       	RStringF action           = aSession.StringPool().OpenFStringL(_L8("action"));
       
   188     	RStringF actionVal12      = aSession.StringPool().OpenFStringL(iSoapAction);
       
   189     	
       
   190         aHeaders.SetFieldL(aSession.StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), 
       
   191 		    			   contentTypeVal, action, actionVal12);
       
   192     	action.Close();
       
   193 	    actionVal12.Close();
       
   194         }
       
   195 
       
   196 	multipartRelated.Close();
       
   197 	boundary.Close();         
       
   198 	boundaryVal.Close();      
       
   199 	type.Close();             
       
   200 	typeVal.Close();          
       
   201 	start.Close();            
       
   202 	startVal.Close();         
       
   203 	startInfo.Close();        
       
   204 	startInfoVal11.Close();   
       
   205 	startInfoVal12.Close();
       
   206 	}
       
   207 // ---------------------------------------------------------------------
       
   208 // creates SoapEnvelope in Request
       
   209 // ---------------------------------------------------------------------
       
   210 //    
       
   211 void CSenMtomTxnState::MessageL()
       
   212     {
       
   213     // iCurrentPart == XOP envelope:
       
   214     SenMultiPartUtils::SerializeMessageL(*(CSenSoapEnvelope2*)iMessage, iCurrentPart);
       
   215     TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("CSenMtomTxnState::GetNextDataPart - aDataPart (XOP Envelope):")));
       
   216     iCurPart = ETrue; 
       
   217     }
       
   218 
       
   219 //  End of File