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    
018    package org.apache.geronimo.cxf.client;
019    
020    import java.net.URI;
021    import java.util.Map;
022    
023    import javax.naming.NamingException;
024    import javax.xml.bind.JAXBException;
025    import javax.xml.namespace.QName;
026    import javax.xml.ws.handler.HandlerResolver;
027    
028    import org.apache.commons.logging.Log;
029    import org.apache.commons.logging.LogFactory;
030    import org.apache.cxf.jaxws.context.WebServiceContextImpl;
031    import org.apache.cxf.jaxws.javaee.HandlerChainsType;
032    import org.apache.geronimo.cxf.CXFHandlerResolver;
033    import org.apache.geronimo.cxf.CXFWebServiceContainer;
034    import org.apache.geronimo.gbean.AbstractName;
035    import org.apache.geronimo.jaxws.HandlerChainsUtils;
036    import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
037    import org.apache.geronimo.jaxws.JNDIResolver;
038    import org.apache.geronimo.jaxws.client.EndpointInfo;
039    import org.apache.geronimo.jaxws.client.JAXWSServiceReference;
040    
041    public class CXFServiceReference extends JAXWSServiceReference {
042    
043        private static final Log LOG = LogFactory.getLog(CXFServiceReference.class);
044    
045        public CXFServiceReference(String serviceClassName,
046                                   String referenceClassName,
047                                   URI wsdlURI,
048                                   QName serviceQName,
049                                   AbstractName name,
050                                   String handlerChainsXML,
051                                   Map<Object, EndpointInfo> seiInfoMap) {
052            super(handlerChainsXML, seiInfoMap, name, serviceQName, wsdlURI, referenceClassName, serviceClassName);        
053        }
054           
055        public Object getContent() throws NamingException {
056            CXFWebServiceContainer.getDefaultBus();
057            Object reference = super.getContent();   
058            SAAJInterceptor.registerInterceptors();        
059            return reference;
060        }
061        
062        protected HandlerChainsType getHandlerChains() {
063            try {
064                return HandlerChainsUtils.toHandlerChains(this.handlerChainsXML, HandlerChainsType.class);
065            } catch (JAXBException e) {          
066                // this should not happen
067                LOG.warn("Failed to deserialize handler chains", e);
068                return null;
069            }
070        }
071    
072        protected HandlerResolver getHandlerResolver(Class serviceClass) {
073            JAXWSAnnotationProcessor annotationProcessor =
074                    new JAXWSAnnotationProcessor(new JNDIResolver(), new WebServiceContextImpl());
075            CXFHandlerResolver handlerResolver =
076                    new CXFHandlerResolver(classLoader, serviceClass, getHandlerChains(), annotationProcessor);
077            return handlerResolver;
078        }
079    }