1 martin 1.50 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.51 //
|
3 martin 1.50 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.51 //
|
10 martin 1.50 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.51 //
|
17 martin 1.50 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.51 //
|
20 martin 1.50 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.51 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.50 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.51 //
|
28 martin 1.50 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/Config.h>
33 #include <iostream>
|
34 kumpf 1.9 #include <Pegasus/Common/Constants.h>
|
35 mike 1.2 #include <Pegasus/Common/XmlParser.h>
36 #include <Pegasus/Common/XmlReader.h>
37 #include <Pegasus/Common/System.h>
38 #include <Pegasus/Common/XmlWriter.h>
39 #include <Pegasus/Common/HTTPMessage.h>
40 #include <Pegasus/Common/CIMMessage.h>
|
41 kumpf 1.19 #include <Pegasus/Common/Exception.h>
|
42 mike 1.2 #include "CIMExportResponseDecoder.h"
43
|
44 humberto 1.22 // l10n
45 #include <Pegasus/Common/MessageLoader.h>
46
|
47 mike 1.2 PEGASUS_USING_STD;
48
49 PEGASUS_NAMESPACE_BEGIN
50
51 CIMExportResponseDecoder::CIMExportResponseDecoder(
|
52 kumpf 1.49 MessageQueue* outputQueue,
53 MessageQueue* encoderQueue,
54 ClientAuthenticator* authenticator)
55 : MessageQueue(PEGASUS_QUEUENAME_EXPORTRESPDECODER),
56 _outputQueue(outputQueue),
57 _encoderQueue(encoderQueue),
58 _authenticator(authenticator)
|
59 mike 1.2 {
|
60 kumpf 1.49 PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
61 "CIMExportResponseDecoder::CIMExportResponseDecoder()");
|
62 kumpf 1.32 PEG_METHOD_EXIT();
|
63 mike 1.2 }
64
65 CIMExportResponseDecoder::~CIMExportResponseDecoder()
66 {
|
67 kumpf 1.49 PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
68 "CIMExportResponseDecoder::~CIMExportResponseDecoder()");
|
69 a.arora 1.31 _outputQueue.release();
70 _encoderQueue.release();
71 _authenticator.release();
|
72 kumpf 1.32 PEG_METHOD_EXIT();
|
73 mike 1.2 }
74
|
75 kumpf 1.49 void CIMExportResponseDecoder::setEncoderQueue(MessageQueue* encoderQueue)
|
76 mike 1.2 {
|
77 kumpf 1.49 PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
78 "CIMExportResponseDecoder::setEncoderQueue()");
79 _encoderQueue.release();
80 _encoderQueue.reset(encoderQueue);
81 PEG_METHOD_EXIT();
|
82 mike 1.2 }
83
|
84 kumpf 1.19 void CIMExportResponseDecoder::handleEnqueue()
|
85 mike 1.2 {
|
86 kumpf 1.49 PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
87 "CIMExportResponseDecoder::handleEnqueue()");
88 Message* message = dequeue();
89
90 PEGASUS_ASSERT(message != 0);
|
91 kumpf 1.19
|
92 kumpf 1.49 switch (message->getType())
93 {
94 case HTTP_MESSAGE:
95 {
96 HTTPMessage* httpMessage = (HTTPMessage*)message;
97 _handleHTTPMessage(httpMessage);
98 break;
99 }
100
101 default:
|
102 dl.meetei 1.52 PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);)
|
103 kumpf 1.49 break;
104 }
|
105 mike 1.2
|
106 kumpf 1.49 delete message;
107 PEG_METHOD_EXIT();
|
108 mday 1.4 }
|
109 mike 1.2
110 void CIMExportResponseDecoder::_handleHTTPMessage(HTTPMessage* httpMessage)
111 {
|
112 kumpf 1.49 PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
|
113 carolann.graves 1.48 "CIMExportResponseDecoder::_handleHTTPMessage()");
|
114 mday 1.4
|
115 j.alex 1.38 //
|
116 carolann.graves 1.48 // Parse the HTTP CIM Export response message
|
117 j.alex 1.38 //
|
118 carolann.graves 1.48 ClientExceptionMessage* exceptionMessage;
119 char* content;
120 Array<HTTPHeader> headers;
121 Uint32 contentLength;
122 Uint32 statusCode;
123 String reasonPhrase;
124 Boolean cimReconnect;
125 Boolean valid;
126 HTTPExportResponseDecoder::parseHTTPHeaders(httpMessage, exceptionMessage,
127 headers, contentLength, statusCode, reasonPhrase, cimReconnect, valid);
|
128 mday 1.4
|
129 kumpf 1.19 //
|
130 carolann.graves 1.48 // Return exception on any parse errors from the HTTP export response
131 // message
|
132 kumpf 1.19 //
|
133 carolann.graves 1.48 if (!valid)
|
134 kumpf 1.19 {
|
135 carolann.graves 1.48 _outputQueue->enqueue(exceptionMessage);
136 PEG_METHOD_EXIT();
137 return;
|
138 kumpf 1.19 }
|
139 mday 1.4
|
140 kumpf 1.49 try
141 {
142 if (_authenticator->checkResponseHeaderForChallenge(headers))
143 {
144 //
145 // Get the original request, put that in the encoder's queue for
146 // re-sending with authentication challenge response.
147 //
148
149 Message* reqMessage = _authenticator->releaseRequestMessage();
150
151 if (cimReconnect == true)
152 {
153 reqMessage->setCloseConnect(cimReconnect);
154 _outputQueue->enqueue(reqMessage);
155 }
156 else
157 {
158 _encoderQueue->enqueue(reqMessage);
159 }
160
161 kumpf 1.49 PEG_METHOD_EXIT();
162 return;
163 }
164 else
165 {
166 //
167 // Received a valid/error response from the server.
168 // We do not need the original request message anymore, hence
169 // delete the request message by getting the handle from the
170 // ClientAuthenticator.
171 //
172 Message* reqMessage = _authenticator->releaseRequestMessage();
173 delete reqMessage;
174 }
|
175 kumpf 1.19 }
176 catch(InvalidAuthHeader& e)
177 {
|
178 a.arora 1.31 AutoPtr<CIMClientMalformedHTTPException> malformedHTTPException(
179 new CIMClientMalformedHTTPException(e.getMessage()));
180 AutoPtr<ClientExceptionMessage> response(
181 new ClientExceptionMessage(malformedHTTPException.get()));
182
183 malformedHTTPException.release();
|
184 kumpf 1.19
|
185 j.alex 1.38 response->setCloseConnect(cimReconnect);
|
186 a.arora 1.31 _outputQueue->enqueue(response.release());
|
187 kumpf 1.32 PEG_METHOD_EXIT();
|
188 kumpf 1.19 return;
189 }
190
|
191 carolann.graves 1.48 //
192 // Validate the HTTP headers in the export response message
193 //
194 HTTPExportResponseDecoder::validateHTTPHeaders(httpMessage, headers,
195 contentLength, statusCode, cimReconnect, reasonPhrase, content,
196 exceptionMessage, valid);
|
197 kumpf 1.19
198 //
|
199 carolann.graves 1.48 // Return exception on any errors in the HTTP headers in the export
200 // response message
|
201 kumpf 1.19 //
|
202 carolann.graves 1.48 if (!valid)
|
203 kumpf 1.19 {
|
204 carolann.graves 1.48 _outputQueue->enqueue(exceptionMessage);
|
205 kumpf 1.32 PEG_METHOD_EXIT();
|
206 kumpf 1.19 return;
207 }
|
208 mday 1.4
|
209 carolann.graves 1.48 //
210 // Decode the export response message
211 //
212 Message* responseMessage;
213 HTTPExportResponseDecoder::decodeExportResponse(content, cimReconnect,
214 responseMessage);
215 _outputQueue->enqueue(responseMessage);
|
216 mike 1.2
|
217 kumpf 1.32 PEG_METHOD_EXIT();
|
218 mike 1.2 }
219
220 PEGASUS_NAMESPACE_END
|