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_ENVELOPE_H
28 #define SEN_SOAP_ENVELOPE_H
31 #include <SenBaseFragment.h>
32 #include <SenSoapConstants.h>
35 _LIT8(KSoapActionHeaderValueEmpty, "\"\""); // default, if not set
38 // Now declared in <SenSoapConstants.h>
39 _LIT8(KSenSoap12ContentTypeHeaderValue, "application/soap+xml; charset=\"UTF-8\"");
40 _LIT8(KSenSoap12AcceptHeaderValue, "application/soap+xml");
41 _LIT8(KSenSoapEnvelopeName, "Envelope");
42 _LIT8(KSenSoapEnvelopeQName, "S:Envelope");
44 _LIT8(KSenSoapEnvelopeXmlns, "http://schemas.xmlsoap.org/soap/envelope/");
45 _LIT8(KSenSoap12EnvelopeXmlns, "http://www.w3.org/2003/05/soap-envelope");
46 _LIT8(KSenSoapEnvelopeHeaderName, "Header");
47 _LIT8(KSenSoapEnvelopeHeaderQName, "S:Header");
48 _LIT8(KSenSoapEnvelopeBodyName, "Body");
49 _LIT8(KSenSoapEnvelopeBodyQName, "S:Body");
50 _LIT8(KSenSoapFaultName, "Fault");
52 _LIT8(KSenSoapActionHeaderName, "SOAPAction");
53 _LIT8(KSenSoapActionHeaderValueEmpty, "\"\"");
56 const TInt KStateParsingSoapHeader = 20; // ignore state (even number)
57 const TInt KStateParsingSoapBody = 40; // ignore state (even number)
58 const TInt KStateParsingSoapFault = 5; // save state (odd number)
67 // FORWARD DECLARATIONS
73 * CSenSoapEnvelope is an utility class offering capability to parse
74 * XML SOAP envelope and manipulation methods to alter its contents.
75 * Typically WSC uses this class to parse messages received through
76 * WSF HandleMessageL() and HandleErrorL() callbacks.
77 * Class has convenience methods for checking if a SOAP envelope body
78 * contains a fault and functionality to detach SOAP Fault object out
79 * from it. Also possibility to set SOAPAction HTTP header is supported.
83 class CSenSoapEnvelope : public CSenBaseFragment
85 public: // Constructors and destructor
88 * Two-phased constructor.
90 IMPORT_C static CSenSoapEnvelope* NewL();
95 IMPORT_C virtual ~CSenSoapEnvelope();
100 * Sets body of the envelope.
101 * @since Series60 3.0
102 * @param aBody Body (content) to be set.
103 * @return SOAP body (content) which was just set
105 IMPORT_C virtual TPtrC8 SetBodyL(const TDesC8& aBody);
108 * Getter for envelopes body
109 * @since Series60 3.0
110 * @return body as CSenElement
112 IMPORT_C virtual CSenElement& BodyL();
115 * Getter for envelopes header
116 * @since Series60 3.0
117 * @return header as CSenElement
119 IMPORT_C virtual CSenElement& HeaderL();
122 * Adds an element to the header.
123 * @since Series60 3.0
124 * @param aHeaderElement new child element to be
125 * added inside Header element. Ownership
126 * is always transferred to CSenSoapEnvelope.
127 * @return added CSenElement
129 IMPORT_C virtual CSenElement& AddHeaderL(CSenElement& aHeaderElement);
132 * Getter for the envelope body as a UTF-8 form XML string.
133 * @since Series60 3.0
134 * @return body as a HBufC8 pointer. Ownership is transferred to caller.
136 IMPORT_C virtual HBufC8* BodyAsStringL();
139 * Checks if this SOAP envelope body contains SOAP fault or not.
140 * @since Series60 3.0
141 * @return TBool ETrue if there is a fault, EFalse if not.
143 IMPORT_C virtual TBool IsFault();
146 * Detaches the <Fault> element from the envelope, removing the element
148 * @since Series60 3.0
149 * @return pointer to the soap fault. Caller takes the ownership.
150 * NULL if <Fault> element is non-existent.
152 IMPORT_C virtual CSenSoapFault* DetachFaultL();
155 * Gets the <Fault> element. Ownership is not transferred.
156 * NULL if not a fault.
157 * @since Series60 3.0
158 * @return reference to SOAP fault object owned by this SOAP envelope
160 IMPORT_C virtual CSenSoapFault* FaultL();
163 * Sets the SOAP action HTTP header. WSF will use this value
164 * while submitting this SOAP envelope request over HTTP/S transport.
165 * @since Series60 3.0
166 * @param aSoapAction the SOAP Action HTTP header to be set.
167 * The default value is KSenSoapActionHeaderValueEmpty, which is
168 * two double quotation marks - "" - without any character in between.
169 * SOAP specification requires double quotation marks, even if action
171 * If a string without double quotation marks is passed, it will be
172 * wrapped inside double quotation marks, added in the beginning and
173 * at the end of the actual SOAP Action string.
175 * @return newly set SOAP action header. String might have been
176 * extended to include double quotation marks, if those were missing
179 IMPORT_C virtual TPtrC8 SetSoapActionL(const TDesC8& aSoapAction);
182 * Gets the soap action header.
183 * @since Series60 3.0
184 * @return current SOAP action header, which is always wrapped
185 * inside double quotation marks. If SOAPAction has not been set
186 * for this SOAP envelope, function will return zero-length
187 * descriptor (KNullDesC8)
189 IMPORT_C virtual TPtrC8 SoapAction();
192 * Gets the soap action header.
193 * @since Series60 5.0
194 * @return current SOAP action header, which is always wrapped
195 * inside double quotation marks. If SOAPAction has not been set
196 * for this SOAP envelope, function will return zero-length
197 * descriptor (KNullDesC8)
199 IMPORT_C TPtrC8 SoapAction2() ;
202 * Method parses given piece of XML into this SOAP envelope
204 IMPORT_C void ParseL(const TDesC8& aXml);
207 * Getter for checking whether this message has at least one
208 * valid <Header> element
209 * @return ETrue, if <Header> element exists, EFalse otherwise.
211 IMPORT_C TBool HasHeader();
214 * Getter for checking whether this message has valid <Body> element
215 * @return ETrue, if <Body> element exists, EFalse otherwise.
217 IMPORT_C TBool HasBody();
220 * Getter for currently effecitve SOAP version.
221 * @return enumeration which dictates SOAP version.
223 IMPORT_C TSOAPVersion SoapVersion();
234 * This method should be called from the deriving
235 * classes ConstructL() methods.
236 * @since Series60 3.0
238 IMPORT_C void BaseConstructL(TSOAPVersion aVersion);
241 * This method should be called from the deriving
242 * classes ConstructL() methods.
243 * @since Series60 3.0
245 IMPORT_C void BaseConstructL();
250 * This method should be overridden by subclasses.
251 * Implements functionality to parse SOAP header if one is found
252 * during parsing the envelope.
253 * Parses all elements found under top <Header> element by
254 * using DOM fragment.
255 * @since Series60 3.0
256 * @param aNsUri The namespace URI of the new element
257 * @param aLocalName The local name of the new element
258 * @param aQName The qualified name of the new element
259 * @param aAttributes The attributes of the new element
261 IMPORT_C virtual void ParseHeaderL( const TDesC8& aNsUri,
262 const TDesC8& aLocalName,
263 const TDesC8& aQName,
264 const RAttributeArray& aAttributes);
266 // Functions from base classes
268 // From CSenBaseFragment
271 * Callback function which implement the XML content handler interface.
272 * This callback will occur on each start element tag found in the XML
274 * The SOAP envelope recognizes and parses the following elements and
275 * their corresponding attributes inside namespace defined in
276 * KSenSoapEnvelopeXmlns:
277 * KSenSoapEnvelopeName, "Envelope"
278 * KSenSoapHeaderName, "Header"
279 * KSenSoapBodyName, "Body"
280 * KSenSoapFault, "Fault" (only if found inside Body element)
282 * @since Series60 3.0
283 * @param aNsUri The namespace URI of the new element
284 * @param aLocalName The local name of the new element
285 * @param aQName The qualified name of the new element
286 * @param aAttributes The attributes of the new element
288 IMPORT_C virtual void StartElementL(const TDesC8& aNsUri,
289 const TDesC8& aLocalName,
290 const TDesC8& aQName,
291 const RAttributeArray& aAttributes);
294 * Callback function which implement the XML content handler interface.
295 * This callback will occur on each end element tag found in the XML
297 * @since Series60 3.0
298 * @param aNsUri The namespace URI of the new element
299 * @param aLocalName The local name of the new element
300 * @param aQName The qualified name of the new element
302 IMPORT_C virtual void EndElementL(const TDesC8& aNsUri,
303 const TDesC8& aLocalName,
304 const TDesC8& aQName);
307 // Internal members, protected so that deriving classes have access to them.
308 CSenBaseFragment* ipBodyFragment;
309 CSenBaseFragment* ipHeaderFragment;
310 HBufC8* ipSoapAction;
316 #endif // SEN_SOAP_ENVELOPE_H