117
117
message.setOmMessage( env.getBody( ).getFirstElement( ) );
119
119
final SOAPHeader header = env.getHeader( );
120
121
final List<SOAPHeaderBlock> headers = Lists.newArrayList( header.examineAllHeaderBlocks( ) );
121
// :: try to get the fault info from the soap header -- hello there? :://
122
String action = "ProblemAction";
123
String relatesTo = "RelatesTo";
124
for ( final SOAPHeaderBlock headerBlock : headers ) {
125
if ( action.equals( headerBlock.getLocalName( ) ) ) {
126
action = headerBlock.getText( );
127
} else if ( relatesTo.equals( headerBlock.getLocalName( ) ) ) {
128
relatesTo = headerBlock.getText( );
131
// :: process the real fault :://
132
final SOAPFault fault = env.getBody( ).getFault( );
133
String faultReason = "";
134
final Iterator children = fault.getChildElements( );
135
while ( children.hasNext( ) ) {
136
final OMElement child = ( OMElement ) children.next( );
137
faultReason += child.getText( );
139
final String faultCode = fault.getCode( ).getText( );
140
faultReason = faultReason.replaceAll( faultCode, "" );
141
throw new EucalyptusRemoteFault( action, relatesTo, faultCode, faultReason );
122
// :: try to get the fault info from the soap header -- hello there? :://
123
String action = "ProblemAction";
124
String relatesTo = "RelatesTo";
125
for ( final SOAPHeaderBlock headerBlock : headers ) {
126
if ( action.equals( headerBlock.getLocalName( ) ) ) {
127
action = headerBlock.getText( );
128
} else if ( relatesTo.equals( headerBlock.getLocalName( ) ) ) {
129
relatesTo = headerBlock.getText( );
132
// :: process the real fault :://
133
final SOAPFault fault = env.getBody( ).getFault( );
135
String faultReason = "";
136
final Iterator children = fault.getChildElements( );
137
while ( children.hasNext( ) ) {
138
final OMElement child = ( OMElement ) children.next( );
139
faultReason += child.getText( );
141
final String faultCode = fault.getCode( ).getText( );
142
faultReason = faultReason.replaceAll( faultCode, "" );
143
throw new EucalyptusRemoteFault( action, relatesTo, faultCode, faultReason );
166
170
httpMessage.getSoapEnvelope( ).getBody( ).addChild( httpMessage.getOmMessage( ) );
168
172
ByteArrayOutputStream byteOut = new ByteArrayOutputStream( );
170
174
HoldMe.canHas.lock( );
172
httpMessage.getSoapEnvelope( ).serialize( byteOut );//HACK: xml breakage?
174
HoldMe.canHas.unlock();
176
httpMessage.getSoapEnvelope( ).serialize( byteOut );//HACK: xml breakage?
178
HoldMe.canHas.unlock();
177
181
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer( byteOut.toByteArray( ) );
178
182
httpMessage.addHeader( HttpHeaders.Names.CONTENT_LENGTH, String.valueOf( buffer.readableBytes( ) ) );
184
188
private static SOAPEnvelope createFault( String faultCode, String faultReason, String faultDetails,
185
189
String resourceType, String resource ) {
186
HoldMe.canHas.lock( );
188
SOAPFactory soapFactory = HoldMe.getOMSOAP11Factory();
190
SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode();
191
soapFaultCode.setText( SOAP11Constants.FAULT_CODE_SENDER + "." + faultCode );
193
SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason();
194
soapFaultReason.setText( faultReason );
196
SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail();
198
if(resource != null) {
199
OMElement detail = soapFactory.createOMElement(new QName(resourceType));
200
detail.setText(resource);
201
soapFaultDetail.addDetailEntry(detail);
203
soapFaultDetail.setText(faultDetails);
206
SOAPEnvelope soapEnv = soapFactory.getDefaultEnvelope( );
207
SOAPFault soapFault = soapFactory.createSOAPFault( );
208
soapFault.setCode( soapFaultCode );
209
soapFault.setDetail( soapFaultDetail );
210
soapFault.setReason( soapFaultReason );
211
soapEnv.getBody( ).addFault( soapFault );
214
HoldMe.canHas.unlock();
190
HoldMe.canHas.lock( );
192
SOAPFactory soapFactory = HoldMe.getOMSOAP11Factory();
194
SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode();
195
soapFaultCode.setText( SOAP11Constants.FAULT_CODE_SENDER + "." + faultCode );
197
SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason();
198
soapFaultReason.setText( faultReason );
200
SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail();
202
if(resource != null) {
203
OMElement detail = soapFactory.createOMElement(new QName(resourceType));
204
detail.setText(resource);
205
soapFaultDetail.addDetailEntry(detail);
207
soapFaultDetail.setText(faultDetails);
210
SOAPEnvelope soapEnv = soapFactory.getDefaultEnvelope( );
211
SOAPFault soapFault = soapFactory.createSOAPFault( );
212
soapFault.setCode( soapFaultCode );
213
soapFault.setDetail( soapFaultDetail );
214
soapFault.setReason( soapFaultReason );
215
soapEnv.getBody( ).addFault( soapFault );
218
HoldMe.canHas.unlock();