src/share/jaxws_classes/com/sun/xml/internal/ws/handler/ClientMessageHandlerTube.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.istack.internal.Nullable;
29 import com.sun.xml.internal.ws.api.WSBinding;
30 import com.sun.xml.internal.ws.api.handler.MessageHandler;
31 import com.sun.xml.internal.ws.api.message.Attachment;
32 import com.sun.xml.internal.ws.api.message.AttachmentSet;
33 import com.sun.xml.internal.ws.api.message.Packet;
34 import com.sun.xml.internal.ws.api.model.SEIModel;
35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
36 import com.sun.xml.internal.ws.api.pipe.Tube;
37 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
38 import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
39 import com.sun.xml.internal.ws.binding.BindingImpl;
40 import com.sun.xml.internal.ws.client.HandlerConfiguration;
41 import com.sun.xml.internal.ws.message.DataHandlerAttachment;
42
43 import javax.activation.DataHandler;
44 import javax.xml.ws.WebServiceException;
45 import javax.xml.ws.handler.MessageContext;
46 import javax.xml.ws.handler.Handler;
47 import java.util.*;
48
49 /**
50 * @author Rama Pulavarthi
51 */
52 public class ClientMessageHandlerTube extends HandlerTube {
53 private SEIModel seiModel;
54 private Set<String> roles;
55
56 /**
57 * Creates a new instance of MessageHandlerTube
58 */
59 public ClientMessageHandlerTube(@Nullable SEIModel seiModel, WSBinding binding, WSDLPort port, Tube next) {
60 super(next, port, binding);
61 this.seiModel = seiModel;
62 }
63
64 /**
65 * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
66 */
67 private ClientMessageHandlerTube(ClientMessageHandlerTube that, TubeCloner cloner) {
68 super(that, cloner);
69 this.seiModel = that.seiModel;
70 }
71
72 public AbstractFilterTubeImpl copy(TubeCloner cloner) {
73 return new ClientMessageHandlerTube(this, cloner);
74 }
75
76 void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
77 try {
78 //CLIENT-SIDE
79 processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
80
81 } catch (WebServiceException wse) {
82 //no rewrapping
83 throw wse;
84 } catch (RuntimeException re) {
85 throw new WebServiceException(re);
86 }
87 }
88
89 boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
90 boolean handlerResult;
91
92 //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
93 Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
94 AttachmentSet attSet = context.packet.getMessage().getAttachments();
95 for(String cid : atts.keySet()){
96 if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
97 Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
98 attSet.add(att);
99 }
100 }
101
102 try {
103 //CLIENT-SIDE
104 handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
105 } catch (WebServiceException wse) {
106 remedyActionTaken = true;
107 //no rewrapping
108 throw wse;
109 } catch (RuntimeException re) {
110 remedyActionTaken = true;
111
112 throw new WebServiceException(re);
113
114 }
115 if (!handlerResult) {
116 remedyActionTaken = true;
117 }
118 return handlerResult;
119 }
120
121 void closeHandlers(MessageContext mc) {
122 closeClientsideHandlers(mc);
123
124 }
125
126 void setUpProcessor() {
127 if (handlers == null) {
128 // Take a snapshot, User may change chain after invocation, Same chain
129 // should be used for the entire MEP
130 handlers = new ArrayList<Handler>();
131 HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
132 List<MessageHandler> msgHandlersSnapShot= handlerConfig.getMessageHandlers();
133 if (!msgHandlersSnapShot.isEmpty()) {
134 handlers.addAll(msgHandlersSnapShot);
135 roles = new HashSet<String>();
136 roles.addAll(handlerConfig.getRoles());
137 processor = new SOAPHandlerProcessor(true, this, getBinding(), handlers);
138 }
139 }
140 }
141
142
143
144 MessageUpdatableContext getContext(Packet p) {
145 MessageHandlerContextImpl context = new MessageHandlerContextImpl(seiModel, getBinding(), port, p, roles);
146 return context;
147 }
148
149
150 }

mercurial