View Javadoc

1   /*
2    * Copyright 2007 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.soap.client.core;
18  
19  import java.io.IOException;
20  
21  import org.springframework.util.Assert;
22  import org.springframework.util.StringUtils;
23  import org.springframework.ws.WebServiceMessage;
24  import org.springframework.ws.client.core.WebServiceMessageCallback;
25  import org.springframework.ws.soap.SoapMessage;
26  
27  /**
28   * [email protected] WebServiceMessageCallback} implementation that sets the SOAP Action header on the message.
29   * <p/>
30   * A usage example with [email protected] org.springframework.ws.client.core.WebServiceTemplate}:
31   * <pre>
32   * WebServiceTemplate template = new WebServiceTemplate(messageFactory);
33   * Result result = new DOMResult();
34   * template.sendSourceAndReceiveToResult(
35   *     new StringSource("&lt;content xmlns=\"http://tempuri.org\"/&gt;"),
36   *     new SoapActionCallback("http://tempuri.org/SOAPAction"),
37   *     result);
38   * </pre>
39   *
40   * @author Arjen Poutsma
41   * @since 1.0.0
42   */
43  public class SoapActionCallback implements WebServiceMessageCallback {
44  
45      private final String soapAction;
46  
47      /** Create a new <code>SoapActionCallback</code> with the given string SOAPAction. */
48      public SoapActionCallback(String soapAction) {
49          if (!StringUtils.hasText(soapAction)) {
50              soapAction = "\"\"";
51          }
52          this.soapAction = soapAction;
53      }
54  
55      public void doWithMessage(WebServiceMessage message) throws IOException {
56          Assert.isInstanceOf(SoapMessage.class, message);
57          SoapMessage soapMessage = (SoapMessage) message;
58          soapMessage.setSoapAction(soapAction);
59      }
60  
61  }