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.gbean.AbstractName;
034    import org.apache.geronimo.jaxws.HandlerChainsUtils;
035    import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
036    import org.apache.geronimo.jaxws.JNDIResolver;
037    import org.apache.geronimo.jaxws.client.EndpointInfo;
038    import org.apache.geronimo.jaxws.client.JAXWSServiceReference;
039    
040    public class CXFServiceReference extends JAXWSServiceReference {
041    
042        private static final Log LOG = LogFactory.getLog(CXFServiceReference.class);
043    
044        public CXFServiceReference(String serviceClassName,
045                                   String referenceClassName,
046                                   URI wsdlURI,
047                                   QName serviceQName,
048                                   AbstractName name,
049                                   String handlerChainsXML,
050                                   Map<Object, EndpointInfo> seiInfoMap) {
051            super(handlerChainsXML, seiInfoMap, name, serviceQName, wsdlURI, referenceClassName, serviceClassName);        
052        }
053           
054        public Object getContent() throws NamingException {
055            Object reference = super.getContent();   
056            SAAJInterceptor.registerInterceptors();        
057            return reference;
058        }
059        
060        protected HandlerChainsType getHandlerChains() {
061            try {
062                return HandlerChainsUtils.toHandlerChains(this.handlerChainsXML, HandlerChainsType.class);
063            } catch (JAXBException e) {          
064                // this should not happen
065                LOG.warn("Failed to deserialize handler chains", e);
066                return null;
067            }
068        }
069    
070        protected HandlerResolver getHandlerResolver(Class serviceClass) {
071            JAXWSAnnotationProcessor annotationProcessor =
072                    new JAXWSAnnotationProcessor(new JNDIResolver(), new WebServiceContextImpl());
073            CXFHandlerResolver handlerResolver =
074                    new CXFHandlerResolver(classLoader, serviceClass, getHandlerChains(), annotationProcessor);
075            return handlerResolver;
076        }
077    }