~tritone-team/tritone/eucalyptus

« back to all changes in this revision

Viewing changes to clc/modules/wsstack/src/main/java/com/eucalyptus/ws/handlers/WalrusSoapHandler.java

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-12-01 21:09:28 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: james.westby@ubuntu.com-20091201210928-o2dvg0ubljhb0ft6
Tags: upstream-1.6.1~bzr1083
ImportĀ upstreamĀ versionĀ 1.6.1~bzr1083

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
                                message.setOmMessage( env.getBody( ).getFirstElement( ) );
118
118
                        } else {
119
119
                                final SOAPHeader header = env.getHeader( );
 
120
                                if(header != null) {
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( );
129
 
                                        }
130
 
                                }
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( );
138
 
                                }
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( );
 
130
                                                }
 
131
                                        }
 
132
                                        // :: process the real fault :://
 
133
                                        final SOAPFault fault = env.getBody( ).getFault( );
 
134
                                        if(fault != null) {
 
135
                                                String faultReason = "";
 
136
                                                final Iterator children = fault.getChildElements( );
 
137
                                                while ( children.hasNext( ) ) {
 
138
                                                        final OMElement child = ( OMElement ) children.next( );
 
139
                                                        faultReason += child.getText( );
 
140
                                                }
 
141
                                                final String faultCode = fault.getCode( ).getText( );
 
142
                                                faultReason = faultReason.replaceAll( faultCode, "" );
 
143
                                                throw new EucalyptusRemoteFault( action, relatesTo, faultCode, faultReason );
 
144
                                        }
 
145
                                }
142
146
                        }
143
147
                }
144
148
        }
166
170
                                httpMessage.getSoapEnvelope( ).getBody( ).addChild( httpMessage.getOmMessage( ) );
167
171
                        }
168
172
                        ByteArrayOutputStream byteOut = new ByteArrayOutputStream( );
169
 
                        
 
173
 
170
174
                        HoldMe.canHas.lock( );
171
175
                        try {
172
 
                     httpMessage.getSoapEnvelope( ).serialize( byteOut );//HACK: xml breakage?
173
 
            } finally {
174
 
              HoldMe.canHas.unlock();
175
 
            }
 
176
                                httpMessage.getSoapEnvelope( ).serialize( byteOut );//HACK: xml breakage?
 
177
                        } finally {
 
178
                                HoldMe.canHas.unlock();
 
179
                        }
176
180
 
177
181
                        ChannelBuffer buffer = ChannelBuffers.wrappedBuffer( byteOut.toByteArray( ) );
178
182
                        httpMessage.addHeader( HttpHeaders.Names.CONTENT_LENGTH, String.valueOf( buffer.readableBytes( ) ) );
183
187
 
184
188
        private static SOAPEnvelope createFault(  String faultCode, String faultReason, String faultDetails, 
185
189
                        String resourceType, String resource )  {
186
 
    HoldMe.canHas.lock( );
187
 
    try {
188
 
      SOAPFactory soapFactory = HoldMe.getOMSOAP11Factory();
189
 
 
190
 
      SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode();
191
 
      soapFaultCode.setText( SOAP11Constants.FAULT_CODE_SENDER + "." + faultCode );
192
 
 
193
 
      SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason();
194
 
      soapFaultReason.setText( faultReason );
195
 
 
196
 
      SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail();
197
 
 
198
 
      if(resource != null) {
199
 
        OMElement detail = soapFactory.createOMElement(new QName(resourceType));
200
 
        detail.setText(resource);
201
 
        soapFaultDetail.addDetailEntry(detail);
202
 
      } else {
203
 
        soapFaultDetail.setText(faultDetails);
204
 
      }
205
 
 
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 );
212
 
      return soapEnv;
213
 
    } finally {
214
 
      HoldMe.canHas.unlock();
215
 
    }
 
190
                HoldMe.canHas.lock( );
 
191
                try {
 
192
                        SOAPFactory soapFactory = HoldMe.getOMSOAP11Factory();
 
193
 
 
194
                        SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode();
 
195
                        soapFaultCode.setText( SOAP11Constants.FAULT_CODE_SENDER + "." + faultCode );
 
196
 
 
197
                        SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason();
 
198
                        soapFaultReason.setText( faultReason );
 
199
 
 
200
                        SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail();
 
201
 
 
202
                        if(resource != null) {
 
203
                                OMElement detail = soapFactory.createOMElement(new QName(resourceType));
 
204
                                detail.setText(resource);
 
205
                                soapFaultDetail.addDetailEntry(detail);
 
206
                        } else {
 
207
                                soapFaultDetail.setText(faultDetails);
 
208
                        }
 
209
 
 
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 );
 
216
                        return soapEnv;
 
217
                } finally {
 
218
                        HoldMe.canHas.unlock();
 
219
                }
216
220
        }
217
221
 
218
222
}