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