Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.transport; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.xml.internal.ws.api.EndpointAddress; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.api.message.Packet; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.pipe.*; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.api.pipe.helper.AbstractTubeImpl; |
aoqi@0 | 32 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.developer.HttpConfigFeature; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import javax.xml.ws.BindingProvider; |
aoqi@0 | 36 | import javax.xml.ws.WebServiceFeature; |
aoqi@0 | 37 | |
aoqi@0 | 38 | /** |
aoqi@0 | 39 | * Proxy transport {@link Tube} and {@link Pipe} that lazily determines the |
aoqi@0 | 40 | * actual transport pipe by looking at {@link Packet#endpointAddress}. |
aoqi@0 | 41 | * |
aoqi@0 | 42 | * <p> |
aoqi@0 | 43 | * This pseudo transport is used when there's no statically known endpoint address, |
aoqi@0 | 44 | * and thus it's expected that the application will configure {@link BindingProvider} |
aoqi@0 | 45 | * at runtime before making invocation. |
aoqi@0 | 46 | * |
aoqi@0 | 47 | * <p> |
aoqi@0 | 48 | * Since a typical application makes multiple invocations with the same endpoint |
aoqi@0 | 49 | * address, this class implements a simple cache strategy to avoid re-creating |
aoqi@0 | 50 | * transport pipes excessively. |
aoqi@0 | 51 | * |
aoqi@0 | 52 | * @author Kohsuke Kawaguchi |
aoqi@0 | 53 | */ |
aoqi@0 | 54 | public final class DeferredTransportPipe extends AbstractTubeImpl { |
aoqi@0 | 55 | |
aoqi@0 | 56 | private Tube transport; |
aoqi@0 | 57 | private EndpointAddress address; |
aoqi@0 | 58 | |
aoqi@0 | 59 | // parameter to TransportPipeFactory |
aoqi@0 | 60 | private final ClassLoader classLoader; |
aoqi@0 | 61 | private final ClientTubeAssemblerContext context; |
aoqi@0 | 62 | |
aoqi@0 | 63 | public DeferredTransportPipe(ClassLoader classLoader, ClientTubeAssemblerContext context) { |
aoqi@0 | 64 | this.classLoader = classLoader; |
aoqi@0 | 65 | this.context = context; |
aoqi@0 | 66 | if (context.getBinding().getFeature(HttpConfigFeature.class) == null) { |
aoqi@0 | 67 | context.getBinding().getFeatures().mergeFeatures( |
aoqi@0 | 68 | new WebServiceFeature[] { new HttpConfigFeature() }, false); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | //See if we can create the transport pipe from the available information. |
aoqi@0 | 71 | try { |
aoqi@0 | 72 | this.transport = TransportTubeFactory.create(classLoader, context); |
aoqi@0 | 73 | this.address = context.getAddress(); |
aoqi@0 | 74 | } catch(Exception e) { |
aoqi@0 | 75 | //No problem, transport will be initialized while processing the requests |
aoqi@0 | 76 | } |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | public DeferredTransportPipe(DeferredTransportPipe that, TubeCloner cloner) { |
aoqi@0 | 80 | super(that,cloner); |
aoqi@0 | 81 | this.classLoader = that.classLoader; |
aoqi@0 | 82 | this.context = that.context; |
aoqi@0 | 83 | if(that.transport!=null) { |
aoqi@0 | 84 | this.transport = cloner.copy(that.transport); |
aoqi@0 | 85 | this.address = that.address; |
aoqi@0 | 86 | } |
aoqi@0 | 87 | } |
aoqi@0 | 88 | public NextAction processException(@NotNull Throwable t) { |
aoqi@0 | 89 | return transport.processException(t); |
aoqi@0 | 90 | } |
aoqi@0 | 91 | |
aoqi@0 | 92 | public NextAction processRequest(@NotNull Packet request) { |
aoqi@0 | 93 | if(request.endpointAddress==address) |
aoqi@0 | 94 | // cache hit |
aoqi@0 | 95 | return transport.processRequest(request); |
aoqi@0 | 96 | |
aoqi@0 | 97 | // cache miss |
aoqi@0 | 98 | |
aoqi@0 | 99 | if(transport!=null) { |
aoqi@0 | 100 | // delete the current entry |
aoqi@0 | 101 | transport.preDestroy(); |
aoqi@0 | 102 | transport = null; |
aoqi@0 | 103 | address = null; |
aoqi@0 | 104 | } |
aoqi@0 | 105 | |
aoqi@0 | 106 | // otherwise find out what transport will process this. |
aoqi@0 | 107 | |
aoqi@0 | 108 | ClientTubeAssemblerContext newContext = new ClientTubeAssemblerContext( |
aoqi@0 | 109 | request.endpointAddress, |
aoqi@0 | 110 | context.getWsdlModel(), |
aoqi@0 | 111 | context.getBindingProvider(), |
aoqi@0 | 112 | context.getBinding(), |
aoqi@0 | 113 | context.getContainer(), |
aoqi@0 | 114 | context.getCodec().copy(), |
aoqi@0 | 115 | context.getSEIModel(), |
aoqi@0 | 116 | context.getSEI() |
aoqi@0 | 117 | ); |
aoqi@0 | 118 | |
aoqi@0 | 119 | address = request.endpointAddress; |
aoqi@0 | 120 | transport = TransportTubeFactory.create(classLoader, newContext); |
aoqi@0 | 121 | // successful return from the above method indicates a successful pipe creation |
aoqi@0 | 122 | assert transport!=null; |
aoqi@0 | 123 | |
aoqi@0 | 124 | return transport.processRequest(request); |
aoqi@0 | 125 | } |
aoqi@0 | 126 | |
aoqi@0 | 127 | public NextAction processResponse(@NotNull Packet response) { |
aoqi@0 | 128 | if (transport != null) |
aoqi@0 | 129 | return transport.processResponse(response); |
aoqi@0 | 130 | return doReturnWith(response); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | public void preDestroy() { |
aoqi@0 | 134 | if(transport!=null) { |
aoqi@0 | 135 | transport.preDestroy(); |
aoqi@0 | 136 | transport = null; |
aoqi@0 | 137 | address = null; |
aoqi@0 | 138 | } |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | public DeferredTransportPipe copy(TubeCloner cloner) { |
aoqi@0 | 142 | return new DeferredTransportPipe(this,cloner); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | } |