2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: CSenSoapEnvelope is an utility class offering capability to
15 * parse XML SOAP envelope and manipulation methods to alter its
27 #ifndef SEN_SOAP_ENVELOPE2_H
28 #define SEN_SOAP_ENVELOPE2_H
31 #include <SenDomFragmentBase.h>
32 #include <SenSoapConstants.h>
33 #include <MSenMessage.h>
37 // Now declared in <SenSoapConstants.h>
38 _LIT8(KSenSoapEnvelopeName, "Envelope");
39 _LIT8(KSenSoapEnvelopePrefix, "S");
40 _LIT8(KSenSoapEnvelopeXmlns, "http://schemas.xmlsoap.org/soap/envelope/");
41 _LIT8(KSenSoap12EnvelopeXmlns, "http://www.w3.org/2003/05/soap-envelope");
42 _LIT8(KSenSoapEnvelopeHeaderName, "Header");
43 _LIT8(KSenSoapEnvelopeHeaderQName, "S:Header");
44 _LIT8(KSenSoapEnvelopeBodyName, "Body");
45 _LIT8(KSenSoapEnvelopeBodyQName, "S:Body");
46 _LIT8(KSenSoapFaultName, "Fault");
48 _LIT8(KSenSoapActionHeaderName, "SOAPAction");
49 _LIT8(KSenSoapActionHeaderValueEmpty, "\"\"");
51 const TInt KStateParsingSoapHeader = 20; // ignore state (even number)
52 const TInt KStateParsingSoapBody = 40; // ignore state (even number)
53 const TInt KStateParsingSoapFault = 5; // save state (odd number)
62 // FORWARD DECLARATIONS
64 class CSenTransportProperties;
65 class CSenMessageContext;
66 class MSenMessageContext;
71 * CSenSoapEnvelope is an utility class offering capability to parse
72 * XML SOAP envelope and manipulation methods to alter its contents.
73 * Typically WSC uses this class to parse messages received through
74 * WSF HandleMessageL() and HandleErrorL() callbacks.
75 * Class has convenience methods for checking if a SOAP envelope body
76 * contains a fault and functionality to detach SOAP Fault object out
77 * from it. Also possibility to set SOAPAction HTTP header is supported.
81 class CSenSoapEnvelope2 : public CSenFragmentBase, public MSenMessage
83 public: // Constructors and destructor
86 * Two-phased constructor.
88 IMPORT_C static CSenSoapEnvelope2* NewL();
91 * Two-phased constructor.
93 IMPORT_C static CSenSoapEnvelope2* NewLC();
96 * Two-phased constructor.
98 IMPORT_C static CSenSoapEnvelope2* NewL(MSenMessageContext& aContext);
101 * Two-phased constructor.
103 IMPORT_C static CSenSoapEnvelope2* NewLC(MSenMessageContext& aContext);
106 * Two-phased copy constructor.
108 IMPORT_C static CSenSoapEnvelope2* NewL(CSenSoapEnvelope2& aEnvelope);
111 * Two-phased copy constructor.
113 IMPORT_C static CSenSoapEnvelope2* NewLC(CSenSoapEnvelope2& aEnvelope);
118 IMPORT_C virtual ~CSenSoapEnvelope2();
123 * Sets body of the envelope.
124 * @since Series60 4.0
125 * @param aBody Body (content) to be set.
126 * @return SOAP body (content) which was just set
128 IMPORT_C virtual TPtrC8 SetBodyL(const TDesC8& aBody);
131 * Sets body of the envelope.
132 * @since Series60 4.0
133 * @param aBody Body (content) to be set.
134 * @return SOAP body (content) which was just set
136 IMPORT_C virtual TXmlEngElement SetBodyL(TXmlEngElement aBodyElement);
139 * Getter for envelopes body
140 * @since Series60 4.0
141 * @return body as TXmlEngElement
143 IMPORT_C virtual TXmlEngElement BodyL();
146 * Getter for envelopes header
147 * @since Series60 4.0
148 * @return header as TXmlEngElement
150 IMPORT_C virtual TXmlEngElement HeaderL();
153 * Adds an element to the header.
154 * @since Series60 4.0
155 * @param aHeaderElement new child element to be
156 * added inside Header element. Ownership
157 * is always transferred to CSenSoapEnvelope.
158 * @return added TXmlEngElement
160 IMPORT_C virtual TXmlEngElement AddHeaderL(TXmlEngElement aHeaderElement);
163 * Getter for the envelope body as a UTF-8 form XML string.
164 * @since Series60 4.0
165 * @return body as a HBufC8 pointer. Ownership is transferred to caller.
167 IMPORT_C virtual HBufC8* BodyAsStringL();
170 * Checks if this SOAP envelope body contains SOAP fault or not.
171 * @since Series60 4.0
172 * @return TBool ETrue if there is a fault, EFalse if not.
174 IMPORT_C virtual TBool IsFault();
177 * Detaches the <Fault> element from the envelope, removing the element
179 * @since Series60 4.0
180 * @return pointer to the soap fault. Caller takes the ownership.
181 * NULL if <Fault> element is non-existent.
183 IMPORT_C virtual CSenSoapFault2* DetachFaultL();
186 * Gets the <Fault> element. Ownership is not transferred.
187 * NULL if not a fault.
188 * @since Series60 4.0
189 * @return reference to SOAP fault object owned by this SOAP envelope
191 IMPORT_C virtual CSenSoapFault2* FaultL();
194 * Sets the SOAP action HTTP header. WSF will use this value
195 * while submitting this SOAP envelope request over HTTP/S transport.
196 * @since Series60 4.0
197 * @param aSoapAction the SOAP Action HTTP header to be set.
198 * The default value is KSenSoapActionHeaderValueEmpty, which is
199 * two double quotation marks - "" - without any character in between.
200 * SOAP specification requires double quotation marks, even if action
202 * If a string without double quotation marks is passed, it will be
203 * wrapped inside double quotation marks, added in the beginning and
204 * at the end of the actual SOAP Action string.
206 * @return newly set SOAP action header. String might have been
207 * extended to include double quotation marks, if those were missing
210 IMPORT_C virtual TPtrC8 SetSoapActionL(const TDesC8& aSoapAction);
213 * Gets the soap action header.
214 * @since Series60 4.0
215 * @return current SOAP action header, which is always wrapped
216 * inside double quotation marks. If SOAPAction has not been set
217 * to this SOAP envelope instance, function will return zero-length
218 * descriptor (KNullDesC8)
220 IMPORT_C virtual TPtrC8 SoapAction();
223 * Getter for checking whether this message has at least one
224 * valid <Header> element
225 * @return ETrue, if <Header> element exists, EFalse otherwise.
227 IMPORT_C TBool HasHeader();
230 * Getter for checking whether this message has valid <Body> element
231 * @return ETrue, if <Body> element exists, EFalse otherwise.
233 IMPORT_C TBool HasBody();
236 * Getter for currently effecitve SOAP version.
237 * @return enumeration which dictates SOAP version.
239 IMPORT_C virtual TSOAPVersion SoapVersion();
241 public: // From MSenMessage
242 IMPORT_C virtual TClass Type();
243 IMPORT_C virtual TDirection Direction();
244 IMPORT_C virtual TInt SetContext(MSenMessageContext* apOwnedContext);
245 IMPORT_C virtual MSenMessageContext* Context();
246 IMPORT_C virtual TInt SetProperties(MSenProperties* apOwnedProperties);
247 IMPORT_C virtual MSenProperties* Properties();
249 IMPORT_C virtual TBool IsSafeToCast(TClass aType);
250 IMPORT_C virtual TInt TxnId();
251 IMPORT_C virtual MSenMessage* CloneL();
260 * This method should be called from the deriving
261 * classes ConstructL() methods.
262 * @since Series60 4.0
264 IMPORT_C void BaseConstructL(TSOAPVersion aVersion);
267 * This method should be called from the deriving
268 * classes ConstructL() methods.
269 * @since Series60 4.0
271 IMPORT_C void BaseConstructL();
274 * This method should be called from the deriving
275 * classes ConstructL() methods.
276 * @since Series60 4.0
278 IMPORT_C void BaseConstructL(MSenMessageContext& aMessage);
281 * This method should be called from the deriving
282 * classes ConstructL() methods.
283 * @since Series60 4.0
285 IMPORT_C void BaseConstructL(MSenMessageContext& aMessage,
286 TSOAPVersion aVersion);
289 * This method should be called from the deriving
290 * classes ConstructL() methods.
291 * @since Series60 4.0
293 IMPORT_C void BaseConstructL(CSenSoapEnvelope2& aEnvelope);
298 * This method should be overridden by subclasses.
299 * Implements functionality to parse SOAP header if one is found
300 * during parsing the envelope.
301 * Parses all elements found under top <Header> element by
302 * using DOM fragment.
303 * @since Series60 4.0
304 * @param aNsUri The namespace URI of the new element
305 * @param aLocalName The local name of the new element
306 * @param aQName The qualified name of the new element
307 * @param aAttributes The attributes of the new element
309 IMPORT_C virtual void ParseHeaderL(const RTagInfo& aElement,
310 const RAttributeArray& aAttributes);
312 // Functions from base classes
314 // From CSenFragmentBase
315 IMPORT_C virtual void OnStartElementL(const RTagInfo& aElement,
316 const RAttributeArray& aAttributes,
319 IMPORT_C virtual void OnEndElementL(const RTagInfo& aElement,
322 IMPORT_C virtual CSenFragmentBase* CreateBodyFragmentL(const TDesC8& aNsUri,
323 const TDesC8& aLocalName,
324 const TDesC8& aPrefix,
325 const RAttributeArray& aAttributes,
326 TXmlEngElement& aParent,
327 RSenDocument& aOwnerDocument);
330 // Internal members, protected so that deriving classes have access to them.
331 CSenFragmentBase* ipBodyFragment;
332 CSenFragmentBase* ipHeaderFragment;
333 HBufC8* ipSoapAction;
336 MSenProperties* ipProperties; // owned => safe upward cast is performed in de-alloc
337 MSenMessageContext* ipNotOwnedContext; // owned => safe upward cast is performed in de-alloc
342 TDirection iDirection;
345 #endif // SEN_SOAP_ENVELOPE_H