src/share/jaxws_classes/com/sun/xml/internal/ws/client/HandlerConfigurator.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.client;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29 import com.sun.istack.internal.Nullable;
ohair@286 30 import com.sun.xml.internal.ws.api.client.WSPortInfo;
ohair@286 31 import com.sun.xml.internal.ws.binding.BindingImpl;
ohair@286 32 import com.sun.xml.internal.ws.handler.HandlerChainsModel;
ohair@286 33 import com.sun.xml.internal.ws.util.HandlerAnnotationInfo;
ohair@286 34 import com.sun.xml.internal.ws.util.HandlerAnnotationProcessor;
ohair@286 35
ohair@286 36 import javax.jws.HandlerChain;
ohair@286 37 import javax.xml.ws.Service;
ohair@286 38 import javax.xml.ws.handler.Handler;
ohair@286 39 import javax.xml.ws.handler.HandlerResolver;
ohair@286 40 import javax.xml.ws.handler.PortInfo;
ohair@286 41 import javax.xml.ws.soap.SOAPBinding;
ohair@286 42 import java.util.ArrayList;
ohair@286 43 import java.util.HashMap;
ohair@286 44 import java.util.List;
ohair@286 45 import java.util.Map;
ohair@286 46 import java.util.logging.Level;
ohair@286 47 import java.util.logging.Logger;
ohair@286 48
ohair@286 49 /**
ohair@286 50 * Used by {@link WSServiceDelegate} to configure {@link BindingImpl}
ohair@286 51 * with handlers. The two mechanisms encapsulated by this abstraction
ohair@286 52 * is {@link HandlerChain} annotaion and {@link HandlerResolver}
ohair@286 53 * interface.
ohair@286 54 *
ohair@286 55 * @author Kohsuke Kawaguchi
ohair@286 56 */
ohair@286 57 abstract class HandlerConfigurator {
ohair@286 58 /**
ohair@286 59 * Configures the given {@link BindingImpl} object by adding handlers to it.
ohair@286 60 */
ohair@286 61 abstract void configureHandlers(@NotNull WSPortInfo port, @NotNull BindingImpl binding);
ohair@286 62
ohair@286 63 /**
ohair@286 64 * Returns a {@link HandlerResolver}, if this object encapsulates any {@link HandlerResolver}.
ohair@286 65 * Otherwise null.
ohair@286 66 */
ohair@286 67 abstract HandlerResolver getResolver();
ohair@286 68
ohair@286 69
ohair@286 70 /**
ohair@286 71 * Configures handlers by calling {@link HandlerResolver}.
ohair@286 72 * <p>
ohair@286 73 * When a null {@link HandlerResolver} is set by the user to
ohair@286 74 * {@link Service#setHandlerResolver(HandlerResolver)}, we'll use this object
ohair@286 75 * with null {@link #resolver}.
ohair@286 76 */
ohair@286 77 static final class HandlerResolverImpl extends HandlerConfigurator {
ohair@286 78 private final @Nullable HandlerResolver resolver;
ohair@286 79
ohair@286 80 public HandlerResolverImpl(HandlerResolver resolver) {
ohair@286 81 this.resolver = resolver;
ohair@286 82 }
ohair@286 83
alanb@368 84 @Override
ohair@286 85 void configureHandlers(@NotNull WSPortInfo port, @NotNull BindingImpl binding) {
alanb@368 86 if (resolver!=null) {
ohair@286 87 binding.setHandlerChain(resolver.getHandlerChain(port));
alanb@368 88 }
ohair@286 89 }
ohair@286 90
ohair@286 91
alanb@368 92 @Override
ohair@286 93 HandlerResolver getResolver() {
ohair@286 94 return resolver;
ohair@286 95 }
ohair@286 96 }
ohair@286 97
ohair@286 98 /**
ohair@286 99 * Configures handlers from {@link HandlerChain} annotation.
ohair@286 100 *
ohair@286 101 * <p>
ohair@286 102 * This class is a simple
ohair@286 103 * map of PortInfo objects to handler chains. It is used by a
ohair@286 104 * {@link WSServiceDelegate} object, and can
ohair@286 105 * be replaced by user code with a different class implementing
ohair@286 106 * HandlerResolver. This class is only used on the client side, and
ohair@286 107 * it includes a lot of logging to help when there are issues since
ohair@286 108 * it deals with port names, service names, and bindings. All three
ohair@286 109 * must match when getting a handler chain from the map.
ohair@286 110 *
ohair@286 111 * <p>It is created by the {@link WSServiceDelegate}
ohair@286 112 * class , which uses {@link HandlerAnnotationProcessor} to create
ohair@286 113 * a handler chain and then it sets the chains on this class and they
ohair@286 114 * are put into the map. The ServiceContext uses the map to set handler
ohair@286 115 * chains on bindings when they are created.
ohair@286 116 */
ohair@286 117 static final class AnnotationConfigurator extends HandlerConfigurator {
ohair@286 118 private final HandlerChainsModel handlerModel;
ohair@286 119 private final Map<WSPortInfo,HandlerAnnotationInfo> chainMap = new HashMap<WSPortInfo,HandlerAnnotationInfo>();
ohair@286 120 private static final Logger logger = Logger.getLogger(
ohair@286 121 com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".handler");
ohair@286 122
ohair@286 123 AnnotationConfigurator(WSServiceDelegate delegate) {
ohair@286 124 handlerModel = HandlerAnnotationProcessor.buildHandlerChainsModel(delegate.getServiceClass());
ohair@286 125 assert handlerModel!=null; // this class is suppeod to be called only when there's @HandlerCHain
ohair@286 126 }
ohair@286 127
ohair@286 128
ohair@286 129 void configureHandlers(WSPortInfo port, BindingImpl binding) {
ohair@286 130 //Check in cache first
ohair@286 131 HandlerAnnotationInfo chain = chainMap.get(port);
ohair@286 132
ohair@286 133 if(chain==null) {
ohair@286 134 logGetChain(port);
ohair@286 135 // Put it in cache
ohair@286 136 chain = handlerModel.getHandlersForPortInfo(port);
ohair@286 137 chainMap.put(port,chain);
ohair@286 138 }
ohair@286 139
ohair@286 140 if (binding instanceof SOAPBinding) {
ohair@286 141 ((SOAPBinding) binding).setRoles(chain.getRoles());
ohair@286 142 }
ohair@286 143
ohair@286 144 logSetChain(port,chain);
ohair@286 145 binding.setHandlerChain(chain.getHandlers());
ohair@286 146 }
ohair@286 147
ohair@286 148 HandlerResolver getResolver() {
ohair@286 149 return new HandlerResolver() {
ohair@286 150 public List<Handler> getHandlerChain(PortInfo portInfo) {
ohair@286 151 return new ArrayList<Handler>(
ohair@286 152 handlerModel.getHandlersForPortInfo(portInfo).getHandlers());
ohair@286 153 }
ohair@286 154 };
ohair@286 155 }
ohair@286 156 // logged at finer level
ohair@286 157 private void logSetChain(WSPortInfo info, HandlerAnnotationInfo chain) {
ohair@286 158 logger.finer("Setting chain of length " + chain.getHandlers().size() +
ohair@286 159 " for port info");
ohair@286 160 logPortInfo(info, Level.FINER);
ohair@286 161 }
ohair@286 162
ohair@286 163 // logged at fine level
ohair@286 164 private void logGetChain(WSPortInfo info) {
ohair@286 165 logger.fine("No handler chain found for port info:");
ohair@286 166 logPortInfo(info, Level.FINE);
ohair@286 167 logger.fine("Existing handler chains:");
ohair@286 168 if (chainMap.isEmpty()) {
ohair@286 169 logger.fine("none");
ohair@286 170 } else {
ohair@286 171 for (WSPortInfo key : chainMap.keySet()) {
ohair@286 172 logger.fine(chainMap.get(key).getHandlers().size() +
ohair@286 173 " handlers for port info ");
ohair@286 174 logPortInfo(key, Level.FINE);
ohair@286 175 }
ohair@286 176 }
ohair@286 177 }
ohair@286 178
ohair@286 179 private void logPortInfo(WSPortInfo info, Level level) {
ohair@286 180 logger.log(level, "binding: " + info.getBindingID() +
ohair@286 181 "\nservice: " + info.getServiceName() +
ohair@286 182 "\nport: " + info.getPortName());
ohair@286 183 }
ohair@286 184 }
ohair@286 185 }

mercurial