(file) Return to WSMANExportClient.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/Constants.h>
 33                    #include <Pegasus/WsmServer/WsmWriter.h>
 34                    #include <Pegasus/WsmServer/WsmRequest.h>
 35                    #include <Pegasus/WsmServer/CimToWsmResponseMapper.h>
 36                    #include <Pegasus/ExportClient/WSMANExportClient.h>
 37 anusha.kandepu 1.2 #include <Pegasus/Common/TimeValue.h>
 38 anusha.kandepu 1.1 
 39                    PEGASUS_USING_STD;
 40                    
 41                    PEGASUS_NAMESPACE_BEGIN
 42                    
 43                    WSMANExportClient::WSMANExportClient(
 44                        HTTPConnector* httpConnector,
 45 anusha.kandepu 1.2     Monitor* monitor,
 46 anusha.kandepu 1.1     Uint32 timeoutMilliseconds)
 47                        :
 48                        ExportClient(PEGASUS_QUEUENAME_WSMANEXPORTCLIENT,
 49                            httpConnector,
 50 anusha.kandepu 1.2         timeoutMilliseconds,
 51                            monitor)
 52 anusha.kandepu 1.1 {
 53                        PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, 
 54                            "WSMANExportClient::WSMANExportClient()");
 55                        PEG_METHOD_EXIT();
 56                    }
 57                    
 58                    WSMANExportClient::~WSMANExportClient()
 59                    {
 60                        PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, 
 61                            "WSMANExportClient::~WSMANExportClient()");
 62                        disconnect();
 63                        PEG_METHOD_EXIT();
 64                    }
 65                    
 66                    void WSMANExportClient::exportIndication(
 67                        const String& url,
 68                        const CIMInstance& instanceName,
 69                        const ContentLanguageList& contentLanguages,
 70                        const String& toPath)    
 71                    {
 72                        PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, 
 73 anusha.kandepu 1.1         "WSMANExportClient::exportIndication()");
 74                        try
 75                        {
 76                            CimToWsmResponseMapper wsmMapper;
 77                            WsmInstance wsmInstance;
 78                            wsmMapper.convertCimToWsmInstance(url, instanceName, 
 79                                wsmInstance, PEGASUS_INSTANCE_NS);
 80                            WsmRequest * request = new WsExportIndicationRequest(
 81                                WsmUtils::getMessageId(),
 82                                url,
 83                                toPath,
 84                                wsmInstance);
 85                    
 86                            request->contentLanguages = contentLanguages;
 87 anusha.kandepu 1.2         if(_wsmanResponseDecoder != NULL)
 88                            {
 89                                _wsmanResponseDecoder->setWsmRequest(request);
 90                                _wsmanResponseDecoder->setContentLanguages(contentLanguages);
 91                            }
 92                    
 93 anusha.kandepu 1.3         PEG_TRACE ((TRC_EXPORT_CLIENT, Tracer::LEVEL4,
 94 anusha.kandepu 1.1             "Exporting %s Indication for destination %s:%d%s",
 95                                (const char*)(instanceName.getClassName().getString().
 96                                getCString()),
 97                                (const char*)(_connectHost.getCString()), _connectPortNumber,
 98                                (const char*)(url.getCString())));
 99                    
100                    
101 anusha.kandepu 1.3         Boolean ackReceived = _doRequest(request,WS_EXPORT_INDICATION);
102                            //ackReceived flag will be true only if the delivery mode is
103                            // PUSH_WITH_ACK and if we get acknowledgement from the listner. 
104                            if(ackReceived)
105                            {
106                                PEG_TRACE ((TRC_EXPORT_CLIENT, Tracer::LEVEL4,
107                                    "%s Indication for destination %s:%d%s exported successfully"
108                                    "and got acknowledgement from the listner",
109                                    (const char*)(instanceName.getClassName().getString().
110                                    getCString()),
111                                    (const char*)(_connectHost.getCString()), _connectPortNumber,
112                                    (const char*)(url.getCString())));
113                            }
114 anusha.kandepu 1.1     }
115                        catch (const Exception& e)
116                        {
117                            PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
118                                "Failed to export indication: %s",
119                                (const char*)e.getMessage().getCString()));
120                            throw;
121                        }
122                        catch (...)
123                        {
124                            PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
125                                "Failed to export indication for class %s",
126                                (const char*)(instanceName.getClassName().getString().
127                                getCString())));
128                            throw;
129                        }
130                        PEG_METHOD_EXIT();
131                    }
132                    
133 anusha.kandepu 1.3 Boolean WSMANExportClient::_doRequest(
134 anusha.kandepu 1.2     WsmRequest * request,
135                        WsmOperationType expectedResponseMessageType)
136 anusha.kandepu 1.1     
137                    {
138                        PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "WSMANExportClient::_doRequest()");
139                    
140                        AutoPtr<WsmRequest> indicationRequest(request);
141                        
142                        if (!_connected )
143                        {
144                            PEG_METHOD_EXIT();
145                            throw NotConnectedException();
146                        }
147                    
148                        _authenticator.setRequestMessage(0);
149                    
150                        //
151                        //  Set HTTP method in request to POST
152                        //
153                        indicationRequest->httpMethod = HTTP_METHOD__POST;
154                    
155 anusha.kandepu 1.2     //Current WSMAN eventing part supports only PUSH and PUSH_WITH_ACK 
156 anusha.kandepu 1.3     // delivery mode.So we will deliver the indication if the delivery 
157 anusha.kandepu 1.2     // mode is one of them. 
158                        if (( _deliveryMode == Push ) || (_deliveryMode == PushWithAck))
159 anusha.kandepu 1.1     {
160 anusha.kandepu 1.2         _wsmanRequestEncoder->setDeliveryMode(_deliveryMode);
161 anusha.kandepu 1.1         _wsmanRequestEncoder->enqueue(indicationRequest.release());
162                        }
163                        else
164                        {
165                            PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
166                                "Failed to export indication since delivery mode %s"
167                                " is not supported", (const char*)_deliveryMode));
168                        }
169 anusha.kandepu 1.2     Uint64 startupTime = TimeValue::getCurrentTime().toMilliseconds();
170                        Uint64 currentTime = startupTime;
171                        Uint64 stopTime = currentTime + _timeoutMilliseconds;
172                        while (currentTime < stopTime)
173                        {
174                            //Wait until the timeout expires or an event occurs:
175                            _monitor->run(Uint32(stopTime- currentTime));
176                                            
177                            // Check to see if incoming queue has a message
178                            AutoPtr<WsmResponse> response(dynamic_cast<WsmResponse*>(dequeue()));
179                            if (response.get() != 0)
180                            {
181                                //Shouldn't be any more messages in our queue
182                                PEGASUS_ASSERT(getCount() == 0);
183                                if(response->getCloseConnect() == true)
184                                {
185 dl.meetei      1.4                 _disconnect(true);
186                                    _doReconnect = true;
187 anusha.kandepu 1.2                 response->setCloseConnect(false);
188                                }
189                                if (response->getType() == CLIENT_EXCEPTION_MESSAGE)
190                                {
191                                    Exception* clientException =
192                                        ((ClientExceptionMessage*)response.get())->clientException;
193                    
194                                    PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL2,
195                                        "Client Exception Message received.");
196                                    AutoPtr<Exception> d(clientException);
197                                    CIMClientMalformedHTTPException* malformedHTTPException =
198                                        dynamic_cast<CIMClientMalformedHTTPException*>(
199                                        clientException);
200                                    if (malformedHTTPException)
201                                    {
202                                        PEG_METHOD_EXIT();
203                                        throw *malformedHTTPException;
204                                    }
205                    
206                                    CIMClientHTTPErrorException* httpErrorException =
207                                        dynamic_cast<CIMClientHTTPErrorException*>(
208 anusha.kandepu 1.2                     clientException);
209                                    if (httpErrorException)
210                                    {
211                                        PEG_METHOD_EXIT();
212                                        throw *httpErrorException;
213                                    }
214                    
215                                    PEG_METHOD_EXIT();
216                                    throw *clientException; 
217                    
218                                }
219                                else if(response->getOperationType() == expectedResponseMessageType)
220                                {
221                                    PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL4,
222                                        "Received expected indication response message.");
223                                    PEG_METHOD_EXIT();
224 anusha.kandepu 1.3                 return true;
225 anusha.kandepu 1.2             }
226                                else if (response->getOperationType() == WSM_FAULT)
227                                {
228                                    PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL1,
229                                            "Received indication failure message.");
230                                    PEG_METHOD_EXIT();
231 anusha.kandepu 1.3                 return false;
232 anusha.kandepu 1.2             }
233                                else
234                                {
235                                    MessageLoaderParms mlParms(
236                                        "ExportClient.WSMANExportClient.MISMATCHED_RESPONSE",
237                                        "Mismatched response message type.");
238                                    String mlString(MessageLoader::getMessage(mlParms));
239                    
240                                    CIMClientResponseException responseException(mlString);
241                    
242                                    PEG_TRACE_CSTRING(TRC_EXPORT_CLIENT, Tracer::LEVEL1,
243                                        (const char*)mlString.getCString());
244                    
245                                    PEG_METHOD_EXIT();
246                                    throw responseException;
247                    
248                                } 
249                     
250                            }
251                            currentTime = TimeValue::getCurrentTime().toMilliseconds();
252 anusha.kandepu 1.3     }
253 anusha.kandepu 1.1     PEG_METHOD_EXIT();
254 anusha.kandepu 1.3     return false;
255 anusha.kandepu 1.1 }
256                    
257                    void WSMANExportClient ::setDeliveryMode(deliveryMode &deliveryMode)
258                    {
259                        _deliveryMode = deliveryMode;
260                    }
261                        
262 anusha.kandepu 1.2 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2