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