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