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