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.server.endpoint.adapter.method;
18  
19  import javax.xml.transform.TransformerException;
20  
21  import org.springframework.ws.MockWebServiceMessage;
22  import org.springframework.ws.MockWebServiceMessageFactory;
23  import org.springframework.ws.context.DefaultMessageContext;
24  import org.springframework.ws.context.MessageContext;
25  import org.springframework.ws.soap.axiom.AxiomSoapMessage;
26  import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
27  import org.springframework.ws.soap.saaj.SaajSoapMessage;
28  import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
29  import org.springframework.xml.transform.StringSource;
30  import org.springframework.xml.transform.TransformerObjectSupport;
31  
32  import org.apache.axiom.om.OMAbstractFactory;
33  import org.apache.axiom.soap.SOAPFactory;
34  
35  public class AbstractMethodArgumentResolverTestCase extends TransformerObjectSupport {
36  
37      protected static final String NAMESPACE_URI = "http://springframework.org/ws";
38  
39      protected static final String LOCAL_NAME = "request";
40  
41      protected static final String XML = "<" + LOCAL_NAME + " xmlns=\"" + NAMESPACE_URI + "\"/>";
42  
43      protected MessageContext createSaajMessageContext() throws javax.xml.soap.SOAPException {
44          javax.xml.soap.MessageFactory saajFactory = javax.xml.soap.MessageFactory.newInstance();
45          javax.xml.soap.SOAPMessage saajMessage = saajFactory.createMessage();
46          saajMessage.getSOAPBody().addChildElement(LOCAL_NAME, "", NAMESPACE_URI);
47          return new DefaultMessageContext(new SaajSoapMessage(saajMessage), new SaajSoapMessageFactory(saajFactory));
48      }
49  
50      protected MessageContext createMockMessageContext() throws TransformerException {
51          MockWebServiceMessage request = new MockWebServiceMessage(new StringSource(XML));
52          return new DefaultMessageContext(request, new MockWebServiceMessageFactory());
53      }
54  
55      protected MessageContext createCachingAxiomMessageContext() throws Exception {
56          SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
57          AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory, true, false);
58          transform(new StringSource(XML), request.getPayloadResult());
59          AxiomSoapMessageFactory soapMessageFactory = new AxiomSoapMessageFactory();
60          soapMessageFactory.afterPropertiesSet();
61          return new DefaultMessageContext(request, soapMessageFactory);
62      }
63  
64      protected MessageContext createNonCachingAxiomMessageContext() throws Exception {
65          SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
66          AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory, false, false);
67          transform(new StringSource(XML), request.getPayloadResult());
68          AxiomSoapMessageFactory soapMessageFactory = new AxiomSoapMessageFactory();
69          soapMessageFactory.setPayloadCaching(false);
70          soapMessageFactory.afterPropertiesSet();
71          return new DefaultMessageContext(request, soapMessageFactory);
72      }
73  }