HP-RK Changed the MessageQueue::getQueueName() method from virtual to non-virtual...
[tpot/pegasus/.git] / src / Pegasus / ExportClient / CIMExportRequestEncoder.cpp
1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
27 //
28 //              Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/Config.h>
33 #include <iostream>
34 #include <Pegasus/Common/Constants.h>
35 #include <Pegasus/Common/System.h>
36 #include <Pegasus/Common/XmlWriter.h>
37 #include <Pegasus/Common/HTTPMessage.h>
38 #include "CIMExportRequestEncoder.h"
39
40 PEGASUS_USING_STD;
41
42 PEGASUS_NAMESPACE_BEGIN
43
44 CIMExportRequestEncoder::CIMExportRequestEncoder(
45    MessageQueue* outputQueue, ClientAuthenticator* authenticator)
46    : 
47    Base(PEGASUS_QUEUENAME_EXPORTREQENCODER),
48    _outputQueue(outputQueue),
49    _authenticator(authenticator)
50 {
51    String tmpHostName = System::getHostName();
52    _hostName = tmpHostName.allocateCString();
53 }
54
55 CIMExportRequestEncoder::~CIMExportRequestEncoder()
56 {
57    delete [] _hostName;
58 }
59
60 void CIMExportRequestEncoder::handleEnqueue(Message *message)
61 {
62    if (!message)
63       return;
64
65    _authenticator->setRequestMessage(message);
66
67    switch (message->getType())
68    {
69       case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
70          _encodeExportIndicationRequest((CIMExportIndicationRequestMessage*)message);
71          break;
72    }
73
74    //ATTN: Do not delete the message here.
75    //
76    // ClientAuthenticator needs this message for resending the request on
77    // authentication challenge from the server. The message is deleted in
78    // the decoder after receiving the valid response from thr server.
79    //
80    //delete message;
81 }
82
83
84 void CIMExportRequestEncoder::handleEnqueue()
85 {
86    Message* message = dequeue();
87    if( message != 0 )
88       handleEnqueue(message);
89 }
90
91 void CIMExportRequestEncoder::_encodeExportIndicationRequest(
92    CIMExportIndicationRequestMessage* message)
93 {
94    Array<Sint8> params;
95
96    XmlWriter::appendInstanceIParameter(
97       params, "NewIndication", message->indicationInstance);
98         
99    Array<Sint8> buffer = XmlWriter::formatSimpleEMethodReqMessage(
100       message->url.allocateCString(), 
101       "ExportIndication", 
102       message->messageId, 
103       _authenticator->buildRequestAuthHeader(), 
104       params);
105
106    _outputQueue->enqueue(new HTTPMessage(buffer));
107 }
108
109 PEGASUS_NAMESPACE_END