src/share/jaxws_classes/com/sun/xml/internal/ws/api/pipe/ClientTubeAssemblerContext.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/pipe/ClientTubeAssemblerContext.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,340 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, 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.api.pipe;
    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.ws.addressing.W3CWsaClientTube;
    1.34 +import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionWsaClientTube;
    1.35 +import com.sun.xml.internal.ws.api.EndpointAddress;
    1.36 +import com.sun.xml.internal.ws.api.WSBinding;
    1.37 +import com.sun.xml.internal.ws.api.WSService;
    1.38 +import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    1.39 +import com.sun.xml.internal.ws.api.client.ClientPipelineHook;
    1.40 +import com.sun.xml.internal.ws.api.client.WSPortInfo;
    1.41 +import com.sun.xml.internal.ws.api.model.SEIModel;
    1.42 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.43 +import com.sun.xml.internal.ws.api.pipe.helper.PipeAdapter;
    1.44 +import com.sun.xml.internal.ws.api.server.Container;
    1.45 +import com.sun.xml.internal.ws.binding.BindingImpl;
    1.46 +import com.sun.xml.internal.ws.client.ClientSchemaValidationTube;
    1.47 +import com.sun.xml.internal.ws.developer.SchemaValidationFeature;
    1.48 +import com.sun.xml.internal.ws.developer.WSBindingProvider;
    1.49 +import com.sun.xml.internal.ws.handler.ClientLogicalHandlerTube;
    1.50 +import com.sun.xml.internal.ws.handler.ClientMessageHandlerTube;
    1.51 +import com.sun.xml.internal.ws.handler.ClientSOAPHandlerTube;
    1.52 +import com.sun.xml.internal.ws.handler.HandlerTube;
    1.53 +import com.sun.xml.internal.ws.protocol.soap.ClientMUTube;
    1.54 +import com.sun.xml.internal.ws.transport.DeferredTransportPipe;
    1.55 +import com.sun.xml.internal.ws.util.pipe.DumpTube;
    1.56 +
    1.57 +import javax.xml.ws.soap.SOAPBinding;
    1.58 +import java.io.PrintStream;
    1.59 +
    1.60 +/**
    1.61 + * Factory for well-known {@link Tube} implementations
    1.62 + * that the {@link TubelineAssembler} needs to use
    1.63 + * to satisfy JAX-WS requirements.
    1.64 + *
    1.65 + * @author Jitendra Kotamraju
    1.66 + */
    1.67 +public class ClientTubeAssemblerContext {
    1.68 +
    1.69 +    private final @NotNull EndpointAddress address;
    1.70 +    private final @Nullable WSDLPort wsdlModel;
    1.71 +    private final @Nullable SEIModel seiModel;
    1.72 +    private final @Nullable Class    sei;
    1.73 +    private final @NotNull WSService rootOwner;
    1.74 +    private final @NotNull WSBinding binding;
    1.75 +    private final @NotNull Container container;
    1.76 +    private @NotNull Codec codec;
    1.77 +
    1.78 +    //Nullable only to maintain comaptibility with old constructors of this class.
    1.79 +    private final @Nullable WSBindingProvider bindingProvider;
    1.80 +
    1.81 +    /**
    1.82 +     * This constructor should be used only by JAX-WS Runtime and is not meant for external consumption.
    1.83 +     * @deprecated
    1.84 +     *      Use {@link #ClientTubeAssemblerContext(EndpointAddress, WSDLPort, WSBindingProvider, WSBinding, Container, Codec, SEIModel)}
    1.85 +     */
    1.86 +    public ClientTubeAssemblerContext(@NotNull EndpointAddress address, @Nullable WSDLPort wsdlModel, @NotNull WSService rootOwner, @NotNull WSBinding binding) {
    1.87 +        this(address, wsdlModel, rootOwner, binding, Container.NONE);
    1.88 +    }
    1.89 +
    1.90 +    /**
    1.91 +     * This constructor should be used only by JAX-WS Runtime and is not meant for external consumption.
    1.92 +     * @deprecated
    1.93 +     *      Use {@link #ClientTubeAssemblerContext(EndpointAddress, WSDLPort, WSBindingProvider, WSBinding, Container, Codec, SEIModel)}.
    1.94 +     */
    1.95 +    public ClientTubeAssemblerContext(@NotNull EndpointAddress address, @Nullable WSDLPort wsdlModel,
    1.96 +                                      @NotNull WSService rootOwner, @NotNull WSBinding binding,
    1.97 +                                      @NotNull Container container) {
    1.98 +        // WSBinding is actually BindingImpl
    1.99 +        this(address, wsdlModel, rootOwner, binding, container, ((BindingImpl)binding).createCodec() );
   1.100 +    }
   1.101 +
   1.102 +    /**
   1.103 +     * This constructor should be used only by JAX-WS Runtime and is not meant for external consumption.
   1.104 +     * @deprecated
   1.105 +     *      Use {@link #ClientTubeAssemblerContext(EndpointAddress, WSDLPort, WSBindingProvider, WSBinding, Container, Codec,SEIModel)}.
   1.106 +     */
   1.107 +    public ClientTubeAssemblerContext(@NotNull EndpointAddress address, @Nullable WSDLPort wsdlModel,
   1.108 +                                      @NotNull WSService rootOwner, @NotNull WSBinding binding,
   1.109 +                                      @NotNull Container container, Codec codec) {
   1.110 +        this(address, wsdlModel, rootOwner, binding, container, codec, null, null);
   1.111 +    }
   1.112 +
   1.113 +    /**
   1.114 +     * This constructor should be used only by JAX-WS Runtime and is not meant for external consumption.
   1.115 +     * @deprecated
   1.116 +     *      Use {@link #ClientTubeAssemblerContext(EndpointAddress, WSDLPort, WSBindingProvider, WSBinding, Container, Codec, SEIModel)}.
   1.117 +     */
   1.118 +    public ClientTubeAssemblerContext(@NotNull EndpointAddress address, @Nullable WSDLPort wsdlModel,
   1.119 +                                      @NotNull WSService rootOwner, @NotNull WSBinding binding,
   1.120 +                                      @NotNull Container container, Codec codec, SEIModel seiModel, Class sei) {
   1.121 +        this(address, wsdlModel, rootOwner, null/* no info on which port it is, so pass null*/, binding, container, codec, seiModel, sei);
   1.122 +    }
   1.123 +
   1.124 +    /**
   1.125 +     * This constructor should be used only by JAX-WS Runtime and is not meant for external consumption.
   1.126 +     *
   1.127 +     * @since JAX-WS 2.2
   1.128 +     */
   1.129 +    public ClientTubeAssemblerContext(@NotNull EndpointAddress address, @Nullable WSDLPort wsdlModel,
   1.130 +                                      @NotNull WSBindingProvider bindingProvider, @NotNull WSBinding binding,
   1.131 +                                      @NotNull Container container, Codec codec, SEIModel seiModel, Class sei) {
   1.132 +        this(address, wsdlModel, (bindingProvider==null? null: bindingProvider.getPortInfo().getOwner()), bindingProvider, binding, container, codec, seiModel, sei);
   1.133 +
   1.134 +    }
   1.135 +
   1.136 +    //common constructor
   1.137 +    //WSService is null, when ClientTubeAssemblerContext is created for sending non-anonymous responses.
   1.138 +    private ClientTubeAssemblerContext(@NotNull EndpointAddress address, @Nullable WSDLPort wsdlModel,
   1.139 +                                       @Nullable WSService rootOwner, @Nullable WSBindingProvider bindingProvider, @NotNull WSBinding binding,
   1.140 +                                      @NotNull Container container, Codec codec, SEIModel seiModel, Class sei) {
   1.141 +        this.address = address;
   1.142 +        this.wsdlModel = wsdlModel;
   1.143 +        this.rootOwner = rootOwner;
   1.144 +        this.bindingProvider = bindingProvider;
   1.145 +        this.binding = binding;
   1.146 +        this.container = container;
   1.147 +        this.codec = codec;
   1.148 +        this.seiModel = seiModel;
   1.149 +        this.sei = sei;
   1.150 +    }
   1.151 +
   1.152 +    /**
   1.153 +     * The endpoint address. Always non-null. This parameter is taken separately
   1.154 +     * from {@link com.sun.xml.internal.ws.api.model.wsdl.WSDLPort} (even though there's {@link com.sun.xml.internal.ws.api.model.wsdl.WSDLPort#getAddress()})
   1.155 +     * because sometimes WSDL is not available.
   1.156 +     */
   1.157 +    public @NotNull EndpointAddress getAddress() {
   1.158 +        return address;
   1.159 +    }
   1.160 +
   1.161 +    /**
   1.162 +     * The created pipeline will be used to serve this port.
   1.163 +     * Null if the service isn't associated with any port definition in WSDL,
   1.164 +     * and otherwise non-null.
   1.165 +     */
   1.166 +    public @Nullable WSDLPort getWsdlModel() {
   1.167 +        return wsdlModel;
   1.168 +    }
   1.169 +
   1.170 +    /**
   1.171 +     * The pipeline is created for this {@link com.sun.xml.internal.ws.api.WSService}.
   1.172 +     * Always non-null. (To be precise, the newly created pipeline
   1.173 +     * is owned by a proxy or a dispatch created from thsi {@link com.sun.xml.internal.ws.api.WSService}.)
   1.174 +     */
   1.175 +    public @NotNull WSService getService() {
   1.176 +        return rootOwner;
   1.177 +    }
   1.178 +
   1.179 +    /**
   1.180 +     * The pipeline is created for this {@link com.sun.xml.internal.ws.api.client.WSPortInfo}.
   1.181 +     * Nullable incase of backwards compatible usages of this class.
   1.182 +     */
   1.183 +    public @Nullable WSPortInfo getPortInfo() {
   1.184 +        return bindingProvider == null? null: bindingProvider.getPortInfo();
   1.185 +    }
   1.186 +
   1.187 +
   1.188 +    /**
   1.189 +     * The pipeline is created for this {@link WSBindingProvider}.
   1.190 +     * Nullable incase of backwards compatible usages of this class.
   1.191 +     */
   1.192 +    public @Nullable WSBindingProvider getBindingProvider() {
   1.193 +        return bindingProvider;
   1.194 +    }
   1.195 +
   1.196 +    /**
   1.197 +     * The binding of the new pipeline to be created.
   1.198 +     */
   1.199 +    public @NotNull WSBinding getBinding() {
   1.200 +        return binding;
   1.201 +    }
   1.202 +
   1.203 +    /**
   1.204 +     * The created pipeline will use seiModel to get java concepts for the endpoint
   1.205 +     *
   1.206 +     * @return Null if the service doesn't have SEI model e.g. Dispatch,
   1.207 +     *         and otherwise non-null.
   1.208 +     */
   1.209 +    public @Nullable SEIModel getSEIModel() {
   1.210 +        return seiModel;
   1.211 +    }
   1.212 +
   1.213 +    /**
   1.214 +     * The SEI class for the endpoint
   1.215 +     *
   1.216 +     * @return Null if the service doesn't have SEI model e.g. Dispatch,
   1.217 +     *         and otherwise non-null.
   1.218 +     */
   1.219 +    public @Nullable Class getSEI() {
   1.220 +        return sei;
   1.221 +    }
   1.222 +
   1.223 +    /**
   1.224 +     * Returns the Container in which the client is running
   1.225 +     *
   1.226 +     * @return Container in which client is running
   1.227 +     */
   1.228 +    public Container getContainer() {
   1.229 +        return container;
   1.230 +    }
   1.231 +
   1.232 +    /**
   1.233 +     * creates a {@link Tube} that dumps messages that pass through.
   1.234 +     */
   1.235 +    public Tube createDumpTube(String name, PrintStream out, Tube next) {
   1.236 +        return new DumpTube(name, out, next);
   1.237 +    }
   1.238 +
   1.239 +    /**
   1.240 +     * Creates a {@link Tube} that adds container specific security
   1.241 +     */
   1.242 +    public @NotNull Tube createSecurityTube(@NotNull Tube next) {
   1.243 +        ClientPipelineHook hook = container.getSPI(ClientPipelineHook.class);
   1.244 +        if (hook != null) {
   1.245 +            ClientPipeAssemblerContext ctxt = new ClientPipeAssemblerContext(address, wsdlModel,
   1.246 +                                      rootOwner, binding, container);
   1.247 +            return PipeAdapter.adapt(hook.createSecurityPipe(ctxt, PipeAdapter.adapt(next)));
   1.248 +        }
   1.249 +        return next;
   1.250 +    }
   1.251 +
   1.252 +    /**
   1.253 +     * Creates a {@link Tube} that invokes protocol and logical handlers.
   1.254 +     */
   1.255 +    public Tube createWsaTube(Tube next) {
   1.256 +        if (binding instanceof SOAPBinding && AddressingVersion.isEnabled(binding) && wsdlModel!=null)
   1.257 +            if(AddressingVersion.fromBinding(binding) == AddressingVersion.MEMBER) {
   1.258 +                return new MemberSubmissionWsaClientTube(wsdlModel, binding, next);
   1.259 +            } else {
   1.260 +                return new W3CWsaClientTube(wsdlModel, binding, next);
   1.261 +            }
   1.262 +        else
   1.263 +            return next;
   1.264 +    }
   1.265 +
   1.266 +    /**
   1.267 +     * Creates a {@link Tube} that invokes protocol and logical handlers.
   1.268 +     */
   1.269 +    public Tube createHandlerTube(Tube next) {
   1.270 +        HandlerTube cousinHandlerTube = null;
   1.271 +        //XML/HTTP Binding can have only LogicalHandlerPipe
   1.272 +        if (binding instanceof SOAPBinding) {
   1.273 +            //Add MessageHandlerTube
   1.274 +            HandlerTube messageHandlerTube = new ClientMessageHandlerTube(seiModel, binding, wsdlModel, next);
   1.275 +            next = cousinHandlerTube = messageHandlerTube;
   1.276 +
   1.277 +            //Add SOAPHandlerTuber
   1.278 +            HandlerTube soapHandlerTube = new ClientSOAPHandlerTube(binding, next, cousinHandlerTube);
   1.279 +            next = cousinHandlerTube = soapHandlerTube;
   1.280 +        }
   1.281 +        return new ClientLogicalHandlerTube(binding, seiModel, next, cousinHandlerTube);
   1.282 +    }
   1.283 +
   1.284 +    /**
   1.285 +     * Creates a {@link Tube} that performs SOAP mustUnderstand processing.
   1.286 +     * This pipe should be before HandlerPipes.
   1.287 +     */
   1.288 +    public Tube createClientMUTube(Tube next) {
   1.289 +        if(binding instanceof SOAPBinding)
   1.290 +            return new ClientMUTube(binding,next);
   1.291 +        else
   1.292 +            return next;
   1.293 +    }
   1.294 +
   1.295 +    /**
   1.296 +     * creates a {@link Tube} that validates messages against schema
   1.297 +     */
   1.298 +    public Tube createValidationTube(Tube next) {
   1.299 +        if (binding instanceof SOAPBinding && binding.isFeatureEnabled(SchemaValidationFeature.class) && wsdlModel!=null)
   1.300 +            return new ClientSchemaValidationTube(binding, wsdlModel, next);
   1.301 +        else
   1.302 +            return next;
   1.303 +    }
   1.304 +
   1.305 +    /**
   1.306 +     * Creates a transport pipe (for client), which becomes the terminal pipe.
   1.307 +     */
   1.308 +    public Tube createTransportTube() {
   1.309 +        ClassLoader cl = Thread.currentThread().getContextClassLoader();
   1.310 +
   1.311 +        // The application may configure the endpoint address through request context
   1.312 +        // using {@link BindingProvider#ENDPOINT_ADDRESS_PROPERTY}. Let us
   1.313 +        // defer the creation of actual transport until the service invocation,
   1.314 +        // DeferredTransportPipe is used for this purpose.
   1.315 +        return new DeferredTransportPipe(cl,this);
   1.316 +    }
   1.317 +
   1.318 +    /**
   1.319 +     * Gets the {@link Codec} that is set by {@link #setCodec} or the default codec
   1.320 +     * based on the binding.
   1.321 +     *
   1.322 +     * @return codec to be used for web service requests
   1.323 +     */
   1.324 +    public @NotNull Codec getCodec() {
   1.325 +        return codec;
   1.326 +    }
   1.327 +
   1.328 +    /**
   1.329 +     * Interception point to change {@link Codec} during {@link Tube}line assembly. The
   1.330 +     * new codec will be used by jax-ws client runtime for encoding/decoding web service
   1.331 +     * request/response messages. The new codec should be used by the transport tubes.
   1.332 +     *
   1.333 +     * <p>
   1.334 +     * the codec should correctly implement {@link Codec#copy} since it is used while
   1.335 +     * serving requests concurrently.
   1.336 +     *
   1.337 +     * @param codec codec to be used for web service requests
   1.338 +     */
   1.339 +    public void setCodec(@NotNull Codec codec) {
   1.340 +        this.codec = codec;
   1.341 +    }
   1.342 +
   1.343 +}

mercurial