Skip to content

Commit 85c94b0

Browse files
committed
SWS-218
1 parent 39de154 commit 85c94b0

File tree

5 files changed

+52
-334
lines changed

5 files changed

+52
-334
lines changed

core/src/main/java/org/springframework/ws/server/endpoint/AbstractMarshallingPayloadEndpoint.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.oxm.Marshaller;
2525
import org.springframework.oxm.Unmarshaller;
2626
import org.springframework.util.Assert;
27+
import org.springframework.validation.Validator;
2728
import org.springframework.ws.WebServiceMessage;
2829
import org.springframework.ws.context.MessageContext;
2930
import org.springframework.ws.support.MarshallingUtils;
@@ -50,6 +51,8 @@ public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpo
5051

5152
private Unmarshaller unmarshaller;
5253

54+
private Validator[] validators;
55+
5356
/**
5457
* Creates a new <code>AbstractMarshallingPayloadEndpoint</code>. The {@link Marshaller} and {@link Unmarshaller}
5558
* must be injected using properties.
@@ -119,6 +122,30 @@ public final void setUnmarshaller(Unmarshaller unmarshaller) {
119122
this.unmarshaller = unmarshaller;
120123
}
121124

125+
/**
126+
* Set the primary {@link Validator} for this endpoint. The {@link Validator} is must support the specified command
127+
* class. If there are one or more existing validators set already when this method is called, only the specified
128+
* validator will be kept. Use {@link #setValidators(Validator[])} to set multiple validators.
129+
*/
130+
public final void setValidator(Validator validator) {
131+
this.validators = new Validator[]{validator};
132+
}
133+
134+
/** Return the primary Validator for this controller. */
135+
public final Validator getValidator() {
136+
return (this.validators != null && this.validators.length > 0 ? this.validators[0] : null);
137+
}
138+
139+
/** Set the Validators for this controller. The Validator must support the specified command class. */
140+
public final void setValidators(Validator[] validators) {
141+
this.validators = validators;
142+
}
143+
144+
/** Return the Validators for this controller. */
145+
public final Validator[] getValidators() {
146+
return validators;
147+
}
148+
122149
public final void afterPropertiesSet() throws Exception {
123150
Assert.notNull(getMarshaller(), "marshaller is required");
124151
Assert.notNull(getUnmarshaller(), "unmarshaller is required");

core/src/main/java/org/springframework/ws/soap/server/endpoint/AbstractSoapFaultDefinitionExceptionResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ protected final boolean resolveExceptionInternal(MessageContext messageContext,
6666
return false;
6767
}
6868
if (!StringUtils.hasLength(definition.getFaultStringOrReason())) {
69-
definition.setFaultStringOrReason(ex.getMessage());
69+
String faultString = StringUtils.hasLength(ex.getMessage()) ? ex.getMessage() : ex.toString();
70+
definition.setFaultStringOrReason(faultString);
7071
}
7172
SoapBody soapBody = ((SoapMessage) messageContext.getResponse()).getSoapBody();
7273
SoapFault fault = null;

core/src/test/java/org/springframework/ws/soap/server/endpoint/SoapFaultMappingExceptionResolverTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ws.soap.server.endpoint;
1818

19+
import java.io.IOException;
1920
import java.util.Locale;
2021
import java.util.Properties;
2122
import javax.xml.soap.MessageFactory;
@@ -167,5 +168,27 @@ public void testResolveExceptionDefault() throws Exception {
167168
assertNull("Detail on fault", fault.getFaultDetail());
168169
}
169170

171+
public void testResolveNoMessageException() throws Exception {
172+
Properties mappings = new Properties();
173+
mappings.setProperty(IOException.class.getName(), "SERVER");
174+
resolver.setExceptionMappings(mappings);
175+
176+
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
177+
SOAPMessage message = messageFactory.createMessage();
178+
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
179+
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
180+
181+
boolean result = resolver.resolveException(context, null, new IOException());
182+
assertTrue("resolveException returns false", result);
183+
assertTrue("Context has no response", context.hasResponse());
184+
SoapMessage response = (SoapMessage) context.getResponse();
185+
assertTrue("Response has no fault", response.getSoapBody().hasFault());
186+
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
187+
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
188+
fault.getFaultCode());
189+
assertEquals("Invalid fault string on fault", "java.io.IOException", fault.getFaultStringOrReason());
190+
assertNull("Detail on fault", fault.getFaultDetail());
191+
}
192+
170193

171194
}

core/src/test/resources/org/springframework/ws/wsdl/wsdl11/builder/inline.wsdl

Lines changed: 0 additions & 207 deletions
This file was deleted.

0 commit comments

Comments
 (0)