aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.ws.transport.http; aoqi@0: aoqi@0: import com.sun.xml.internal.ws.transport.http.DeploymentDescriptorParser.AdapterFactory; aoqi@0: import com.sun.xml.internal.ws.api.server.WSEndpoint; aoqi@0: import com.sun.xml.internal.ws.api.server.PortAddressResolver; aoqi@0: import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; aoqi@0: import com.sun.istack.internal.NotNull; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import java.util.List; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Map; aoqi@0: import java.util.HashMap; aoqi@0: import java.util.AbstractList; aoqi@0: import java.util.Map.Entry; aoqi@0: aoqi@0: /** aoqi@0: * List of {@link HttpAdapter}s created together. aoqi@0: * aoqi@0: *

aoqi@0: * Some cases WAR file may contain multiple endpoints for ports in a WSDL. aoqi@0: * If the runtime knows these ports, their port addresses can be patched. aoqi@0: * This class keeps a list of {@link HttpAdapter}s and use that information to patch aoqi@0: * multiple port addresses. aoqi@0: * aoqi@0: *

aoqi@0: * Concrete implementations of this class need to override {@link #createHttpAdapter} aoqi@0: * method to create implementations of {@link HttpAdapter}. aoqi@0: * aoqi@0: * @author Jitendra Kotamraju aoqi@0: */ aoqi@0: public abstract class HttpAdapterList extends AbstractList implements AdapterFactory { aoqi@0: private final List adapters = new ArrayList(); aoqi@0: private final Map addressMap = new HashMap(); aoqi@0: aoqi@0: // TODO: documented because it's used by AS aoqi@0: @Override aoqi@0: public T createAdapter(String name, String urlPattern, WSEndpoint endpoint) { aoqi@0: T t = createHttpAdapter(name, urlPattern, endpoint); aoqi@0: adapters.add(t); aoqi@0: WSDLPort port = endpoint.getPort(); aoqi@0: if (port != null) { aoqi@0: PortInfo portInfo = new PortInfo(port.getOwner().getName(),port.getName().getLocalPart(), endpoint.getImplementationClass()); aoqi@0: addressMap.put(portInfo, getValidPath(urlPattern)); aoqi@0: } aoqi@0: return t; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Implementations need to override this one to create a concrete class aoqi@0: * of HttpAdapter aoqi@0: */ aoqi@0: protected abstract T createHttpAdapter(String name, String urlPattern, WSEndpoint endpoint); aoqi@0: aoqi@0: /** aoqi@0: * @return urlPattern without "/*" aoqi@0: */ aoqi@0: private String getValidPath(@NotNull String urlPattern) { aoqi@0: if (urlPattern.endsWith("/*")) { aoqi@0: return urlPattern.substring(0, urlPattern.length() - 2); aoqi@0: } else { aoqi@0: return urlPattern; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Creates a PortAddressResolver that maps portname to its address aoqi@0: * aoqi@0: * @param endpointImpl application endpoint Class that eventually serves the request. aoqi@0: */ aoqi@0: public PortAddressResolver createPortAddressResolver(final String baseAddress, final Class endpointImpl) { aoqi@0: return new PortAddressResolver() { aoqi@0: @Override aoqi@0: public String getAddressFor(@NotNull QName serviceName, @NotNull String portName) { aoqi@0: String urlPattern = addressMap.get(new PortInfo(serviceName,portName, endpointImpl)); aoqi@0: if (urlPattern == null) { aoqi@0: //if a WSDL defines more ports, urlpattern is null (portName does not match endpointImpl) aoqi@0: //so fallback to the default behaviour where only serviceName/portName is checked aoqi@0: for (Entry e : addressMap.entrySet()) { aoqi@0: if (serviceName.equals(e.getKey().serviceName) && portName.equals(e.getKey().portName)) { aoqi@0: urlPattern = e.getValue(); aoqi@0: break; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return (urlPattern == null) ? null : baseAddress+urlPattern; aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: @Override aoqi@0: public T get(int index) { aoqi@0: return adapters.get(index); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public int size() { aoqi@0: return adapters.size(); aoqi@0: } aoqi@0: aoqi@0: private static class PortInfo { aoqi@0: private final QName serviceName; aoqi@0: private final String portName; aoqi@0: private final Class implClass; aoqi@0: aoqi@0: PortInfo(@NotNull QName serviceName, @NotNull String portName, Class implClass) { aoqi@0: this.serviceName = serviceName; aoqi@0: this.portName = portName; aoqi@0: this.implClass = implClass; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public boolean equals(Object portInfo) { aoqi@0: if (portInfo instanceof PortInfo) { aoqi@0: PortInfo that = (PortInfo)portInfo; aoqi@0: if (this.implClass == null) { aoqi@0: return this.serviceName.equals(that.serviceName) && this.portName.equals(that.portName) && that.implClass == null; aoqi@0: } aoqi@0: return this.serviceName.equals(that.serviceName) && this.portName.equals(that.portName) && this.implClass.equals(that.implClass); aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public int hashCode() { aoqi@0: int retVal = serviceName.hashCode()+portName.hashCode(); aoqi@0: return implClass != null ? retVal + implClass.hashCode() : retVal; aoqi@0: } aoqi@0: } aoqi@0: }