|
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 */ |
|
25 |
|
26 package com.sun.xml.internal.ws.handler; |
|
27 |
|
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.api.model.SEIModel; |
|
37 import com.sun.xml.internal.ws.binding.BindingImpl; |
|
38 import com.sun.xml.internal.ws.message.DataHandlerAttachment; |
|
39 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; |
|
40 import com.sun.xml.internal.ws.spi.db.BindingContext; |
|
41 |
|
42 import javax.xml.ws.handler.LogicalHandler; |
|
43 import javax.xml.ws.handler.MessageContext; |
|
44 import javax.xml.ws.handler.Handler; |
|
45 import javax.xml.ws.WebServiceException; |
|
46 import javax.activation.DataHandler; |
|
47 import java.util.List; |
|
48 import java.util.ArrayList; |
|
49 import java.util.Map; |
|
50 import java.util.Map.Entry; |
|
51 |
|
52 /** |
|
53 * |
|
54 * @author WS Development Team |
|
55 */ |
|
56 public class ServerLogicalHandlerTube extends HandlerTube { |
|
57 |
|
58 private SEIModel seiModel; |
|
59 |
|
60 /** |
|
61 * Creates a new instance of LogicalHandlerTube |
|
62 */ |
|
63 public ServerLogicalHandlerTube(WSBinding binding, SEIModel seiModel, WSDLPort port, Tube next) { |
|
64 super(next, port, binding); |
|
65 this.seiModel = seiModel; |
|
66 setUpHandlersOnce(); |
|
67 } |
|
68 |
|
69 /** |
|
70 * This constructor is used on client-side where, SOAPHandlerTube is created |
|
71 * first and then a LogicalHandlerTube is created with a handler to that |
|
72 * SOAPHandlerTube. |
|
73 * With this handle, LogicalHandlerTube can call |
|
74 * SOAPHandlerTube.closeHandlers() |
|
75 */ |
|
76 public ServerLogicalHandlerTube(WSBinding binding, SEIModel seiModel, Tube next, HandlerTube cousinTube) { |
|
77 super(next, cousinTube, binding); |
|
78 this.seiModel = seiModel; |
|
79 setUpHandlersOnce(); |
|
80 } |
|
81 |
|
82 /** |
|
83 * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}. |
|
84 */ |
|
85 |
|
86 private ServerLogicalHandlerTube(ServerLogicalHandlerTube that, TubeCloner cloner) { |
|
87 super(that, cloner); |
|
88 this.seiModel = that.seiModel; |
|
89 this.handlers = that.handlers; |
|
90 } |
|
91 |
|
92 //should be overridden by DriverHandlerTubes |
|
93 @Override |
|
94 protected void initiateClosing(MessageContext mc) { |
|
95 if (getBinding().getSOAPVersion() != null) { |
|
96 super.initiateClosing(mc); |
|
97 } else { |
|
98 close(mc); |
|
99 super.initiateClosing(mc); |
|
100 } |
|
101 } |
|
102 |
|
103 public AbstractFilterTubeImpl copy(TubeCloner cloner) { |
|
104 return new ServerLogicalHandlerTube(this, cloner); |
|
105 } |
|
106 |
|
107 private void setUpHandlersOnce() { |
|
108 handlers = new ArrayList<Handler>(); |
|
109 List<LogicalHandler> logicalSnapShot= ((BindingImpl) getBinding()).getHandlerConfig().getLogicalHandlers(); |
|
110 if (!logicalSnapShot.isEmpty()) { |
|
111 handlers.addAll(logicalSnapShot); |
|
112 } |
|
113 } |
|
114 |
|
115 protected void resetProcessor() { |
|
116 processor = null; |
|
117 } |
|
118 |
|
119 void setUpProcessor() { |
|
120 if (!handlers.isEmpty() && processor == null) { |
|
121 if (getBinding().getSOAPVersion() == null) { |
|
122 processor = new XMLHandlerProcessor(this, getBinding(), |
|
123 handlers); |
|
124 } else { |
|
125 processor = new SOAPHandlerProcessor(false, this, getBinding(), handlers); |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 MessageUpdatableContext getContext(Packet packet) { |
|
131 return new LogicalMessageContextImpl(getBinding(), getBindingContext(), packet); |
|
132 } |
|
133 |
|
134 private BindingContext getBindingContext() { |
|
135 return (seiModel!= null && seiModel instanceof AbstractSEIModelImpl) ? |
|
136 ((AbstractSEIModelImpl)seiModel).getBindingContext() : null; |
|
137 } |
|
138 |
|
139 boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) { |
|
140 |
|
141 boolean handlerResult; |
|
142 try { |
|
143 //SERVER-SIDE |
|
144 handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.INBOUND, context, !isOneWay); |
|
145 |
|
146 } catch (RuntimeException re) { |
|
147 remedyActionTaken = true; |
|
148 throw re; |
|
149 } |
|
150 if (!handlerResult) { |
|
151 remedyActionTaken = true; |
|
152 } |
|
153 return handlerResult; |
|
154 } |
|
155 |
|
156 void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) { |
|
157 //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message |
|
158 Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS); |
|
159 AttachmentSet attSet = context.packet.getMessage().getAttachments(); |
|
160 for (Entry<String, DataHandler> entry : atts.entrySet()) { |
|
161 String cid = entry.getKey(); |
|
162 Attachment att = new DataHandlerAttachment(cid, atts.get(cid)); |
|
163 attSet.add(att); |
|
164 } |
|
165 |
|
166 try { |
|
167 //SERVER-SIDE |
|
168 processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault); |
|
169 |
|
170 } catch (WebServiceException wse) { |
|
171 //no rewrapping |
|
172 throw wse; |
|
173 } catch (RuntimeException re) { |
|
174 throw re; |
|
175 } |
|
176 } |
|
177 |
|
178 void closeHandlers(MessageContext mc) { |
|
179 closeServersideHandlers(mc); |
|
180 |
|
181 } |
|
182 } |