src/share/jaxws_classes/com/sun/xml/internal/ws/transport/http/HttpAdapterList.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

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.transport.http;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.ws.transport.http.DeploymentDescriptorParser.AdapterFactory;
ohair@286 29 import com.sun.xml.internal.ws.api.server.WSEndpoint;
ohair@286 30 import com.sun.xml.internal.ws.api.server.PortAddressResolver;
ohair@286 31 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 32 import com.sun.istack.internal.NotNull;
ohair@286 33
ohair@286 34 import javax.xml.namespace.QName;
ohair@286 35 import java.util.List;
ohair@286 36 import java.util.ArrayList;
ohair@286 37 import java.util.Map;
ohair@286 38 import java.util.HashMap;
ohair@286 39 import java.util.AbstractList;
alanb@368 40 import java.util.Map.Entry;
ohair@286 41
ohair@286 42 /**
ohair@286 43 * List of {@link HttpAdapter}s created together.
ohair@286 44 *
ohair@286 45 * <p>
ohair@286 46 * Some cases WAR file may contain multiple endpoints for ports in a WSDL.
ohair@286 47 * If the runtime knows these ports, their port addresses can be patched.
ohair@286 48 * This class keeps a list of {@link HttpAdapter}s and use that information to patch
ohair@286 49 * multiple port addresses.
ohair@286 50 *
ohair@286 51 * <p>
ohair@286 52 * Concrete implementations of this class need to override {@link #createHttpAdapter}
ohair@286 53 * method to create implementations of {@link HttpAdapter}.
ohair@286 54 *
ohair@286 55 * @author Jitendra Kotamraju
ohair@286 56 */
ohair@286 57 public abstract class HttpAdapterList<T extends HttpAdapter> extends AbstractList<T> implements AdapterFactory<T> {
ohair@286 58 private final List<T> adapters = new ArrayList<T>();
ohair@286 59 private final Map<PortInfo, String> addressMap = new HashMap<PortInfo, String>();
ohair@286 60
ohair@286 61 // TODO: documented because it's used by AS
alanb@368 62 @Override
ohair@286 63 public T createAdapter(String name, String urlPattern, WSEndpoint<?> endpoint) {
ohair@286 64 T t = createHttpAdapter(name, urlPattern, endpoint);
ohair@286 65 adapters.add(t);
ohair@286 66 WSDLPort port = endpoint.getPort();
ohair@286 67 if (port != null) {
alanb@368 68 PortInfo portInfo = new PortInfo(port.getOwner().getName(),port.getName().getLocalPart(), endpoint.getImplementationClass());
ohair@286 69 addressMap.put(portInfo, getValidPath(urlPattern));
ohair@286 70 }
ohair@286 71 return t;
ohair@286 72 }
ohair@286 73
ohair@286 74 /**
ohair@286 75 * Implementations need to override this one to create a concrete class
ohair@286 76 * of HttpAdapter
ohair@286 77 */
ohair@286 78 protected abstract T createHttpAdapter(String name, String urlPattern, WSEndpoint<?> endpoint);
ohair@286 79
ohair@286 80 /**
ohair@286 81 * @return urlPattern without "/*"
ohair@286 82 */
ohair@286 83 private String getValidPath(@NotNull String urlPattern) {
ohair@286 84 if (urlPattern.endsWith("/*")) {
ohair@286 85 return urlPattern.substring(0, urlPattern.length() - 2);
ohair@286 86 } else {
ohair@286 87 return urlPattern;
ohair@286 88 }
ohair@286 89 }
ohair@286 90
ohair@286 91 /**
ohair@286 92 * Creates a PortAddressResolver that maps portname to its address
alanb@368 93 *
alanb@368 94 * @param endpointImpl application endpoint Class that eventually serves the request.
ohair@286 95 */
alanb@368 96 public PortAddressResolver createPortAddressResolver(final String baseAddress, final Class<?> endpointImpl) {
ohair@286 97 return new PortAddressResolver() {
alanb@368 98 @Override
ohair@286 99 public String getAddressFor(@NotNull QName serviceName, @NotNull String portName) {
alanb@368 100 String urlPattern = addressMap.get(new PortInfo(serviceName,portName, endpointImpl));
alanb@368 101 if (urlPattern == null) {
alanb@368 102 //if a WSDL defines more ports, urlpattern is null (portName does not match endpointImpl)
alanb@368 103 //so fallback to the default behaviour where only serviceName/portName is checked
alanb@368 104 for (Entry<PortInfo, String> e : addressMap.entrySet()) {
alanb@368 105 if (serviceName.equals(e.getKey().serviceName) && portName.equals(e.getKey().portName)) {
alanb@368 106 urlPattern = e.getValue();
alanb@368 107 break;
alanb@368 108 }
alanb@368 109 }
alanb@368 110 }
ohair@286 111 return (urlPattern == null) ? null : baseAddress+urlPattern;
ohair@286 112 }
ohair@286 113 };
ohair@286 114 }
ohair@286 115
ohair@286 116
alanb@368 117 @Override
ohair@286 118 public T get(int index) {
ohair@286 119 return adapters.get(index);
ohair@286 120 }
ohair@286 121
alanb@368 122 @Override
ohair@286 123 public int size() {
ohair@286 124 return adapters.size();
ohair@286 125 }
ohair@286 126
ohair@286 127 private static class PortInfo {
ohair@286 128 private final QName serviceName;
ohair@286 129 private final String portName;
alanb@368 130 private final Class<?> implClass;
ohair@286 131
alanb@368 132 PortInfo(@NotNull QName serviceName, @NotNull String portName, Class<?> implClass) {
ohair@286 133 this.serviceName = serviceName;
ohair@286 134 this.portName = portName;
alanb@368 135 this.implClass = implClass;
ohair@286 136 }
ohair@286 137
ohair@286 138 @Override
ohair@286 139 public boolean equals(Object portInfo) {
ohair@286 140 if (portInfo instanceof PortInfo) {
ohair@286 141 PortInfo that = (PortInfo)portInfo;
alanb@368 142 if (this.implClass == null) {
alanb@368 143 return this.serviceName.equals(that.serviceName) && this.portName.equals(that.portName) && that.implClass == null;
alanb@368 144 }
alanb@368 145 return this.serviceName.equals(that.serviceName) && this.portName.equals(that.portName) && this.implClass.equals(that.implClass);
ohair@286 146 }
ohair@286 147 return false;
ohair@286 148 }
ohair@286 149
ohair@286 150 @Override
ohair@286 151 public int hashCode() {
alanb@368 152 int retVal = serviceName.hashCode()+portName.hashCode();
alanb@368 153 return implClass != null ? retVal + implClass.hashCode() : retVal;
ohair@286 154 }
ohair@286 155 }
ohair@286 156 }

mercurial