001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.soap.bindings.soap.impl;
018    
019    import java.util.List;
020    
021    import org.apache.servicemix.soap.api.Interceptor;
022    import org.apache.servicemix.soap.api.Message;
023    import org.apache.servicemix.soap.bindings.soap.SoapVersion;
024    import org.apache.servicemix.soap.bindings.soap.interceptors.MustUnderstandInterceptor;
025    import org.apache.servicemix.soap.bindings.soap.interceptors.SoapFaultInInterceptor;
026    import org.apache.servicemix.soap.bindings.soap.interceptors.SoapFaultOutInterceptor;
027    import org.apache.servicemix.soap.bindings.soap.interceptors.SoapInInterceptor;
028    import org.apache.servicemix.soap.bindings.soap.interceptors.SoapOutInterceptor;
029    import org.apache.servicemix.soap.bindings.soap.interceptors.SoapActionInOperationInterceptor;
030    import org.apache.servicemix.soap.bindings.soap.interceptors.SoapActionOutOperationInterceptor;
031    import org.apache.servicemix.soap.bindings.soap.model.wsdl1.Wsdl1SoapBinding;
032    import org.apache.servicemix.soap.bindings.soap.model.wsdl1.Wsdl1SoapOperation;
033    import org.apache.servicemix.soap.core.model.AbstractBinding;
034    import org.apache.servicemix.soap.interceptors.jbi.JbiFaultOutInterceptor;
035    import org.apache.servicemix.soap.interceptors.jbi.JbiInInterceptor;
036    import org.apache.servicemix.soap.interceptors.jbi.JbiInWsdl1Interceptor;
037    import org.apache.servicemix.soap.interceptors.jbi.JbiOutInterceptor;
038    import org.apache.servicemix.soap.interceptors.jbi.JbiOutWsdl1Interceptor;
039    import org.apache.servicemix.soap.interceptors.mime.AttachmentsInInterceptor;
040    import org.apache.servicemix.soap.interceptors.mime.AttachmentsOutInterceptor;
041    import org.apache.servicemix.soap.interceptors.wsdl.WsdlOperationInInterceptor;
042    import org.apache.servicemix.soap.interceptors.xml.BodyOutInterceptor;
043    import org.apache.servicemix.soap.interceptors.xml.StaxInInterceptor;
044    import org.apache.servicemix.soap.interceptors.xml.StaxOutInterceptor;
045    
046    
047    public class Wsdl1SoapBindingImpl extends AbstractBinding<Wsdl1SoapOperation> implements Wsdl1SoapBinding {
048    
049        private SoapVersion soapVersion;
050        private String locationURI;
051        private String transportURI;
052        private Style style;
053    
054        public Wsdl1SoapBindingImpl() {
055            this(null);
056        }
057        
058        public Wsdl1SoapBindingImpl(SoapVersion soapVersion) {
059            this.soapVersion = soapVersion;
060            
061            List<Interceptor> phase;
062            
063            // ServerIn phase
064            phase = getInterceptors(Phase.ServerIn);
065            phase.add(new AttachmentsInInterceptor());
066            phase.add(new StaxInInterceptor());
067            phase.add(new SoapInInterceptor(soapVersion));
068            phase.add(new SoapActionInOperationInterceptor());
069            phase.add(new WsdlOperationInInterceptor());
070            phase.add(new MustUnderstandInterceptor());
071            phase.add(new JbiInWsdl1Interceptor(true));
072            phase.add(new JbiInInterceptor(true));
073            
074            // ServerOut phase
075            phase = getInterceptors(Phase.ServerOut);
076            phase.add(new JbiFaultOutInterceptor());
077            phase.add(new JbiOutInterceptor(true));
078            phase.add(new JbiOutWsdl1Interceptor(true));
079            phase.add(new AttachmentsOutInterceptor());
080            phase.add(new StaxOutInterceptor());
081            phase.add(new SoapOutInterceptor(soapVersion));
082            phase.add(new BodyOutInterceptor());
083            
084            // ServerOutFault phase
085            phase = getInterceptors(Phase.ServerOutFault);
086            phase.add(new StaxOutInterceptor());
087            phase.add(new SoapOutInterceptor(soapVersion));
088            phase.add(new SoapFaultOutInterceptor());
089            
090            // ClientOut phase
091            phase = getInterceptors(Phase.ClientOut);
092            phase.add(new JbiOutInterceptor(false));
093            phase.add(new JbiOutWsdl1Interceptor(false));
094            phase.add(new SoapActionOutOperationInterceptor());
095            phase.add(new AttachmentsOutInterceptor());
096            phase.add(new StaxOutInterceptor());
097            phase.add(new SoapOutInterceptor(soapVersion));
098            phase.add(new BodyOutInterceptor());
099    
100            // ClientIn phase
101            phase = getInterceptors(Phase.ClientIn);
102            phase.add(new AttachmentsInInterceptor());
103            phase.add(new StaxInInterceptor());
104            phase.add(new SoapInInterceptor());
105            phase.add(new SoapFaultInInterceptor());
106            phase.add(new JbiInWsdl1Interceptor(false));
107            phase.add(new JbiInInterceptor(false));
108        }
109    
110        /**
111         * @return the locationURI
112         */
113        public String getLocationURI() {
114            return locationURI;
115        }
116    
117        /**
118         * @param locationURI the locationURI to set
119         */
120        public void setLocationURI(String locationURI) {
121            this.locationURI = locationURI;
122        }
123    
124        /**
125         * @return the transportURI
126         */
127        public String getTransportURI() {
128            return transportURI;
129        }
130    
131        /**
132         * @param transportURI the transportURI to set
133         */
134        public void setTransportURI(String transportURI) {
135            this.transportURI = transportURI;
136        }
137    
138        /**
139         * @return the style
140         */
141        public Style getStyle() {
142            return style;
143        }
144    
145        /**
146         * @param style the style to set
147         */
148        public void setStyle(Style style) {
149            this.style = style;
150        }
151    
152        public Message createMessage() {
153            Message msg = super.createMessage();
154            if (msg.get(SoapVersion.class) == null && soapVersion != null) {
155                msg.put(SoapVersion.class, soapVersion);
156            }
157            return msg;
158        }
159        
160        public Message createMessage(Message request) {
161            Message msg = super.createMessage(request);
162            if (msg.get(SoapVersion.class) == null && request.get(SoapVersion.class) != null) {
163                msg.put(SoapVersion.class, request.get(SoapVersion.class));
164            }
165            if (msg.get(SoapVersion.class) == null && soapVersion != null) {
166                msg.put(SoapVersion.class, soapVersion);
167            }
168            return msg;
169        }
170        
171    }