1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/client/Stub.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,753 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.client; 1.30 + 1.31 +import com.sun.istack.internal.NotNull; 1.32 +import com.sun.istack.internal.Nullable; 1.33 +import com.sun.xml.internal.stream.buffer.XMLStreamBuffer; 1.34 +import com.sun.xml.internal.ws.addressing.WSEPRExtension; 1.35 +import com.sun.xml.internal.ws.api.BindingID; 1.36 +import com.sun.xml.internal.ws.api.Component; 1.37 +import com.sun.xml.internal.ws.api.ComponentFeature; 1.38 +import com.sun.xml.internal.ws.api.ComponentFeature.Target; 1.39 +import com.sun.xml.internal.ws.api.ComponentRegistry; 1.40 +import com.sun.xml.internal.ws.api.ComponentsFeature; 1.41 +import com.sun.xml.internal.ws.api.EndpointAddress; 1.42 +import com.sun.xml.internal.ws.api.WSBinding; 1.43 +import com.sun.xml.internal.ws.api.WSService; 1.44 +import com.sun.xml.internal.ws.api.addressing.AddressingVersion; 1.45 +import com.sun.xml.internal.ws.api.addressing.WSEndpointReference; 1.46 +import com.sun.xml.internal.ws.api.client.WSPortInfo; 1.47 +import com.sun.xml.internal.ws.api.message.AddressingUtils; 1.48 +import com.sun.xml.internal.ws.api.message.Header; 1.49 +import com.sun.xml.internal.ws.api.message.HeaderList; 1.50 +import com.sun.xml.internal.ws.api.message.MessageHeaders; 1.51 +import com.sun.xml.internal.ws.api.message.Packet; 1.52 +import com.sun.xml.internal.ws.api.model.SEIModel; 1.53 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; 1.54 +import com.sun.xml.internal.ws.api.pipe.ClientTubeAssemblerContext; 1.55 +import com.sun.xml.internal.ws.api.pipe.Engine; 1.56 +import com.sun.xml.internal.ws.api.pipe.Fiber; 1.57 +import com.sun.xml.internal.ws.api.pipe.FiberContextSwitchInterceptorFactory; 1.58 +import com.sun.xml.internal.ws.api.pipe.SyncStartForAsyncFeature; 1.59 +import com.sun.xml.internal.ws.api.pipe.Tube; 1.60 +import com.sun.xml.internal.ws.api.pipe.TubelineAssembler; 1.61 +import com.sun.xml.internal.ws.api.pipe.TubelineAssemblerFactory; 1.62 +import com.sun.xml.internal.ws.api.server.Container; 1.63 +import com.sun.xml.internal.ws.api.server.ContainerResolver; 1.64 +import com.sun.xml.internal.ws.binding.BindingImpl; 1.65 +import com.sun.xml.internal.ws.developer.JAXWSProperties; 1.66 +import com.sun.xml.internal.ws.developer.WSBindingProvider; 1.67 +import com.sun.xml.internal.ws.model.wsdl.WSDLDirectProperties; 1.68 +import com.sun.xml.internal.ws.model.wsdl.WSDLPortProperties; 1.69 +import com.sun.xml.internal.ws.model.wsdl.WSDLProperties; 1.70 +import com.sun.xml.internal.ws.resources.ClientMessages; 1.71 +import com.sun.xml.internal.ws.util.Pool; 1.72 +import com.sun.xml.internal.ws.util.Pool.TubePool; 1.73 +import com.sun.xml.internal.ws.util.RuntimeVersion; 1.74 +import com.sun.xml.internal.ws.wsdl.OperationDispatcher; 1.75 +import com.sun.org.glassfish.gmbal.ManagedObjectManager; 1.76 + 1.77 +import javax.xml.namespace.QName; 1.78 +import javax.xml.stream.XMLStreamException; 1.79 +import javax.xml.ws.BindingProvider; 1.80 +import javax.xml.ws.EndpointReference; 1.81 +import javax.xml.ws.RespectBindingFeature; 1.82 +import javax.xml.ws.Response; 1.83 +import javax.xml.ws.WebServiceException; 1.84 +import javax.xml.ws.http.HTTPBinding; 1.85 +import javax.xml.ws.wsaddressing.W3CEndpointReference; 1.86 +import java.util.ArrayList; 1.87 +import java.util.Collections; 1.88 +import java.util.List; 1.89 +import java.util.Map; 1.90 +import java.util.Set; 1.91 +import java.util.concurrent.CopyOnWriteArraySet; 1.92 +import java.util.concurrent.Executor; 1.93 +import java.util.logging.Level; 1.94 +import java.util.logging.Logger; 1.95 +import javax.management.ObjectName; 1.96 + 1.97 +/** 1.98 + * Base class for stubs, which accept method invocations from 1.99 + * client applications and pass the message to a {@link Tube} 1.100 + * for processing. 1.101 + * 1.102 + * <p> 1.103 + * This class implements the management of pipe instances, 1.104 + * and most of the {@link BindingProvider} methods. 1.105 + * 1.106 + * @author Kohsuke Kawaguchi 1.107 + */ 1.108 +public abstract class Stub implements WSBindingProvider, ResponseContextReceiver, ComponentRegistry { 1.109 + /** 1.110 + * Internal flag indicating async dispatch should be used even when the 1.111 + * SyncStartForAsyncInvokeFeature is present on the binding associated 1.112 + * with a stub. There is no type associated with this property on the 1.113 + * request context. Its presence is what triggers the 'prevent' behavior. 1.114 + */ 1.115 + public static final String PREVENT_SYNC_START_FOR_ASYNC_INVOKE = "com.sun.xml.internal.ws.client.StubRequestSyncStartForAsyncInvoke"; 1.116 + 1.117 + /** 1.118 + * Reuse pipelines as it's expensive to create. 1.119 + * <p> 1.120 + * Set to null when {@link #close() closed}. 1.121 + */ 1.122 + private Pool<Tube> tubes; 1.123 + 1.124 + private final Engine engine; 1.125 + 1.126 + /** 1.127 + * The {@link WSServiceDelegate} object that owns us. 1.128 + */ 1.129 + protected final WSServiceDelegate owner; 1.130 + 1.131 + /** 1.132 + * Non-null if this stub is configured to talk to an EPR. 1.133 + * <p> 1.134 + * When this field is non-null, its reference parameters are sent as out-bound headers. 1.135 + * This field can be null even when addressing is enabled, but if the addressing is 1.136 + * not enabled, this field must be null. 1.137 + * <p> 1.138 + * Unlike endpoint address, we are not letting users to change the EPR, 1.139 + * as it contains references to services and so on that we don't want to change. 1.140 + */ 1.141 + protected 1.142 + @Nullable 1.143 + WSEndpointReference endpointReference; 1.144 + 1.145 + protected final BindingImpl binding; 1.146 + 1.147 + protected final WSPortInfo portInfo; 1.148 + 1.149 + /** 1.150 + * represents AddressingVersion on binding if enabled, otherwise null; 1.151 + */ 1.152 + protected AddressingVersion addrVersion; 1.153 + 1.154 + public RequestContext requestContext = new RequestContext(); 1.155 + 1.156 + private final RequestContext cleanRequestContext; 1.157 + 1.158 + /** 1.159 + * {@link ResponseContext} from the last synchronous operation. 1.160 + */ 1.161 + private ResponseContext responseContext; 1.162 + @Nullable 1.163 + protected final WSDLPort wsdlPort; 1.164 + 1.165 + protected QName portname; 1.166 + 1.167 + /** 1.168 + * {@link Header}s to be added to outbound {@link Packet}. 1.169 + * The contents is determined by the user. 1.170 + */ 1.171 + @Nullable 1.172 + private volatile Header[] userOutboundHeaders; 1.173 + 1.174 + private final 1.175 + @NotNull 1.176 + WSDLProperties wsdlProperties; 1.177 + protected OperationDispatcher operationDispatcher = null; 1.178 + private final 1.179 + @NotNull 1.180 + ManagedObjectManager managedObjectManager; 1.181 + private boolean managedObjectManagerClosed = false; 1.182 + 1.183 + private final Set<Component> components = new CopyOnWriteArraySet<Component>(); 1.184 + 1.185 + /** 1.186 + * @param master The created stub will send messages to this pipe. 1.187 + * @param binding As a {@link BindingProvider}, this object will 1.188 + * return this binding from {@link BindingProvider#getBinding()}. 1.189 + * @param defaultEndPointAddress The destination of the message. The actual destination 1.190 + * could be overridden by {@link RequestContext}. 1.191 + * @param epr To create a stub that sends out reference parameters 1.192 + * of a specific EPR, give that instance. Otherwise null. 1.193 + * Its address field will not be used, and that should be given 1.194 + * separately as the <tt>defaultEndPointAddress</tt>. 1.195 + */ 1.196 + @Deprecated 1.197 + protected Stub(WSServiceDelegate owner, Tube master, BindingImpl binding, WSDLPort wsdlPort, EndpointAddress defaultEndPointAddress, @Nullable WSEndpointReference epr) { 1.198 + this(owner, master, null, null, binding, wsdlPort, defaultEndPointAddress, epr); 1.199 + } 1.200 + 1.201 + /** 1.202 + * @param portname The name of this port 1.203 + * @param master The created stub will send messages to this pipe. 1.204 + * @param binding As a {@link BindingProvider}, this object will 1.205 + * return this binding from {@link BindingProvider#getBinding()}. 1.206 + * @param defaultEndPointAddress The destination of the message. The actual destination 1.207 + * could be overridden by {@link RequestContext}. 1.208 + * @param epr To create a stub that sends out reference parameters 1.209 + * of a specific EPR, give that instance. Otherwise null. 1.210 + * Its address field will not be used, and that should be given 1.211 + * separately as the <tt>defaultEndPointAddress</tt>. 1.212 + */ 1.213 + @Deprecated 1.214 + protected Stub(QName portname, WSServiceDelegate owner, Tube master, BindingImpl binding, WSDLPort wsdlPort, EndpointAddress defaultEndPointAddress, @Nullable WSEndpointReference epr) { 1.215 + this(owner, master, null, portname, binding, wsdlPort, defaultEndPointAddress, epr); 1.216 + } 1.217 + 1.218 + /** 1.219 + * @param portInfo PortInfo for this stub 1.220 + * @param binding As a {@link BindingProvider}, this object will 1.221 + * return this binding from {@link BindingProvider#getBinding()}. 1.222 + * @param master The created stub will send messages to this pipe. 1.223 + * @param defaultEndPointAddress The destination of the message. The actual destination 1.224 + * could be overridden by {@link RequestContext}. 1.225 + * @param epr To create a stub that sends out reference parameters 1.226 + * of a specific EPR, give that instance. Otherwise null. 1.227 + * Its address field will not be used, and that should be given 1.228 + * separately as the <tt>defaultEndPointAddress</tt>. 1.229 + */ 1.230 + protected Stub(WSPortInfo portInfo, BindingImpl binding, Tube master,EndpointAddress defaultEndPointAddress, @Nullable WSEndpointReference epr) { 1.231 + this((WSServiceDelegate) portInfo.getOwner(), master, portInfo, null, binding,portInfo.getPort(), defaultEndPointAddress, epr); 1.232 + } 1.233 + 1.234 + /** 1.235 + * @param portInfo PortInfo for this stub 1.236 + * @param binding As a {@link BindingProvider}, this object will 1.237 + * return this binding from {@link BindingProvider#getBinding()}. 1.238 + * @param defaultEndPointAddress The destination of the message. The actual destination 1.239 + * could be overridden by {@link RequestContext}. 1.240 + * @param epr To create a stub that sends out reference parameters 1.241 + * of a specific EPR, give that instance. Otherwise null. 1.242 + * Its address field will not be used, and that should be given 1.243 + * separately as the <tt>defaultEndPointAddress</tt>. 1.244 + */ 1.245 + protected Stub(WSPortInfo portInfo, BindingImpl binding, EndpointAddress defaultEndPointAddress, @Nullable WSEndpointReference epr) { 1.246 + this(portInfo,binding,null, defaultEndPointAddress,epr); 1.247 + 1.248 + } 1.249 + 1.250 + private Stub(WSServiceDelegate owner, @Nullable Tube master, @Nullable WSPortInfo portInfo, QName portname, BindingImpl binding, @Nullable WSDLPort wsdlPort, EndpointAddress defaultEndPointAddress, @Nullable WSEndpointReference epr) { 1.251 + Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer()); 1.252 + try { 1.253 + this.owner = owner; 1.254 + this.portInfo = portInfo; 1.255 + this.wsdlPort = wsdlPort != null ? wsdlPort : (portInfo != null ? portInfo.getPort() : null); 1.256 + this.portname = portname; 1.257 + if (portname == null) { 1.258 + if (portInfo != null) { 1.259 + this.portname = portInfo.getPortName(); 1.260 + } else if (wsdlPort != null) { 1.261 + this.portname = wsdlPort.getName(); 1.262 + } 1.263 + } 1.264 + this.binding = binding; 1.265 + 1.266 + ComponentFeature cf = binding.getFeature(ComponentFeature.class); 1.267 + if (cf != null && Target.STUB.equals(cf.getTarget())) { 1.268 + components.add(cf.getComponent()); 1.269 + } 1.270 + ComponentsFeature csf = binding.getFeature(ComponentsFeature.class); 1.271 + if (csf != null) { 1.272 + for (ComponentFeature cfi : csf.getComponentFeatures()) { 1.273 + if (Target.STUB.equals(cfi.getTarget())) 1.274 + components.add(cfi.getComponent()); 1.275 + } 1.276 + } 1.277 + 1.278 + // if there is an EPR, EPR's address should be used for invocation instead of default address 1.279 + if (epr != null) { 1.280 + this.requestContext.setEndPointAddressString(epr.getAddress()); 1.281 + } else { 1.282 + this.requestContext.setEndpointAddress(defaultEndPointAddress); 1.283 + } 1.284 + this.engine = new Engine(getStringId(), owner.getContainer(), owner.getExecutor()); 1.285 + this.endpointReference = epr; 1.286 + wsdlProperties = (wsdlPort == null) ? new WSDLDirectProperties(owner.getServiceName(), portname) : new WSDLPortProperties(wsdlPort); 1.287 + 1.288 + this.cleanRequestContext = this.requestContext.copy(); 1.289 + 1.290 + // ManagedObjectManager MUST be created before the pipeline 1.291 + // is constructed. 1.292 + 1.293 + managedObjectManager = new MonitorRootClient(this).createManagedObjectManager(this); 1.294 + 1.295 + if (master != null) { 1.296 + this.tubes = new TubePool(master); 1.297 + } else { 1.298 + this.tubes = new TubePool(createPipeline(portInfo, binding)); 1.299 + } 1.300 + 1.301 + addrVersion = binding.getAddressingVersion(); 1.302 + 1.303 + // This needs to happen after createPipeline. 1.304 + // TBD: Check if it needs to happen outside the Stub constructor. 1.305 + managedObjectManager.resumeJMXRegistration(); 1.306 + } finally { 1.307 + ContainerResolver.getDefault().exitContainer(old); 1.308 + } 1.309 + } 1.310 + 1.311 + /** 1.312 + * Creates a new pipeline for the given port name. 1.313 + */ 1.314 + private Tube createPipeline(WSPortInfo portInfo, WSBinding binding) { 1.315 + //Check all required WSDL extensions are understood 1.316 + checkAllWSDLExtensionsUnderstood(portInfo, binding); 1.317 + SEIModel seiModel = null; 1.318 + Class sei = null; 1.319 + if (portInfo instanceof SEIPortInfo) { 1.320 + SEIPortInfo sp = (SEIPortInfo) portInfo; 1.321 + seiModel = sp.model; 1.322 + sei = sp.sei; 1.323 + } 1.324 + BindingID bindingId = portInfo.getBindingId(); 1.325 + 1.326 + TubelineAssembler assembler = TubelineAssemblerFactory.create( 1.327 + Thread.currentThread().getContextClassLoader(), bindingId, owner.getContainer()); 1.328 + if (assembler == null) { 1.329 + throw new WebServiceException("Unable to process bindingID=" + bindingId); // TODO: i18n 1.330 + } 1.331 + return assembler.createClient( 1.332 + new ClientTubeAssemblerContext( 1.333 + portInfo.getEndpointAddress(), 1.334 + portInfo.getPort(), 1.335 + this, binding, owner.getContainer(), ((BindingImpl) binding).createCodec(), seiModel, sei)); 1.336 + } 1.337 + 1.338 + public WSDLPort getWSDLPort() { 1.339 + return wsdlPort; 1.340 + } 1.341 + 1.342 + public WSService getService() { 1.343 + return owner; 1.344 + } 1.345 + 1.346 + public Pool<Tube> getTubes() { 1.347 + return tubes; 1.348 + } 1.349 + 1.350 + /** 1.351 + * Checks only if RespectBindingFeature is enabled 1.352 + * checks if all required wsdl extensions in the 1.353 + * corresponding wsdl:Port are understood when RespectBindingFeature is enabled. 1.354 + * @throws WebServiceException 1.355 + * when any wsdl extension that has wsdl:required=true is not understood 1.356 + */ 1.357 + private static void checkAllWSDLExtensionsUnderstood(WSPortInfo port, WSBinding binding) { 1.358 + if (port.getPort() != null && binding.isFeatureEnabled(RespectBindingFeature.class)) { 1.359 + port.getPort().areRequiredExtensionsUnderstood(); 1.360 + } 1.361 + } 1.362 + 1.363 + @Override 1.364 + public WSPortInfo getPortInfo() { 1.365 + return portInfo; 1.366 + } 1.367 + 1.368 + /** 1.369 + * Nullable when there is no associated WSDL Model 1.370 + * @return 1.371 + */ 1.372 + public 1.373 + @Nullable 1.374 + OperationDispatcher getOperationDispatcher() { 1.375 + if (operationDispatcher == null && wsdlPort != null) { 1.376 + operationDispatcher = new OperationDispatcher(wsdlPort, binding, null); 1.377 + } 1.378 + return operationDispatcher; 1.379 + } 1.380 + 1.381 + /** 1.382 + * Gets the port name that this stub is configured to talk to. 1.383 + * <p> 1.384 + * When {@link #wsdlPort} is non-null, the port name is always 1.385 + * the same as {@link WSDLPort#getName()}, but this method 1.386 + * returns a port name even if no WSDL is available for this stub. 1.387 + */ 1.388 + protected abstract 1.389 + @NotNull 1.390 + QName getPortName(); 1.391 + 1.392 + /** 1.393 + * Gets the service name that this stub is configured to talk to. 1.394 + * <p> 1.395 + * When {@link #wsdlPort} is non-null, the service name is always 1.396 + * the same as the one that's inferred from {@link WSDLPort#getOwner()}, 1.397 + * but this method returns a port name even if no WSDL is available for 1.398 + * this stub. 1.399 + */ 1.400 + protected final 1.401 + @NotNull 1.402 + QName getServiceName() { 1.403 + return owner.getServiceName(); 1.404 + } 1.405 + 1.406 + /** 1.407 + * Gets the {@link Executor} to be used for asynchronous method invocations. 1.408 + * <p> 1.409 + * Note that the value this method returns may different from invocations 1.410 + * to invocations. The caller must not cache. 1.411 + * 1.412 + * @return always non-null. 1.413 + */ 1.414 + public final Executor getExecutor() { 1.415 + return owner.getExecutor(); 1.416 + } 1.417 + 1.418 + /** 1.419 + * Passes a message to a pipe for processing. 1.420 + * <p> 1.421 + * Unlike {@link Tube} instances, 1.422 + * this method is thread-safe and can be invoked from 1.423 + * multiple threads concurrently. 1.424 + * 1.425 + * @param packet The message to be sent to the server 1.426 + * @param requestContext The {@link RequestContext} when this invocation is originally scheduled. 1.427 + * This must be the same object as {@link #requestContext} for synchronous 1.428 + * invocations, but for asynchronous invocations, it needs to be a snapshot 1.429 + * captured at the point of invocation, to correctly satisfy the spec requirement. 1.430 + * @param receiver Receives the {@link ResponseContext}. Since the spec requires 1.431 + * that the asynchronous invocations must not update response context, 1.432 + * depending on the mode of invocation they have to go to different places. 1.433 + * So we take a setter that abstracts that away. 1.434 + */ 1.435 + protected final Packet process(Packet packet, RequestContext requestContext, ResponseContextReceiver receiver) { 1.436 + packet.isSynchronousMEP = true; 1.437 + packet.component = this; 1.438 + configureRequestPacket(packet, requestContext); 1.439 + Pool<Tube> pool = tubes; 1.440 + if (pool == null) { 1.441 + throw new WebServiceException("close method has already been invoked"); // TODO: i18n 1.442 + } 1.443 + 1.444 + Fiber fiber = engine.createFiber(); 1.445 + configureFiber(fiber); 1.446 + 1.447 + // then send it away! 1.448 + Tube tube = pool.take(); 1.449 + 1.450 + try { 1.451 + return fiber.runSync(tube, packet); 1.452 + } finally { 1.453 + // this allows us to capture the packet even when the call failed with an exception. 1.454 + // when the call fails with an exception it's no longer a 'reply' but it may provide some information 1.455 + // about what went wrong. 1.456 + 1.457 + // note that Packet can still be updated after 1.458 + // ResponseContext is created. 1.459 + Packet reply = (fiber.getPacket() == null) ? packet : fiber.getPacket(); 1.460 + receiver.setResponseContext(new ResponseContext(reply)); 1.461 + 1.462 + pool.recycle(tube); 1.463 + } 1.464 + } 1.465 + 1.466 + private void configureRequestPacket(Packet packet, RequestContext requestContext) { 1.467 + // fill in Packet 1.468 + packet.proxy = this; 1.469 + packet.handlerConfig = binding.getHandlerConfig(); 1.470 + 1.471 + // to make it multi-thread safe we need to first get a stable snapshot 1.472 + Header[] hl = userOutboundHeaders; 1.473 + if (hl != null) { 1.474 + MessageHeaders mh = packet.getMessage().getHeaders(); 1.475 + for (Header h : hl) { 1.476 + mh.add(h); 1.477 + } 1.478 + } 1.479 + 1.480 + requestContext.fill(packet, (binding.getAddressingVersion() != null)); 1.481 + packet.addSatellite(wsdlProperties); 1.482 + 1.483 + if (addrVersion != null) { 1.484 + // populate request WS-Addressing headers 1.485 + MessageHeaders headerList = packet.getMessage().getHeaders(); 1.486 + AddressingUtils.fillRequestAddressingHeaders(headerList, wsdlPort, binding, packet); 1.487 + 1.488 + 1.489 + // Spec is not clear on if ReferenceParameters are to be added when addressing is not enabled, 1.490 + // but the EPR has ReferenceParameters. 1.491 + // Current approach: Add ReferenceParameters only if addressing enabled. 1.492 + if (endpointReference != null) { 1.493 + endpointReference.addReferenceParametersToList(packet.getMessage().getHeaders()); 1.494 + } 1.495 + } 1.496 + } 1.497 + 1.498 + /** 1.499 + * Passes a message through a {@link Tube}line for processing. The processing happens 1.500 + * asynchronously and when the response is available, Fiber.CompletionCallback is 1.501 + * called. The processing could happen on multiple threads. 1.502 + * 1.503 + * <p> 1.504 + * Unlike {@link Tube} instances, 1.505 + * this method is thread-safe and can be invoked from 1.506 + * multiple threads concurrently. 1.507 + * 1.508 + * @param receiver The {@link Response} implementation 1.509 + * @param request The message to be sent to the server 1.510 + * @param requestContext The {@link RequestContext} when this invocation is originally scheduled. 1.511 + * This must be the same object as {@link #requestContext} for synchronous 1.512 + * invocations, but for asynchronous invocations, it needs to be a snapshot 1.513 + * captured at the point of invocation, to correctly satisfy the spec requirement. 1.514 + * @param completionCallback Once the processing is done, the callback is invoked. 1.515 + */ 1.516 + protected final void processAsync(AsyncResponseImpl<?> receiver, Packet request, RequestContext requestContext, final Fiber.CompletionCallback completionCallback) { 1.517 + // fill in Packet 1.518 + request.component = this; 1.519 + configureRequestPacket(request, requestContext); 1.520 + 1.521 + final Pool<Tube> pool = tubes; 1.522 + if (pool == null) { 1.523 + throw new WebServiceException("close method has already been invoked"); // TODO: i18n 1.524 + } 1.525 + 1.526 + final Fiber fiber = engine.createFiber(); 1.527 + configureFiber(fiber); 1.528 + 1.529 + receiver.setCancelable(fiber); 1.530 + 1.531 + // check race condition on cancel 1.532 + if (receiver.isCancelled()) { 1.533 + return; 1.534 + } 1.535 + 1.536 + FiberContextSwitchInterceptorFactory fcsif = owner.getSPI(FiberContextSwitchInterceptorFactory.class); 1.537 + if (fcsif != null) { 1.538 + fiber.addInterceptor(fcsif.create()); 1.539 + } 1.540 + 1.541 + // then send it away! 1.542 + final Tube tube = pool.take(); 1.543 + 1.544 + Fiber.CompletionCallback fiberCallback = new Fiber.CompletionCallback() { 1.545 + @Override 1.546 + public void onCompletion(@NotNull Packet response) { 1.547 + pool.recycle(tube); 1.548 + completionCallback.onCompletion(response); 1.549 + } 1.550 + 1.551 + @Override 1.552 + public void onCompletion(@NotNull Throwable error) { 1.553 + // let's not reuse tubes as they might be in a wrong state, so not 1.554 + // calling pool.recycle() 1.555 + completionCallback.onCompletion(error); 1.556 + } 1.557 + }; 1.558 + 1.559 + // Check for SyncStartForAsyncInvokeFeature 1.560 + 1.561 + fiber.start(tube, request, fiberCallback, 1.562 + getBinding().isFeatureEnabled(SyncStartForAsyncFeature.class) && 1.563 + !requestContext.containsKey(PREVENT_SYNC_START_FOR_ASYNC_INVOKE)); 1.564 + } 1.565 + 1.566 + protected void configureFiber(Fiber fiber) { 1.567 + // no-op in the base class, but can be used by derived classes to configure the Fiber prior 1.568 + // to invocation 1.569 + } 1.570 + 1.571 + private static final Logger monitoringLogger = Logger.getLogger(com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".monitoring"); 1.572 + 1.573 + @Override 1.574 + public void close() { 1.575 + TubePool tp = (TubePool) tubes; 1.576 + if (tp != null) { 1.577 + // multi-thread safety of 'close' needs to be considered more carefully. 1.578 + // some calls might be pending while this method is invoked. Should we 1.579 + // block until they are complete, or should we abort them (but how?) 1.580 + Tube p = tp.takeMaster(); 1.581 + p.preDestroy(); 1.582 + tubes = null; 1.583 + } 1.584 + if (!managedObjectManagerClosed) { 1.585 + try { 1.586 + final ObjectName name = managedObjectManager.getObjectName(managedObjectManager.getRoot()); 1.587 + // The name is null when the MOM is a NOOP. 1.588 + if (name != null) { 1.589 + monitoringLogger.log(Level.INFO, "Closing Metro monitoring root: {0}", name); 1.590 + } 1.591 + managedObjectManager.close(); 1.592 + } catch (java.io.IOException e) { 1.593 + monitoringLogger.log(Level.WARNING, "Ignoring error when closing Managed Object Manager", e); 1.594 + } 1.595 + managedObjectManagerClosed = true; 1.596 + } 1.597 + } 1.598 + 1.599 + @Override 1.600 + public final WSBinding getBinding() { 1.601 + return binding; 1.602 + } 1.603 + 1.604 + @Override 1.605 + public final Map<String, Object> getRequestContext() { 1.606 + return requestContext.asMap(); 1.607 + } 1.608 + 1.609 + public void resetRequestContext() { 1.610 + requestContext = cleanRequestContext.copy(); 1.611 + } 1.612 + 1.613 + @Override 1.614 + public final ResponseContext getResponseContext() { 1.615 + return responseContext; 1.616 + } 1.617 + 1.618 + @Override 1.619 + public void setResponseContext(ResponseContext rc) { 1.620 + this.responseContext = rc; 1.621 + } 1.622 + 1.623 + private String getStringId() { 1.624 + return RuntimeVersion.VERSION + ": Stub for " + getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY); 1.625 + } 1.626 + 1.627 + @Override 1.628 + public String toString() { 1.629 + return getStringId(); 1.630 + } 1.631 + 1.632 + @Override 1.633 + public final WSEndpointReference getWSEndpointReference() { 1.634 + if (binding.getBindingID().equals(HTTPBinding.HTTP_BINDING)) { 1.635 + throw new java.lang.UnsupportedOperationException( 1.636 + ClientMessages.UNSUPPORTED_OPERATION("BindingProvider.getEndpointReference(Class<T> class)", "XML/HTTP Binding", "SOAP11 or SOAP12 Binding") 1.637 + ); 1.638 + } 1.639 + 1.640 + if (endpointReference != null) { 1.641 + return endpointReference; 1.642 + } 1.643 + 1.644 + String eprAddress = requestContext.getEndpointAddress().toString(); 1.645 + QName portTypeName = null; 1.646 + String wsdlAddress = null; 1.647 + List<WSEndpointReference.EPRExtension> wsdlEPRExtensions = new ArrayList<WSEndpointReference.EPRExtension>(); 1.648 + if (wsdlPort != null) { 1.649 + portTypeName = wsdlPort.getBinding().getPortTypeName(); 1.650 + wsdlAddress = eprAddress + "?wsdl"; 1.651 + 1.652 + //gather EPRExtensions specified in WSDL. 1.653 + try { 1.654 + WSEndpointReference wsdlEpr = wsdlPort.getEPR(); 1.655 + if (wsdlEpr != null) { 1.656 + for (WSEndpointReference.EPRExtension extnEl : wsdlEpr.getEPRExtensions()) { 1.657 + wsdlEPRExtensions.add(new WSEPRExtension( 1.658 + XMLStreamBuffer.createNewBufferFromXMLStreamReader(extnEl.readAsXMLStreamReader()), extnEl.getQName())); 1.659 + } 1.660 + } 1.661 + 1.662 + } catch (XMLStreamException ex) { 1.663 + throw new WebServiceException(ex); 1.664 + } 1.665 + } 1.666 + AddressingVersion av = AddressingVersion.W3C; 1.667 + this.endpointReference = new WSEndpointReference( 1.668 + av, eprAddress, getServiceName(), getPortName(), portTypeName, null, wsdlAddress, null, wsdlEPRExtensions, null); 1.669 + 1.670 + return this.endpointReference; 1.671 + } 1.672 + 1.673 + 1.674 + @Override 1.675 + public final W3CEndpointReference getEndpointReference() { 1.676 + if (binding.getBindingID().equals(HTTPBinding.HTTP_BINDING)) { 1.677 + throw new java.lang.UnsupportedOperationException( 1.678 + ClientMessages.UNSUPPORTED_OPERATION("BindingProvider.getEndpointReference()", "XML/HTTP Binding", "SOAP11 or SOAP12 Binding")); 1.679 + } 1.680 + return getEndpointReference(W3CEndpointReference.class); 1.681 + } 1.682 + 1.683 + @Override 1.684 + public final <T extends EndpointReference> T getEndpointReference(Class<T> clazz) { 1.685 + return getWSEndpointReference().toSpec(clazz); 1.686 + } 1.687 + 1.688 + public 1.689 + @NotNull 1.690 + @Override 1.691 + ManagedObjectManager getManagedObjectManager() { 1.692 + return managedObjectManager; 1.693 + } 1.694 + 1.695 + // 1.696 +// 1.697 +// WSBindingProvider methods 1.698 +// 1.699 +// 1.700 + @Override 1.701 + public final void setOutboundHeaders(List<Header> headers) { 1.702 + if (headers == null) { 1.703 + this.userOutboundHeaders = null; 1.704 + } else { 1.705 + for (Header h : headers) { 1.706 + if (h == null) { 1.707 + throw new IllegalArgumentException(); 1.708 + } 1.709 + } 1.710 + userOutboundHeaders = headers.toArray(new Header[headers.size()]); 1.711 + } 1.712 + } 1.713 + 1.714 + @Override 1.715 + public final void setOutboundHeaders(Header... headers) { 1.716 + if (headers == null) { 1.717 + this.userOutboundHeaders = null; 1.718 + } else { 1.719 + for (Header h : headers) { 1.720 + if (h == null) { 1.721 + throw new IllegalArgumentException(); 1.722 + } 1.723 + } 1.724 + Header[] hl = new Header[headers.length]; 1.725 + System.arraycopy(headers, 0, hl, 0, headers.length); 1.726 + userOutboundHeaders = hl; 1.727 + } 1.728 + } 1.729 + 1.730 + @Override 1.731 + public final List<Header> getInboundHeaders() { 1.732 + return Collections.unmodifiableList(((MessageHeaders) 1.733 + responseContext.get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY)).asList()); 1.734 + } 1.735 + 1.736 + @Override 1.737 + public final void setAddress(String address) { 1.738 + requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address); 1.739 + } 1.740 + 1.741 + @Override 1.742 + public <S> S getSPI(Class<S> spiType) { 1.743 + for (Component c : components) { 1.744 + S s = c.getSPI(spiType); 1.745 + if (s != null) { 1.746 + return s; 1.747 + } 1.748 + } 1.749 + return owner.getSPI(spiType); 1.750 + } 1.751 + 1.752 + @Override 1.753 + public Set<Component> getComponents() { 1.754 + return components; 1.755 + } 1.756 +}