01: /*
02: * Copyright 2005-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.ws.soap.server.endpoint;
17:
18: import java.util.Locale;
19:
20: import org.springframework.util.Assert;
21: import org.springframework.util.StringUtils;
22: import org.springframework.ws.context.MessageContext;
23: import org.springframework.ws.server.endpoint.AbstractEndpointExceptionResolver;
24: import org.springframework.ws.soap.SoapBody;
25: import org.springframework.ws.soap.SoapMessage;
26:
27: /**
28: * Simple, SOAP-specific {@link org.springframework.ws.server.EndpointExceptionResolver EndpointExceptionResolver}
29: * implementation that stores the exception's message as the fault string.
30: * <p/>
31: * <p>The fault code is always set to a Sender (in SOAP 1.1) or Receiver (SOAP 1.2).
32: *
33: * @author Arjen Poutsma
34: * @since 1.0.0
35: */
36: public class SimpleSoapExceptionResolver extends
37: AbstractEndpointExceptionResolver {
38:
39: private Locale locale = Locale.ENGLISH;
40:
41: /** Sets the locale for the faultstring or reason of the SOAP Fault. <p>Defaults to {@link Locale#ENGLISH}. */
42: public void setLocale(Locale locale) {
43: this .locale = locale;
44: }
45:
46: protected boolean resolveExceptionInternal(
47: MessageContext messageContext, Object endpoint, Exception ex) {
48: Assert.isTrue(
49: messageContext.getResponse() instanceof SoapMessage,
50: "SimpleSoapExceptionResolver requires a SoapMessage");
51: SoapMessage response = (SoapMessage) messageContext
52: .getResponse();
53: String faultString = StringUtils.hasLength(ex.getMessage()) ? ex
54: .getMessage()
55: : ex.toString();
56: SoapBody body = response.getSoapBody();
57: body.addServerOrReceiverFault(faultString, locale);
58: return true;
59: }
60:
61: }
|