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.camel.component.cxf.util;
018    
019    import javax.xml.namespace.QName;
020    
021    import org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor;
022    import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
023    import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
024    import org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor;
025    import org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor;
026    import org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor;
027    import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
028    import org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor;
029    import org.apache.cxf.interceptor.AttachmentInInterceptor;
030    import org.apache.cxf.interceptor.AttachmentOutInterceptor;
031    import org.apache.cxf.interceptor.StaxInInterceptor;
032    import org.apache.cxf.interceptor.StaxOutInterceptor;
033    import org.apache.cxf.interceptor.URIMappingInterceptor;
034    import org.apache.cxf.service.Service;
035    import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
036    import org.apache.cxf.service.model.EndpointInfo;
037    import org.apache.cxf.service.model.ServiceInfo;
038    import org.apache.cxf.wsdl11.WSDLServiceFactory;
039    
040    //The service factory bean which is used for the service without SEI
041    public class WSDLSoapServiceFactoryBean extends ReflectionServiceFactoryBean {
042        private QName serviceName;
043        private QName endpointName;
044    
045        @Override
046        public Service create() {
047    
048            WSDLServiceFactory factory = new WSDLServiceFactory(getBus(), getWsdlURL(), getServiceQName());
049    
050            setService(factory.create());
051            initializeSoapInterceptors();
052            //disable the date interceptors
053            updateEndpointInfors();
054            createEndpoints();
055    
056            return getService();
057        }
058    
059    
060        private void updateEndpointInfors() {
061            Service service = getService();
062    
063            for (ServiceInfo inf : service.getServiceInfos()) {
064                for (EndpointInfo ei : inf.getEndpoints()) {
065                    //setup the endpoint address
066                    ei.setAddress("local://" + ei.getService().getName().toString() + "/" + ei.getName().getLocalPart());
067                    // working as the dispatch mode, the binding factory will not add interceptor
068                    //ei.getBinding().setProperty(AbstractBindingFactory.DATABINDING_DISABLED, Boolean.TRUE);
069                }
070            }
071    
072        }
073        
074        protected void checkServiceClassAnnotations(Class<?> sc) {
075            // do nothing here
076        }
077    
078    
079        // do not handle any payload information here
080        private void initializeSoapInterceptors() {
081            getService().getInInterceptors().add(new DataInInterceptor());
082            getService().getInInterceptors().add(new ReadHeadersInterceptor(getBus()));
083            getService().getInInterceptors().add(new CheckFaultInterceptor());
084            getService().getInInterceptors().add(new MustUnderstandInterceptor());
085            getService().getInInterceptors().add(new AttachmentInInterceptor());
086            getService().getInInterceptors().add(new SoapHeaderInterceptor());
087            getService().getInInterceptors().add(new CheckFaultInterceptor());
088            getService().getInInterceptors().add(new URIMappingInterceptor());
089    
090            getService().getInInterceptors().add(new StaxInInterceptor());
091            getService().getInInterceptors().add(new SoapActionInInterceptor());
092    
093            getService().getOutInterceptors().add(new DataOutInterceptor());       
094            getService().getOutInterceptors().add(new AttachmentOutInterceptor());
095            getService().getOutInterceptors().add(new StaxOutInterceptor());
096            getService().getOutInterceptors().add(new SoapHeaderOutFilterInterceptor());
097    
098            getService().getOutInterceptors().add(new SoapPreProtocolOutInterceptor());
099            getService().getOutInterceptors().add(new SoapOutInterceptor(getBus()));
100            getService().getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));
101        }
102    
103        public void setServiceName(QName name) {
104            serviceName = name;
105        }
106    
107        public String getServiceName() {
108            return serviceName.toString();
109        }
110    
111        public QName getServiceQName() {
112            return serviceName;
113        }
114    
115        public QName getEndpointName() {
116            // get the endpoint name if it is not set
117            if (endpointName == null) {
118                endpointName = getService().getEndpoints().keySet().iterator().next();
119            }
120            return endpointName;
121        }
122    
123        public void setEndpointName(QName name) {
124            endpointName = name;
125        }
126    }