325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.api.pipe;
325N/A
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.istack.internal.Nullable;
325N/Aimport com.sun.xml.internal.ws.addressing.W3CWsaServerTube;
325N/Aimport com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionWsaServerTube;
325N/Aimport com.sun.xml.internal.ws.api.addressing.AddressingVersion;
325N/Aimport com.sun.xml.internal.ws.api.model.SEIModel;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
325N/Aimport com.sun.xml.internal.ws.api.pipe.helper.PipeAdapter;
325N/Aimport com.sun.xml.internal.ws.api.server.ServerPipelineHook;
325N/Aimport com.sun.xml.internal.ws.api.server.WSEndpoint;
325N/Aimport com.sun.xml.internal.ws.binding.BindingImpl;
325N/Aimport com.sun.xml.internal.ws.developer.SchemaValidationFeature;
325N/Aimport com.sun.xml.internal.ws.handler.HandlerTube;
325N/Aimport com.sun.xml.internal.ws.handler.ServerLogicalHandlerTube;
325N/Aimport com.sun.xml.internal.ws.handler.ServerMessageHandlerTube;
325N/Aimport com.sun.xml.internal.ws.handler.ServerSOAPHandlerTube;
325N/Aimport com.sun.xml.internal.ws.protocol.soap.ServerMUTube;
325N/Aimport com.sun.xml.internal.ws.server.ServerSchemaValidationTube;
325N/Aimport com.sun.xml.internal.ws.util.pipe.DumpTube;
325N/A
325N/Aimport javax.xml.ws.soap.SOAPBinding;
325N/Aimport java.io.PrintStream;
325N/A
325N/A/**
325N/A * Factory for well-known server {@link Tube} implementations
325N/A * that the {@link TubelineAssembler} needs to use
325N/A * to satisfy JAX-WS requirements.
325N/A *
325N/A * @author Jitendra Kotamraju
325N/A */
325N/Apublic class ServerTubeAssemblerContext {
325N/A
325N/A private final SEIModel seiModel;
325N/A private final WSDLPort wsdlModel;
325N/A private final WSEndpoint endpoint;
325N/A private final BindingImpl binding;
325N/A private final Tube terminal;
325N/A private final boolean isSynchronous;
325N/A private @NotNull Codec codec;
325N/A
325N/A public ServerTubeAssemblerContext(@Nullable SEIModel seiModel,
325N/A @Nullable WSDLPort wsdlModel, @NotNull WSEndpoint endpoint,
325N/A @NotNull Tube terminal, boolean isSynchronous) {
325N/A this.seiModel = seiModel;
325N/A this.wsdlModel = wsdlModel;
325N/A this.endpoint = endpoint;
325N/A this.terminal = terminal;
325N/A // WSBinding is actually BindingImpl
325N/A this.binding = (BindingImpl)endpoint.getBinding();
325N/A this.isSynchronous = isSynchronous;
325N/A this.codec = this.binding.createCodec();
325N/A }
325N/A
325N/A /**
325N/A * The created pipeline will use seiModel to get java concepts for the endpoint
325N/A *
325N/A * @return Null if the service doesn't have SEI model e.g. Provider endpoints,
325N/A * and otherwise non-null.
325N/A */
325N/A public @Nullable SEIModel getSEIModel() {
325N/A return seiModel;
325N/A }
325N/A
325N/A /**
325N/A * The created pipeline will be used to serve this port.
325N/A *
325N/A * @return Null if the service isn't associated with any port definition in WSDL,
325N/A * and otherwise non-null.
325N/A */
325N/A public @Nullable WSDLPort getWsdlModel() {
325N/A return wsdlModel;
325N/A }
325N/A
325N/A /**
325N/A *
325N/A * The created pipeline is used to serve this {@link com.sun.xml.internal.ws.api.server.WSEndpoint}.
325N/A * Specifically, its {@link com.sun.xml.internal.ws.api.WSBinding} should be of interest to many
325N/A * {@link com.sun.xml.internal.ws.api.pipe.Pipe}s.
325N/A * @return Always non-null.
325N/A */
325N/A public @NotNull WSEndpoint getEndpoint() {
325N/A return endpoint;
325N/A }
325N/A
325N/A /**
325N/A * The last {@link com.sun.xml.internal.ws.api.pipe.Pipe} in the pipeline. The assembler is expected to put
325N/A * additional {@link com.sun.xml.internal.ws.api.pipe.Pipe}s in front of it.
325N/A *
325N/A * <p>
325N/A * (Just to give you the idea how this is used, normally the terminal pipe
325N/A * is the one that invokes the user application or {@link javax.xml.ws.Provider}.)
325N/A *
325N/A * @return always non-null terminal pipe
325N/A */
325N/A public @NotNull Tube getTerminalTube() {
325N/A return terminal;
325N/A }
325N/A
325N/A /**
325N/A * If this server pipeline is known to be used for serving synchronous transport,
325N/A * then this method returns true. This can be potentially use as an optimization
325N/A * hint, since often synchronous versions are cheaper to execute than asycnhronous
325N/A * versions.
325N/A */
325N/A public boolean isSynchronous() {
325N/A return isSynchronous;
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link Tube} that performs SOAP mustUnderstand processing.
325N/A * This pipe should be before HandlerPipes.
325N/A */
325N/A public @NotNull Tube createServerMUTube(@NotNull Tube next) {
325N/A if (binding instanceof SOAPBinding)
325N/A return new ServerMUTube(this,next);
325N/A else
325N/A return next;
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link Tube} that invokes protocol and logical handlers.
325N/A */
325N/A public @NotNull Tube createHandlerTube(@NotNull Tube next) {
325N/A if (!binding.getHandlerChain().isEmpty()) {
325N/A HandlerTube cousin = new ServerLogicalHandlerTube(binding, seiModel, wsdlModel, next);
325N/A next = cousin;
325N/A if (binding instanceof SOAPBinding) {
325N/A //Add SOAPHandlerTube
325N/A next = cousin = new ServerSOAPHandlerTube(binding, next, cousin);
325N/A
325N/A //Add MessageHandlerTube
325N/A next = new ServerMessageHandlerTube(seiModel, binding, next, cousin);
325N/A }
325N/A }
325N/A return next;
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link Tube} that does the monitoring of the invocation for a
325N/A * container
325N/A */
325N/A public @NotNull Tube createMonitoringTube(@NotNull Tube next) {
325N/A ServerPipelineHook hook = endpoint.getContainer().getSPI(ServerPipelineHook.class);
325N/A if (hook != null) {
325N/A ServerPipeAssemblerContext ctxt = new ServerPipeAssemblerContext(seiModel, wsdlModel, endpoint, terminal, isSynchronous);
325N/A return PipeAdapter.adapt(hook.createMonitoringPipe(ctxt, PipeAdapter.adapt(next)));
325N/A }
325N/A return next;
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link Tube} that adds container specific security
325N/A */
325N/A public @NotNull Tube createSecurityTube(@NotNull Tube next) {
325N/A ServerPipelineHook hook = endpoint.getContainer().getSPI(ServerPipelineHook.class);
325N/A if (hook != null) {
325N/A ServerPipeAssemblerContext ctxt = new ServerPipeAssemblerContext(seiModel, wsdlModel, endpoint, terminal, isSynchronous);
325N/A return PipeAdapter.adapt(hook.createSecurityPipe(ctxt, PipeAdapter.adapt(next)));
325N/A }
325N/A return next;
325N/A }
325N/A
325N/A /**
325N/A * creates a {@link Tube} that dumps messages that pass through.
325N/A */
325N/A public Tube createDumpTube(String name, PrintStream out, Tube next) {
325N/A return new DumpTube(name, out, next);
325N/A }
325N/A
325N/A /**
325N/A * creates a {@link Tube} that validates messages against schema
325N/A */
325N/A public Tube createValidationTube(Tube next) {
325N/A if (binding instanceof SOAPBinding && binding.isFeatureEnabled(SchemaValidationFeature.class) && wsdlModel!=null)
325N/A return new ServerSchemaValidationTube(endpoint, binding, seiModel, wsdlModel, next);
325N/A else
325N/A return next;
325N/A }
325N/A
325N/A /**
325N/A * Creates WS-Addressing pipe
325N/A */
325N/A public Tube createWsaTube(Tube next) {
325N/A if (binding instanceof SOAPBinding && AddressingVersion.isEnabled(binding)) {
325N/A if(AddressingVersion.fromBinding(binding) == AddressingVersion.MEMBER) {
325N/A return new MemberSubmissionWsaServerTube(endpoint, wsdlModel, binding, next);
325N/A } else {
325N/A return new W3CWsaServerTube(endpoint, wsdlModel, binding, next);
325N/A }
325N/A } else
325N/A return next;
325N/A }
325N/A
325N/A /**
325N/A * Gets the {@link Codec} that is set by {@link #setCodec} or the default codec
325N/A * based on the binding. The codec is a full codec that is responsible for
325N/A * encoding/decoding entire protocol message(for e.g: it is responsible to
325N/A * encode/decode entire MIME messages in SOAP binding)
325N/A *
325N/A * @return codec to be used for web service requests
325N/A * @see {@link Codecs}
325N/A */
325N/A public @NotNull Codec getCodec() {
325N/A return codec;
325N/A }
325N/A
325N/A /**
325N/A * Interception point to change {@link Codec} during {@link Tube}line assembly. The
325N/A * new codec will be used by jax-ws server runtime for encoding/decoding web service
325N/A * request/response messages. {@link WSEndpoint#createCodec()} will return a copy
325N/A * of this new codec and will be used in the server runtime.
325N/A *
325N/A * <p>
325N/A * The codec is a full codec that is responsible for
325N/A * encoding/decoding entire protocol message(for e.g: it is responsible to
325N/A * encode/decode entire MIME messages in SOAP binding)
325N/A *
325N/A * <p>
325N/A * the codec should correctly implement {@link Codec#copy} since it is used while
325N/A * serving requests concurrently.
325N/A *
325N/A * @param codec codec to be used for web service requests
325N/A * @see {@link Codecs}
325N/A */
325N/A public void setCodec(@NotNull Codec codec) {
325N/A this.codec = codec;
325N/A }
325N/A
325N/A}