(file) Return to WSMANExportResponseDecoder.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ExportClient

  1 anusha.kandepu 1.1 //%LICENSE////////////////////////////////////////////////////////////////
  2                    //
  3                    // 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                    //
 10                    // 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                    //
 17                    // The above copyright notice and this permission notice shall be included
 18                    // in all copies or substantial portions of the Software.
 19                    //
 20                    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21                    // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 anusha.kandepu 1.1 // 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                    //
 28                    //////////////////////////////////////////////////////////////////////////
 29                    //
 30                    //%/////////////////////////////////////////////////////////////////////////////
 31                    
 32                    #include <Pegasus/Common/System.h>
 33                    #include <Pegasus/Common/HTTPMessage.h>
 34                    #include <Pegasus/Common/CIMMessage.h>
 35                    #include <Pegasus/Common/Exception.h>
 36                    #include "WSMANExportResponseDecoder.h"
 37                    #include <Pegasus/Common/MessageLoader.h>
 38                    #include <Pegasus/Client/CIMClientException.h>
 39                    #include <Pegasus/ExportClient/HTTPExportResponseDecoder.h>
 40                    
 41                    PEGASUS_USING_STD;
 42                    
 43 anusha.kandepu 1.1 PEGASUS_NAMESPACE_BEGIN
 44                    
 45                    WSMANExportResponseDecoder::WSMANExportResponseDecoder(
 46                        MessageQueue* outputQueue,
 47                        MessageQueue* encoderQueue,
 48                        ClientAuthenticator* authenticator)
 49                        :MessageQueue(PEGASUS_QUEUENAME_EXPORTRESPDECODER),
 50                        _outputQueue(outputQueue),
 51                        _encoderQueue(encoderQueue),
 52                        _authenticator(authenticator)
 53                    {
 54                        PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
 55                            "WSMANExportResponseDecoder::WSMANExportResponseDecoder()");
 56                        PEG_METHOD_EXIT();
 57                    }
 58                    
 59                    WSMANExportResponseDecoder::~WSMANExportResponseDecoder()
 60                    {
 61                        PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
 62                            "WSMANExportResponseDecoder::~WSMANExportResponseDecoder()");
 63                        _outputQueue.release();
 64 anusha.kandepu 1.1     _encoderQueue.release();
 65                        _authenticator.release();
 66                        PEG_METHOD_EXIT();
 67                    }
 68                    
 69                    void WSMANExportResponseDecoder::setEncoderQueue(MessageQueue* encoderQueue)
 70                    {
 71                        PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
 72                            "WSMANExportResponseDecoder::setEncoderQueue()");
 73                        _encoderQueue.release();
 74                        _encoderQueue.reset(encoderQueue);
 75                        PEG_METHOD_EXIT();
 76                    }
 77                    
 78                    void WSMANExportResponseDecoder::handleEnqueue()
 79                    {
 80                        PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
 81                            "WSMANExportResponseDecoder::handleEnqueue()");
 82                        Message* message = dequeue();
 83                        PEGASUS_ASSERT(message != 0);
 84                        switch (message->getType())
 85 anusha.kandepu 1.1     {
 86                            case HTTP_MESSAGE:
 87                            {
 88                                HTTPMessage* httpMessage = (HTTPMessage*)message;
 89                                _handleHTTPMessage(httpMessage);
 90                                break;
 91                            }
 92                            default:
 93                                PEGASUS_ASSERT(0);
 94                                break;
 95                        }
 96                    
 97                        delete message;
 98                        PEG_METHOD_EXIT();
 99                    }
100                    
101                    void WSMANExportResponseDecoder::_handleHTTPMessage(HTTPMessage* httpMessage)
102                    {
103                        PEG_METHOD_ENTER(TRC_EXPORT_CLIENT,
104                            "WSMANExportResponseDecoder::_handleHTTPMessage()");
105                    
106 anusha.kandepu 1.1     //  Parse the HTTP WSMAN Export response message
107                        ClientExceptionMessage* exceptionMessage;
108                        char* content;
109                        Array<HTTPHeader> headers;
110                        Uint32 contentLength;
111                        Uint32 statusCode;
112                        String reasonPhrase;
113                        Boolean cimReconnect;
114                        Boolean valid;
115                        HTTPExportResponseDecoder::parseHTTPHeaders(httpMessage, exceptionMessage,
116                            headers, contentLength, statusCode, reasonPhrase, cimReconnect, valid);
117                    
118                        //  Return exception on any parse errors from the HTTP export response
119                        //  message
120                        if (!valid)
121                        {
122                            _outputQueue->enqueue(exceptionMessage);
123                            PEG_METHOD_EXIT();
124                            return;
125                        }
126                    
127 anusha.kandepu 1.1     try
128                        {
129                            if (_authenticator->checkResponseHeaderForChallenge(headers))
130                            {
131                                //
132                                // Get the original request, put that in the encoder's queue for
133                                // re-sending with authentication challenge response.
134                                //
135                    
136                                Message* reqMessage = _authenticator->releaseRequestMessage();
137                    
138                                if (cimReconnect == true)
139                                {
140                                    reqMessage->setCloseConnect(cimReconnect);
141                                    _outputQueue->enqueue(reqMessage);
142                                }
143                                else
144                                {
145                                    _encoderQueue->enqueue(reqMessage);
146                                }
147                    
148 anusha.kandepu 1.1             PEG_METHOD_EXIT();
149                                return;
150                            }
151                            else
152                            {
153                                //
154                                // Received a valid/error response from the server.
155                                // We do not need the original request message anymore, hence
156                                // delete the request message by getting the handle from the
157                                // ClientAuthenticator.
158                                //
159                                Message* reqMessage = _authenticator->releaseRequestMessage();
160                                delete reqMessage;
161                            }
162                        }
163                        catch(InvalidAuthHeader& e)
164                        {
165                            AutoPtr<CIMClientMalformedHTTPException> malformedHTTPException(
166                                new CIMClientMalformedHTTPException(e.getMessage()));
167                            AutoPtr<ClientExceptionMessage> response(
168                                new ClientExceptionMessage(malformedHTTPException.get()));
169 anusha.kandepu 1.1 
170                            malformedHTTPException.release();
171                    
172                            response->setCloseConnect(cimReconnect);
173                            _outputQueue->enqueue(response.release());
174                            PEG_METHOD_EXIT();
175                            return;
176                        }
177                    
178                        //  Validate the HTTP headers in the export response message
179                        HTTPExportResponseDecoder::validateHTTPHeaders(httpMessage, headers,
180                            contentLength, statusCode, cimReconnect, reasonPhrase, content,
181                            exceptionMessage, valid, true);
182                    
183                        //  Return exception on any errors in the HTTP headers in the export
184                        //  response message
185                        if (!valid)
186                        {
187                            _outputQueue->enqueue(exceptionMessage);
188                            PEG_METHOD_EXIT();
189                            return;
190 anusha.kandepu 1.1     }
191                    
192                        //  Decode the export response message
193                        Message* responseMessage;
194                        HTTPExportResponseDecoder::decodeWSMANExportResponse(
195                            content,
196                            cimReconnect,
197                            responseMessage,
198                            _contentLanguages,
199                            _request);
200                        _outputQueue->enqueue(responseMessage);
201                    
202                        PEG_METHOD_EXIT();
203                    }
204                    void WSMANExportResponseDecoder:: setContentLanguages(
205                        const ContentLanguageList & contentLanguages)
206                    {
207                        _contentLanguages=contentLanguages;
208                    }
209                    void WSMANExportResponseDecoder::setWsmRequest(WsmRequest* request)
210                    {
211 anusha.kandepu 1.1     _request = request;
212                    }
213                    
214                    PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2