src/share/jaxws_classes/com/sun/xml/internal/ws/handler/ServerLogicalHandlerTube.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/handler/ServerLogicalHandlerTube.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,180 @@
     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.handler;
    1.30 +
    1.31 +import com.sun.xml.internal.ws.api.WSBinding;
    1.32 +import com.sun.xml.internal.ws.api.message.Packet;
    1.33 +import com.sun.xml.internal.ws.api.message.AttachmentSet;
    1.34 +import com.sun.xml.internal.ws.api.message.Attachment;
    1.35 +import com.sun.xml.internal.ws.api.pipe.TubeCloner;
    1.36 +import com.sun.xml.internal.ws.api.pipe.Tube;
    1.37 +import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
    1.38 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.39 +import com.sun.xml.internal.ws.api.model.SEIModel;
    1.40 +import com.sun.xml.internal.ws.binding.BindingImpl;
    1.41 +import com.sun.xml.internal.ws.message.DataHandlerAttachment;
    1.42 +import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
    1.43 +import com.sun.xml.internal.ws.spi.db.BindingContext;
    1.44 +
    1.45 +import javax.xml.ws.handler.LogicalHandler;
    1.46 +import javax.xml.ws.handler.MessageContext;
    1.47 +import javax.xml.ws.handler.Handler;
    1.48 +import javax.xml.ws.WebServiceException;
    1.49 +import javax.activation.DataHandler;
    1.50 +import java.util.List;
    1.51 +import java.util.ArrayList;
    1.52 +import java.util.Map;
    1.53 +
    1.54 +/**
    1.55 + *
    1.56 + * @author WS Development Team
    1.57 + */
    1.58 +public class ServerLogicalHandlerTube extends HandlerTube {
    1.59 +
    1.60 +    private SEIModel seiModel;
    1.61 +
    1.62 +    /**
    1.63 +     * Creates a new instance of LogicalHandlerTube
    1.64 +     */
    1.65 +    public ServerLogicalHandlerTube(WSBinding binding, SEIModel seiModel, WSDLPort port, Tube next) {
    1.66 +        super(next, port, binding);
    1.67 +        this.seiModel = seiModel;
    1.68 +        setUpHandlersOnce();
    1.69 +    }
    1.70 +
    1.71 +    /**
    1.72 +     * This constructor is used on client-side where, SOAPHandlerTube is created
    1.73 +     * first and then a LogicalHandlerTube is created with a handler to that
    1.74 +     * SOAPHandlerTube.
    1.75 +     * With this handle, LogicalHandlerTube can call
    1.76 +     * SOAPHandlerTube.closeHandlers()
    1.77 +     */
    1.78 +    public ServerLogicalHandlerTube(WSBinding binding, SEIModel seiModel, Tube next, HandlerTube cousinTube) {
    1.79 +        super(next, cousinTube, binding);
    1.80 +        this.seiModel = seiModel;
    1.81 +        setUpHandlersOnce();
    1.82 +    }
    1.83 +
    1.84 +    /**
    1.85 +     * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
    1.86 +     */
    1.87 +
    1.88 +    private ServerLogicalHandlerTube(ServerLogicalHandlerTube that, TubeCloner cloner) {
    1.89 +        super(that, cloner);
    1.90 +        this.seiModel = that.seiModel;
    1.91 +        this.handlers = that.handlers;
    1.92 +    }
    1.93 +
    1.94 +    //should be overridden by DriverHandlerTubes
    1.95 +    @Override
    1.96 +    protected void initiateClosing(MessageContext mc) {
    1.97 +         if (getBinding().getSOAPVersion() != null) {
    1.98 +            super.initiateClosing(mc);
    1.99 +        } else {
   1.100 +            close(mc);
   1.101 +            super.initiateClosing(mc);
   1.102 +        }
   1.103 +    }
   1.104 +
   1.105 +   public AbstractFilterTubeImpl copy(TubeCloner cloner) {
   1.106 +        return new ServerLogicalHandlerTube(this, cloner);
   1.107 +    }
   1.108 +
   1.109 +    private void setUpHandlersOnce() {
   1.110 +        handlers = new ArrayList<Handler>();
   1.111 +        List<LogicalHandler> logicalSnapShot= ((BindingImpl) getBinding()).getHandlerConfig().getLogicalHandlers();
   1.112 +        if (!logicalSnapShot.isEmpty()) {
   1.113 +            handlers.addAll(logicalSnapShot);
   1.114 +        }
   1.115 +    }
   1.116 +
   1.117 +    protected void resetProcessor() {
   1.118 +        processor = null;
   1.119 +    }
   1.120 +
   1.121 +    void setUpProcessor() {
   1.122 +        if (!handlers.isEmpty() && processor == null) {
   1.123 +            if (getBinding().getSOAPVersion() == null) {
   1.124 +                processor = new XMLHandlerProcessor(this, getBinding(),
   1.125 +                        handlers);
   1.126 +            } else {
   1.127 +                processor = new SOAPHandlerProcessor(false, this, getBinding(), handlers);
   1.128 +            }
   1.129 +        }
   1.130 +    }
   1.131 +
   1.132 +    MessageUpdatableContext getContext(Packet packet) {
   1.133 +        return new LogicalMessageContextImpl(getBinding(), getBindingContext(), packet);
   1.134 +    }
   1.135 +
   1.136 +    private BindingContext getBindingContext() {
   1.137 +        return (seiModel!= null && seiModel instanceof AbstractSEIModelImpl) ?
   1.138 +                ((AbstractSEIModelImpl)seiModel).getBindingContext() : null;
   1.139 +        }
   1.140 +
   1.141 +    boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
   1.142 +
   1.143 +        boolean handlerResult;
   1.144 +        try {
   1.145 +            //SERVER-SIDE
   1.146 +            handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.INBOUND, context, !isOneWay);
   1.147 +
   1.148 +        } catch (RuntimeException re) {
   1.149 +            remedyActionTaken = true;
   1.150 +            throw re;
   1.151 +        }
   1.152 +        if (!handlerResult) {
   1.153 +            remedyActionTaken = true;
   1.154 +        }
   1.155 +        return handlerResult;
   1.156 +    }
   1.157 +
   1.158 +    void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
   1.159 +        //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
   1.160 +        Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
   1.161 +        AttachmentSet attSet = context.packet.getMessage().getAttachments();
   1.162 +        for(String cid : atts.keySet()){
   1.163 +            Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
   1.164 +            attSet.add(att);
   1.165 +        }
   1.166 +
   1.167 +        try {
   1.168 +            //SERVER-SIDE
   1.169 +            processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);
   1.170 +
   1.171 +        } catch (WebServiceException wse) {
   1.172 +            //no rewrapping
   1.173 +            throw wse;
   1.174 +        } catch (RuntimeException re) {
   1.175 +            throw re;
   1.176 +        }
   1.177 +    }
   1.178 +
   1.179 +    void closeHandlers(MessageContext mc) {
   1.180 +        closeServersideHandlers(mc);
   1.181 +
   1.182 +    }
   1.183 +}

mercurial