1 kumpf 1.2 //%2006////////////////////////////////////////////////////////////////////////
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 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 kumpf 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33 #include "SoapResponse.h"
34 #include "WsmWriter.h"
35
36 PEGASUS_USING_STD;
37
38 PEGASUS_NAMESPACE_BEGIN
39
40 SoapResponse::SoapResponse(WsmResponse* response)
41 {
42 String action;
43 kumpf 1.2 ContentLanguageList lang;
44
45 _maxEnvelopeSize = response->getMaxEnvelopeSize();
46 _queueId = response->getQueueId();
47 _httpCloseConnect = response->getHttpCloseConnect();
48
49 WsmWriter::appendSoapEnvelopeStart(_envStart);
50 WsmWriter::appendSoapEnvelopeEnd(_envEnd);
51 WsmWriter::appendSoapHeaderStart(_hdrStart);
52 WsmWriter::appendSoapHeaderEnd(_hdrEnd);
53 WsmWriter::appendSoapBodyStart(_bodyStart);
54 WsmWriter::appendSoapBodyEnd(_bodyEnd);
55
56 switch(response->getType())
57 {
58 case WS_TRANSFER_GET:
59 action = WSM_ACTION_GET_RESPONSE;
60 break;
61
62 case WS_TRANSFER_PUT:
63 action = WSM_ACTION_PUT_RESPONSE;
64 kumpf 1.2 break;
65
66 case WS_TRANSFER_CREATE:
67 action = WSM_ACTION_CREATE_RESPONSE;
68 break;
69
70 case WS_TRANSFER_DELETE:
71 action = WSM_ACTION_DELETE_RESPONSE;
72 break;
73
74 case WS_ENUMERATION_ENUMERATE:
75 action = WSM_ACTION_ENUMERATE_RESPONSE;
76 break;
77
78 case WS_ENUMERATION_PULL:
79 action = WSM_ACTION_PULL_RESPONSE;
80 break;
81
82 case WS_ENUMERATION_RELEASE:
83 action = WSM_ACTION_RELEASE_RESPONSE;
84 break;
85 kumpf 1.2
86 case WSM_FAULT:
87 action = ((WsmFaultResponse*) response)->getFault().getAction();
88 WsmWriter::appendSoapHeader(_hdrContent,
89 action, response->getMessageId(), response->getRelatesTo());
90 WsmWriter::appendWsmFaultBody(_bodyContent,
91 ((WsmFaultResponse*) response)->getFault());
92 break;
93
94 case SOAP_FAULT:
95 action = String(WsmNamespaces::supportedNamespaces[
96 WsmNamespaces::WS_ADDRESSING].extendedName) + String("/fault");
97 WsmWriter::appendSoapFaultHeaders(_hdrContent,
98 ((SoapFaultResponse*) response)->getFault(),
99 action, response->getMessageId(), response->getRelatesTo());
100 WsmWriter::appendSoapFaultBody(_bodyContent,
101 ((SoapFaultResponse*) response)->getFault());
102 break;
103
104 default:
105 PEGASUS_ASSERT(0);
106 kumpf 1.2 }
107
108 WsmWriter::appendHTTPResponseHeader(_httpHeader, action,
109 response->getHttpMethod(), response->getContentLanguages(),
110 response->getType() == WSM_FAULT || response->getType() == SOAP_FAULT,
111 0);
112
113 // Make sure that fault response fits within MaxEnvelopeSize
114 if (response->getType() == WSM_FAULT || response->getType() == SOAP_FAULT)
115 {
116 if (_maxEnvelopeSize && getEnvelopeSize() > _maxEnvelopeSize)
117 {
118 _bodyContent.clear();
119 WsmFault fault(WsmFault::wsman_EncodingLimit,
120 MessageLoaderParms(
121 "WsmServer.WsmResponseEncoder.FAULT_MAX_ENV_SIZE_EXCEEDED",
122 "Fault response could not be encoded within requested "
123 "envelope size limits."),
124 WSMAN_FAULTDETAIL_MAXENVELOPESIZE);
125 WsmWriter::appendWsmFaultBody(_bodyContent, fault);
126 }
127 kumpf 1.2 }
128 else
129 {
130 WsmWriter::appendSoapHeader(_hdrContent,
131 action, response->getMessageId(), response->getRelatesTo());
132 }
133 }
134
135 Buffer SoapResponse::getResponseContent()
136 {
137 Buffer out(WSM_MIN_MAXENVELOPESIZE_VALUE);
138 out << _httpHeader << _envStart << _hdrStart << _hdrContent
139 << _hdrEnd << _bodyStart << _bodyHeader << _bodyContent
140 << _bodyTrailer << _bodyEnd << _envEnd;
141 return out;
142 }
143
144 Boolean SoapResponse::appendHeader(Buffer& buf)
145 {
146 if (_maxEnvelopeSize &&
147 getEnvelopeSize() + buf.size() > _maxEnvelopeSize)
148 kumpf 1.2 {
149 return false;
150 }
151 _hdrContent << buf;
152 return true;
153 }
154
155 Boolean SoapResponse::appendBodyContent(Buffer& buf)
156 {
157 if (_maxEnvelopeSize &&
158 getEnvelopeSize() + buf.size() > _maxEnvelopeSize)
159 {
160 return false;
161 }
162 _bodyContent << buf;
163 return true;
164 }
165
166 Boolean SoapResponse::appendBodyHeader(Buffer& buf)
167 {
168 if (_maxEnvelopeSize &&
169 kumpf 1.2 getEnvelopeSize() + buf.size() > _maxEnvelopeSize)
170 {
171 return false;
172 }
173 _bodyHeader << buf;
174 return true;
175 }
176
177 Boolean SoapResponse::appendBodyTrailer(Buffer& buf)
178 {
179 if (_maxEnvelopeSize &&
180 getEnvelopeSize() + buf.size() > _maxEnvelopeSize)
181 {
182 return false;
183 }
184 _bodyTrailer << buf;
185 return true;
186 }
187
188 PEGASUS_NAMESPACE_END
|