Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
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.handler;
28 import com.sun.xml.internal.ws.api.WSBinding;
29 import com.sun.xml.internal.ws.api.message.Packet;
30 import com.sun.xml.internal.ws.api.message.AttachmentSet;
31 import com.sun.xml.internal.ws.api.message.Attachment;
32 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
33 import com.sun.xml.internal.ws.api.pipe.Tube;
34 import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
36 import com.sun.xml.internal.ws.client.HandlerConfiguration;
37 import com.sun.xml.internal.ws.binding.BindingImpl;
38 import com.sun.xml.internal.ws.message.DataHandlerAttachment;
40 import javax.xml.ws.handler.soap.SOAPHandler;
41 import javax.xml.ws.handler.MessageContext;
42 import javax.xml.ws.handler.Handler;
43 import javax.xml.ws.WebServiceException;
44 import javax.activation.DataHandler;
45 import java.util.*;
47 /**
48 *
49 * @author WS Development Team
50 */
51 public class ServerSOAPHandlerTube extends HandlerTube {
53 private Set<String> roles;
55 /**
56 * Creates a new instance of SOAPHandlerTube
57 */
58 public ServerSOAPHandlerTube(WSBinding binding, WSDLPort port, Tube next) {
59 super(next, port, binding);
60 if (binding.getSOAPVersion() != null) {
61 // SOAPHandlerTube should n't be used for bindings other than SOAP.
62 // TODO: throw Exception
63 }
64 setUpHandlersOnce();
65 }
67 // Handle to LogicalHandlerTube means its used on SERVER-SIDE
69 /**
70 * This constructor is used on client-side where, LogicalHandlerTube is created
71 * first and then a SOAPHandlerTube is created with a handler to that
72 * LogicalHandlerTube.
73 * With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
74 */
75 public ServerSOAPHandlerTube(WSBinding binding, Tube next, HandlerTube cousinTube) {
76 super(next, cousinTube, binding);
77 setUpHandlersOnce();
78 }
80 /**
81 * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
82 */
83 private ServerSOAPHandlerTube(ServerSOAPHandlerTube that, TubeCloner cloner) {
84 super(that, cloner);
85 this.handlers = that.handlers;
86 this.roles = that.roles;
87 }
90 public AbstractFilterTubeImpl copy(TubeCloner cloner) {
91 return new ServerSOAPHandlerTube(this, cloner);
92 }
94 private void setUpHandlersOnce() {
95 handlers = new ArrayList<Handler>();
96 HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
97 List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers();
98 if (!soapSnapShot.isEmpty()) {
99 handlers.addAll(soapSnapShot);
100 roles = new HashSet<String>();
101 roles.addAll(handlerConfig.getRoles());
102 }
103 }
105 protected void resetProcessor() {
106 processor = null;
107 }
109 void setUpProcessor() {
110 if(!handlers.isEmpty() && processor == null)
111 processor = new SOAPHandlerProcessor(false, this, getBinding(), handlers);
112 }
113 MessageUpdatableContext getContext(Packet packet) {
114 SOAPMessageContextImpl context = new SOAPMessageContextImpl(getBinding(), packet,roles);
115 return context;
116 }
118 boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
120 boolean handlerResult;
121 try {
122 //SERVER-SIDE
123 handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.INBOUND, context, !isOneWay);
125 } catch (RuntimeException re) {
126 remedyActionTaken = true;
127 throw re;
129 }
130 if (!handlerResult) {
131 remedyActionTaken = true;
132 }
133 return handlerResult;
134 }
136 void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
138 //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
139 Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
140 AttachmentSet attSet = context.packet.getMessage().getAttachments();
141 for (Map.Entry<String, DataHandler> entry : atts.entrySet()) {
142 String cid = entry.getKey();
143 if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
144 Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
145 attSet.add(att);
146 }
147 }
149 try {
150 //SERVER-SIDE
151 processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);
153 } catch (WebServiceException wse) {
154 //no rewrapping
155 throw wse;
156 } catch (RuntimeException re) {
157 throw re;
159 }
160 }
162 void closeHandlers(MessageContext mc) {
163 closeServersideHandlers(mc);
165 }
166 }