Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
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.handler.MessageHandler;
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.message.Packet;
33 import com.sun.xml.internal.ws.api.model.SEIModel;
34 import com.sun.xml.internal.ws.api.pipe.Tube;
35 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
36 import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
37 import com.sun.xml.internal.ws.binding.BindingImpl;
38 import com.sun.xml.internal.ws.client.HandlerConfiguration;
39 import com.sun.xml.internal.ws.message.DataHandlerAttachment;
41 import javax.activation.DataHandler;
42 import javax.xml.ws.WebServiceException;
43 import javax.xml.ws.handler.MessageContext;
44 import javax.xml.ws.handler.Handler;
45 import java.util.*;
46 import java.util.Map.Entry;
48 /**
49 * @author Rama Pulavarthi
50 */
51 public class ServerMessageHandlerTube extends HandlerTube{
52 private SEIModel seiModel;
53 private Set<String> roles;
55 public ServerMessageHandlerTube(SEIModel seiModel, WSBinding binding, Tube next, HandlerTube cousinTube) {
56 super(next, cousinTube, binding);
57 this.seiModel = seiModel;
58 setUpHandlersOnce();
59 }
61 /**
62 * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
63 */
64 private ServerMessageHandlerTube(ServerMessageHandlerTube that, TubeCloner cloner) {
65 super(that, cloner);
66 this.seiModel = that.seiModel;
67 this.handlers = that.handlers;
68 this.roles = that.roles;
69 }
71 private void setUpHandlersOnce() {
72 handlers = new ArrayList<Handler>();
73 HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
74 List<MessageHandler> msgHandlersSnapShot= handlerConfig.getMessageHandlers();
75 if (!msgHandlersSnapShot.isEmpty()) {
76 handlers.addAll(msgHandlersSnapShot);
77 roles = new HashSet<String>();
78 roles.addAll(handlerConfig.getRoles());
79 }
80 }
82 void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
83 //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
84 Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
85 AttachmentSet attSet = context.packet.getMessage().getAttachments();
86 for (Entry<String, DataHandler> entry : atts.entrySet()) {
87 String cid = entry.getKey();
88 if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
89 Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
90 attSet.add(att);
91 }
92 }
94 try {
95 //SERVER-SIDE
96 processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);
98 } catch (WebServiceException wse) {
99 //no rewrapping
100 throw wse;
101 } catch (RuntimeException re) {
102 throw re;
104 }
105 }
107 boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
108 boolean handlerResult;
109 try {
110 //SERVER-SIDE
111 handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.INBOUND, context, !isOneWay);
113 } catch (RuntimeException re) {
114 remedyActionTaken = true;
115 throw re;
117 }
118 if (!handlerResult) {
119 remedyActionTaken = true;
120 }
121 return handlerResult;
122 }
124 protected void resetProcessor() {
125 processor = null;
126 }
128 void setUpProcessor() {
129 if(!handlers.isEmpty() && processor == null) {
130 processor = new SOAPHandlerProcessor(false, this, getBinding(), handlers);
131 }
132 }
134 void closeHandlers(MessageContext mc) {
135 closeServersideHandlers(mc);
137 }
138 MessageUpdatableContext getContext(Packet packet) {
139 MessageHandlerContextImpl context = new MessageHandlerContextImpl(seiModel, getBinding(), port, packet, roles);
140 return context;
141 }
143 //should be overridden by DriverHandlerTubes
144 @Override
145 protected void initiateClosing(MessageContext mc) {
146 close(mc);
147 super.initiateClosing(mc);
148 }
150 public AbstractFilterTubeImpl copy(TubeCloner cloner) {
151 return new ServerMessageHandlerTube(this, cloner);
152 }
153 }