1 /*
2 * Copyright 2005-2010 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
17 package org.springframework.ws.test.client;
18
19 import java.io.IOException;
20 import java.net.URI;
21
22 import org.springframework.ws.WebServiceMessage;
23 import org.springframework.ws.soap.SoapBody;
24 import org.springframework.ws.soap.SoapMessage;
25
26 import static org.springframework.ws.test.support.AssertionErrors.fail;
27
28 /**
29 * Implementation of {@link ResponseCreator} that responds with a SOAP fault.
30 *
31 * @author Arjen Poutsma
32 * @since 2.0
33 */
34 abstract class SoapFaultResponseCreator extends AbstractResponseCreator {
35
36 @Override
37 protected void doWithResponse(URI uri, WebServiceMessage request, WebServiceMessage response) throws IOException {
38 if (!(response instanceof SoapMessage)) {
39 fail("Response is not a SOAP message");
40 return;
41 }
42 SoapMessage soapResponse = (SoapMessage) response;
43 SoapBody responseBody = soapResponse.getSoapBody();
44 if (responseBody == null) {
45 fail("SOAP message [" + response + "] does not contain SOAP body");
46 }
47 addSoapFault(responseBody);
48 }
49
50 /**
51 * Abstract template method that allows subclasses to add a SOAP Fault to the given Body.
52 *
53 * @param soapBody the body to attach a fault to
54 */
55 protected abstract void addSoapFault(SoapBody soapBody);
56 }