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.axis2.client;
019    
020    import java.lang.reflect.Method;
021    import java.util.List;
022    import java.util.Map;
023    
024    import javax.xml.ws.handler.Handler;
025    
026    import net.sf.cglib.proxy.MethodProxy;
027    
028    import org.apache.axis2.description.AxisService;
029    import org.apache.axis2.jaxws.description.EndpointDescription;
030    import org.apache.axis2.jaxws.description.impl.DescriptionUtils;
031    import org.apache.axis2.jaxws.spi.BindingProvider;
032    import org.apache.geronimo.jaxws.client.EndpointInfo;
033    import org.apache.geronimo.jaxws.client.PortMethodInterceptor;
034    
035    public class Axis2PortMethodInterceptor extends PortMethodInterceptor {
036    
037        public Axis2PortMethodInterceptor(Map<Object, EndpointInfo> seiInfoMap) {
038            super(seiInfoMap);
039        }
040        
041        public Object intercept(Object target, Method method, Object[] arguments, MethodProxy methodProxy) throws Throwable {
042            Object proxy = super.intercept(target, method, arguments, methodProxy);
043            
044            BindingProvider axisProxy = (BindingProvider) proxy;
045            
046            List<Handler> handlers = 
047                (axisProxy.getBinding() != null) ? axisProxy.getBinding().getHandlerChain() : null;
048            AxisService axisService =
049                (axisProxy.getEndpointDescription() != null) ? axisProxy.getEndpointDescription().getAxisService() : null;
050            
051            DescriptionUtils.registerHandlerHeaders(axisService, handlers);
052            
053            return proxy;
054        }
055        
056    }