src/share/jaxws_classes/com/sun/xml/internal/ws/handler/ClientSOAPHandlerTube.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
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.Attachment;
31 import com.sun.xml.internal.ws.api.message.AttachmentSet;
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;
39
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.*;
46
47 /**
48 *
49 * @author WS Development Team
50 */
51 public class ClientSOAPHandlerTube extends HandlerTube {
52
53 private Set<String> roles;
54
55 /**
56 * Creates a new instance of SOAPHandlerTube
57 */
58 public ClientSOAPHandlerTube(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 }
65
66 // Handle to LogicalHandlerTube means its used on SERVER-SIDE
67
68 /**
69 * This constructor is used on client-side where, LogicalHandlerTube is created
70 * first and then a SOAPHandlerTube is created with a handler to that
71 * LogicalHandlerTube.
72 * With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
73 */
74 public ClientSOAPHandlerTube(WSBinding binding, Tube next, HandlerTube cousinTube) {
75 super(next, cousinTube, binding);
76 }
77
78 /**
79 * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
80 */
81 private ClientSOAPHandlerTube(ClientSOAPHandlerTube that, TubeCloner cloner) {
82 super(that, cloner);
83 }
84
85 public AbstractFilterTubeImpl copy(TubeCloner cloner) {
86 return new ClientSOAPHandlerTube(this, cloner);
87 }
88
89 void setUpProcessor() {
90 if (handlers == null) {
91 // Take a snapshot, User may change chain after invocation, Same chain
92 // should be used for the entire MEP
93 handlers = new ArrayList<Handler>();
94 HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
95 List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers();
96 if (!soapSnapShot.isEmpty()) {
97 handlers.addAll(soapSnapShot);
98 roles = new HashSet<String>();
99 roles.addAll(handlerConfig.getRoles());
100 processor = new SOAPHandlerProcessor(true, this, getBinding(), handlers);
101 }
102 }
103 }
104
105 MessageUpdatableContext getContext(Packet packet) {
106 SOAPMessageContextImpl context = new SOAPMessageContextImpl(getBinding(), packet,roles);
107 return context;
108 }
109
110 boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
111
112 boolean handlerResult;
113 //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
114 Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
115 AttachmentSet attSet = context.packet.getMessage().getAttachments();
116 for(String cid : atts.keySet()){
117 if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
118 Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
119 attSet.add(att);
120 }
121 }
122
123 try {
124 //CLIENT-SIDE
125 handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
126 } catch (WebServiceException wse) {
127 remedyActionTaken = true;
128 //no rewrapping
129 throw wse;
130 } catch (RuntimeException re) {
131 remedyActionTaken = true;
132
133 throw new WebServiceException(re);
134
135 }
136 if (!handlerResult) {
137 remedyActionTaken = true;
138 }
139 return handlerResult;
140 }
141
142 void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
143 try {
144
145 //CLIENT-SIDE
146 processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
147
148 } catch (WebServiceException wse) {
149 //no rewrapping
150 throw wse;
151 } catch (RuntimeException re) {
152 throw new WebServiceException(re);
153 }
154 }
155
156 void closeHandlers(MessageContext mc) {
157 closeClientsideHandlers(mc);
158
159 }
160 }

mercurial