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/ClientSOAPHandlerTube.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,160 @@ 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.Attachment; 1.34 +import com.sun.xml.internal.ws.api.message.AttachmentSet; 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.client.HandlerConfiguration; 1.40 +import com.sun.xml.internal.ws.binding.BindingImpl; 1.41 +import com.sun.xml.internal.ws.message.DataHandlerAttachment; 1.42 + 1.43 +import javax.xml.ws.handler.soap.SOAPHandler; 1.44 +import javax.xml.ws.handler.MessageContext; 1.45 +import javax.xml.ws.handler.Handler; 1.46 +import javax.xml.ws.WebServiceException; 1.47 +import javax.activation.DataHandler; 1.48 +import java.util.*; 1.49 + 1.50 +/** 1.51 + * 1.52 + * @author WS Development Team 1.53 + */ 1.54 +public class ClientSOAPHandlerTube extends HandlerTube { 1.55 + 1.56 + private Set<String> roles; 1.57 + 1.58 + /** 1.59 + * Creates a new instance of SOAPHandlerTube 1.60 + */ 1.61 + public ClientSOAPHandlerTube(WSBinding binding, WSDLPort port, Tube next) { 1.62 + super(next, port, binding); 1.63 + if (binding.getSOAPVersion() != null) { 1.64 + // SOAPHandlerTube should n't be used for bindings other than SOAP. 1.65 + // TODO: throw Exception 1.66 + } 1.67 + } 1.68 + 1.69 + // Handle to LogicalHandlerTube means its used on SERVER-SIDE 1.70 + 1.71 + /** 1.72 + * This constructor is used on client-side where, LogicalHandlerTube is created 1.73 + * first and then a SOAPHandlerTube is created with a handler to that 1.74 + * LogicalHandlerTube. 1.75 + * With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers() 1.76 + */ 1.77 + public ClientSOAPHandlerTube(WSBinding binding, Tube next, HandlerTube cousinTube) { 1.78 + super(next, cousinTube, binding); 1.79 + } 1.80 + 1.81 + /** 1.82 + * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}. 1.83 + */ 1.84 + private ClientSOAPHandlerTube(ClientSOAPHandlerTube that, TubeCloner cloner) { 1.85 + super(that, cloner); 1.86 + } 1.87 + 1.88 + public AbstractFilterTubeImpl copy(TubeCloner cloner) { 1.89 + return new ClientSOAPHandlerTube(this, cloner); 1.90 + } 1.91 + 1.92 + void setUpProcessor() { 1.93 + if (handlers == null) { 1.94 + // Take a snapshot, User may change chain after invocation, Same chain 1.95 + // should be used for the entire MEP 1.96 + handlers = new ArrayList<Handler>(); 1.97 + HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig(); 1.98 + List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers(); 1.99 + if (!soapSnapShot.isEmpty()) { 1.100 + handlers.addAll(soapSnapShot); 1.101 + roles = new HashSet<String>(); 1.102 + roles.addAll(handlerConfig.getRoles()); 1.103 + processor = new SOAPHandlerProcessor(true, this, getBinding(), handlers); 1.104 + } 1.105 + } 1.106 + } 1.107 + 1.108 + MessageUpdatableContext getContext(Packet packet) { 1.109 + SOAPMessageContextImpl context = new SOAPMessageContextImpl(getBinding(), packet,roles); 1.110 + return context; 1.111 + } 1.112 + 1.113 + boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) { 1.114 + 1.115 + boolean handlerResult; 1.116 + //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message 1.117 + Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS); 1.118 + AttachmentSet attSet = context.packet.getMessage().getAttachments(); 1.119 + for(String cid : atts.keySet()){ 1.120 + if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice 1.121 + Attachment att = new DataHandlerAttachment(cid, atts.get(cid)); 1.122 + attSet.add(att); 1.123 + } 1.124 + } 1.125 + 1.126 + try { 1.127 + //CLIENT-SIDE 1.128 + handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay); 1.129 + } catch (WebServiceException wse) { 1.130 + remedyActionTaken = true; 1.131 + //no rewrapping 1.132 + throw wse; 1.133 + } catch (RuntimeException re) { 1.134 + remedyActionTaken = true; 1.135 + 1.136 + throw new WebServiceException(re); 1.137 + 1.138 + } 1.139 + if (!handlerResult) { 1.140 + remedyActionTaken = true; 1.141 + } 1.142 + return handlerResult; 1.143 + } 1.144 + 1.145 + void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) { 1.146 + try { 1.147 + 1.148 + //CLIENT-SIDE 1.149 + processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault); 1.150 + 1.151 + } catch (WebServiceException wse) { 1.152 + //no rewrapping 1.153 + throw wse; 1.154 + } catch (RuntimeException re) { 1.155 + throw new WebServiceException(re); 1.156 + } 1.157 + } 1.158 + 1.159 + void closeHandlers(MessageContext mc) { 1.160 + closeClientsideHandlers(mc); 1.161 + 1.162 + } 1.163 +}