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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     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.api.pipe;
    28 import com.sun.istack.internal.NotNull;
    29 import com.sun.istack.internal.Nullable;
    30 import com.sun.xml.internal.ws.addressing.W3CWsaServerTube;
    31 import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionWsaServerTube;
    32 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    33 import com.sun.xml.internal.ws.api.model.SEIModel;
    34 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    35 import com.sun.xml.internal.ws.api.pipe.helper.PipeAdapter;
    36 import com.sun.xml.internal.ws.api.server.ServerPipelineHook;
    37 import com.sun.xml.internal.ws.api.server.WSEndpoint;
    38 import com.sun.xml.internal.ws.binding.BindingImpl;
    39 import com.sun.xml.internal.ws.developer.SchemaValidationFeature;
    40 import com.sun.xml.internal.ws.handler.HandlerTube;
    41 import com.sun.xml.internal.ws.handler.ServerLogicalHandlerTube;
    42 import com.sun.xml.internal.ws.handler.ServerMessageHandlerTube;
    43 import com.sun.xml.internal.ws.handler.ServerSOAPHandlerTube;
    44 import com.sun.xml.internal.ws.protocol.soap.ServerMUTube;
    45 import com.sun.xml.internal.ws.server.ServerSchemaValidationTube;
    46 import com.sun.xml.internal.ws.util.pipe.DumpTube;
    48 import javax.xml.ws.soap.SOAPBinding;
    49 import java.io.PrintStream;
    51 /**
    52  * Factory for well-known server {@link Tube} implementations
    53  * that the {@link TubelineAssembler} needs to use
    54  * to satisfy JAX-WS requirements.
    55  *
    56  * @author Jitendra Kotamraju
    57  */
    58 public class ServerTubeAssemblerContext {
    60     private final SEIModel seiModel;
    61     private final WSDLPort wsdlModel;
    62     private final WSEndpoint endpoint;
    63     private final BindingImpl binding;
    64     private final Tube terminal;
    65     private final boolean isSynchronous;
    66     private @NotNull Codec codec;
    68     public ServerTubeAssemblerContext(@Nullable SEIModel seiModel,
    69                                       @Nullable WSDLPort wsdlModel, @NotNull WSEndpoint endpoint,
    70                                       @NotNull Tube terminal, boolean isSynchronous) {
    71         this.seiModel = seiModel;
    72         this.wsdlModel = wsdlModel;
    73         this.endpoint = endpoint;
    74         this.terminal = terminal;
    75         // WSBinding is actually BindingImpl
    76         this.binding = (BindingImpl)endpoint.getBinding();
    77         this.isSynchronous = isSynchronous;
    78         this.codec = this.binding.createCodec();
    79     }
    81     /**
    82      * The created pipeline will use seiModel to get java concepts for the endpoint
    83      *
    84      * @return Null if the service doesn't have SEI model e.g. Provider endpoints,
    85      *         and otherwise non-null.
    86      */
    87     public @Nullable SEIModel getSEIModel() {
    88         return seiModel;
    89     }
    91     /**
    92      * The created pipeline will be used to serve this port.
    93      *
    94      * @return Null if the service isn't associated with any port definition in WSDL,
    95      *         and otherwise non-null.
    96      */
    97     public @Nullable WSDLPort getWsdlModel() {
    98         return wsdlModel;
    99     }
   101     /**
   102      *
   103      * The created pipeline is used to serve this {@link com.sun.xml.internal.ws.api.server.WSEndpoint}.
   104      * Specifically, its {@link com.sun.xml.internal.ws.api.WSBinding} should be of interest to  many
   105      * {@link com.sun.xml.internal.ws.api.pipe.Pipe}s.
   106      *  @return Always non-null.
   107      */
   108     public @NotNull WSEndpoint<?> getEndpoint() {
   109         return endpoint;
   110     }
   112     /**
   113      * The last {@link com.sun.xml.internal.ws.api.pipe.Pipe} in the pipeline. The assembler is expected to put
   114      * additional {@link com.sun.xml.internal.ws.api.pipe.Pipe}s in front of it.
   115      *
   116      * <p>
   117      * (Just to give you the idea how this is used, normally the terminal pipe
   118      * is the one that invokes the user application or {@link javax.xml.ws.Provider}.)
   119      *
   120      * @return always non-null terminal pipe
   121      */
   122     public @NotNull Tube getTerminalTube() {
   123          return terminal;
   124     }
   126     /**
   127      * If this server pipeline is known to be used for serving synchronous transport,
   128      * then this method returns true. This can be potentially use as an optimization
   129      * hint, since often synchronous versions are cheaper to execute than asycnhronous
   130      * versions.
   131      */
   132     public boolean isSynchronous() {
   133         return isSynchronous;
   134     }
   136     /**
   137      * Creates a {@link Tube} that performs SOAP mustUnderstand processing.
   138      * This pipe should be before HandlerPipes.
   139      */
   140     public @NotNull Tube createServerMUTube(@NotNull Tube next) {
   141         if (binding instanceof SOAPBinding)
   142             return new ServerMUTube(this,next);
   143         else
   144             return next;
   145     }
   147     /**
   148      * Creates a {@link Tube} that invokes protocol and logical handlers.
   149      */
   150     public @NotNull Tube createHandlerTube(@NotNull Tube next) {
   151         if (!binding.getHandlerChain().isEmpty()) {
   152             HandlerTube cousin = new ServerLogicalHandlerTube(binding, seiModel, wsdlModel, next);
   153             next = cousin;
   154             if (binding instanceof SOAPBinding) {
   155                 //Add SOAPHandlerTube
   156                 next = cousin = new ServerSOAPHandlerTube(binding, next, cousin);
   158                 //Add MessageHandlerTube
   159                 next = new ServerMessageHandlerTube(seiModel, binding, next, cousin);
   160             }
   161         }
   162         return next;
   163     }
   165     /**
   166      * Creates a {@link Tube} that does the monitoring of the invocation for a
   167      * container
   168      */
   169     public @NotNull Tube createMonitoringTube(@NotNull Tube next) {
   170         ServerPipelineHook hook = endpoint.getContainer().getSPI(ServerPipelineHook.class);
   171         if (hook != null) {
   172             ServerPipeAssemblerContext ctxt = new ServerPipeAssemblerContext(seiModel, wsdlModel, endpoint, terminal, isSynchronous);
   173             return PipeAdapter.adapt(hook.createMonitoringPipe(ctxt, PipeAdapter.adapt(next)));
   174         }
   175         return next;
   176     }
   178     /**
   179      * Creates a {@link Tube} that adds container specific security
   180      */
   181     public @NotNull Tube createSecurityTube(@NotNull Tube next) {
   182         ServerPipelineHook hook = endpoint.getContainer().getSPI(ServerPipelineHook.class);
   183         if (hook != null) {
   184             ServerPipeAssemblerContext ctxt = new ServerPipeAssemblerContext(seiModel, wsdlModel, endpoint, terminal, isSynchronous);
   185             return PipeAdapter.adapt(hook.createSecurityPipe(ctxt, PipeAdapter.adapt(next)));
   186         }
   187         return next;
   188     }
   190     /**
   191      * creates a {@link Tube} that dumps messages that pass through.
   192      */
   193     public Tube createDumpTube(String name, PrintStream out, Tube next) {
   194         return new DumpTube(name, out, next);
   195     }
   197     /**
   198      * creates a {@link Tube} that validates messages against schema
   199      */
   200     public Tube createValidationTube(Tube next) {
   201         if (binding instanceof SOAPBinding && binding.isFeatureEnabled(SchemaValidationFeature.class) && wsdlModel!=null)
   202             return new ServerSchemaValidationTube(endpoint, binding, seiModel, wsdlModel, next);
   203         else
   204             return next;
   205     }
   207     /**
   208      * Creates WS-Addressing pipe
   209      */
   210     public Tube createWsaTube(Tube next) {
   211         if (binding instanceof SOAPBinding && AddressingVersion.isEnabled(binding)) {
   212             if(AddressingVersion.fromBinding(binding) == AddressingVersion.MEMBER) {
   213                 return new MemberSubmissionWsaServerTube(endpoint, wsdlModel, binding, next);
   214             } else {
   215                 return new W3CWsaServerTube(endpoint, wsdlModel, binding, next);
   216             }
   217         } else
   218             return next;
   219     }
   221     /**
   222      * Gets the {@link Codec} that is set by {@link #setCodec} or the default codec
   223      * based on the binding. The codec is a full codec that is responsible for
   224      * encoding/decoding entire protocol message(for e.g: it is responsible to
   225      * encode/decode entire MIME messages in SOAP binding)
   226      *
   227      * @return codec to be used for web service requests
   228      * @see Codecs
   229      */
   230     public @NotNull Codec getCodec() {
   231         return codec;
   232     }
   234     /**
   235      * Interception point to change {@link Codec} during {@link Tube}line assembly. The
   236      * new codec will be used by jax-ws server runtime for encoding/decoding web service
   237      * request/response messages. {@link WSEndpoint#createCodec()} will return a copy
   238      * of this new codec and will be used in the server runtime.
   239      *
   240      * <p>
   241      * The codec is a full codec that is responsible for
   242      * encoding/decoding entire protocol message(for e.g: it is responsible to
   243      * encode/decode entire MIME messages in SOAP binding)
   244      *
   245      * <p>
   246      * the codec should correctly implement {@link Codec#copy} since it is used while
   247      * serving requests concurrently.
   248      *
   249      * @param codec codec to be used for web service requests
   250      * @see Codecs
   251      */
   252     public void setCodec(@NotNull Codec codec) {
   253         this.codec = codec;
   254     }
   256 }

mercurial