diff -r 88b85470e72c -r f50545b5e2f1 src/share/jaxws_classes/com/sun/xml/internal/ws/client/HandlerConfigurator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/client/HandlerConfigurator.java Tue Mar 06 16:09:35 2012 -0800 @@ -0,0 +1,182 @@ +/* + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.xml.internal.ws.client; + +import com.sun.istack.internal.NotNull; +import com.sun.istack.internal.Nullable; +import com.sun.xml.internal.ws.api.client.WSPortInfo; +import com.sun.xml.internal.ws.binding.BindingImpl; +import com.sun.xml.internal.ws.handler.HandlerChainsModel; +import com.sun.xml.internal.ws.util.HandlerAnnotationInfo; +import com.sun.xml.internal.ws.util.HandlerAnnotationProcessor; + +import javax.jws.HandlerChain; +import javax.xml.ws.Service; +import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.HandlerResolver; +import javax.xml.ws.handler.PortInfo; +import javax.xml.ws.soap.SOAPBinding; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Used by {@link WSServiceDelegate} to configure {@link BindingImpl} + * with handlers. The two mechanisms encapsulated by this abstraction + * is {@link HandlerChain} annotaion and {@link HandlerResolver} + * interface. + * + * @author Kohsuke Kawaguchi + */ +abstract class HandlerConfigurator { + /** + * Configures the given {@link BindingImpl} object by adding handlers to it. + */ + abstract void configureHandlers(@NotNull WSPortInfo port, @NotNull BindingImpl binding); + + /** + * Returns a {@link HandlerResolver}, if this object encapsulates any {@link HandlerResolver}. + * Otherwise null. + */ + abstract HandlerResolver getResolver(); + + + /** + * Configures handlers by calling {@link HandlerResolver}. + *
+ * When a null {@link HandlerResolver} is set by the user to + * {@link Service#setHandlerResolver(HandlerResolver)}, we'll use this object + * with null {@link #resolver}. + */ + static final class HandlerResolverImpl extends HandlerConfigurator { + private final @Nullable HandlerResolver resolver; + + public HandlerResolverImpl(HandlerResolver resolver) { + this.resolver = resolver; + } + + void configureHandlers(@NotNull WSPortInfo port, @NotNull BindingImpl binding) { + if(resolver!=null) + binding.setHandlerChain(resolver.getHandlerChain(port)); + } + + + HandlerResolver getResolver() { + return resolver; + } + } + + /** + * Configures handlers from {@link HandlerChain} annotation. + * + *
+ * This class is a simple + * map of PortInfo objects to handler chains. It is used by a + * {@link WSServiceDelegate} object, and can + * be replaced by user code with a different class implementing + * HandlerResolver. This class is only used on the client side, and + * it includes a lot of logging to help when there are issues since + * it deals with port names, service names, and bindings. All three + * must match when getting a handler chain from the map. + * + *
It is created by the {@link WSServiceDelegate}
+ * class , which uses {@link HandlerAnnotationProcessor} to create
+ * a handler chain and then it sets the chains on this class and they
+ * are put into the map. The ServiceContext uses the map to set handler
+ * chains on bindings when they are created.
+ */
+ static final class AnnotationConfigurator extends HandlerConfigurator {
+ private final HandlerChainsModel handlerModel;
+ private final Map