Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
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.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;
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 import java.util.Map.Entry;
50 /**
51 * @author Rama Pulavarthi
52 */
53 public class ClientMessageHandlerTube extends HandlerTube {
54 private SEIModel seiModel;
55 private Set<String> roles;
57 /**
58 * Creates a new instance of MessageHandlerTube
59 */
60 public ClientMessageHandlerTube(@Nullable SEIModel seiModel, WSBinding binding, WSDLPort port, Tube next) {
61 super(next, port, binding);
62 this.seiModel = seiModel;
63 }
65 /**
66 * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
67 */
68 private ClientMessageHandlerTube(ClientMessageHandlerTube that, TubeCloner cloner) {
69 super(that, cloner);
70 this.seiModel = that.seiModel;
71 }
73 public AbstractFilterTubeImpl copy(TubeCloner cloner) {
74 return new ClientMessageHandlerTube(this, cloner);
75 }
77 void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
78 try {
79 //CLIENT-SIDE
80 processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
82 } catch (WebServiceException wse) {
83 //no rewrapping
84 throw wse;
85 } catch (RuntimeException re) {
86 throw new WebServiceException(re);
87 }
88 }
90 boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
91 boolean handlerResult;
93 //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
94 Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
95 AttachmentSet attSet = context.packet.getMessage().getAttachments();
96 for (Entry<String, DataHandler> entry : atts.entrySet()) {
97 String cid = entry.getKey();
98 if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
99 Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
100 attSet.add(att);
101 }
102 }
104 try {
105 //CLIENT-SIDE
106 handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
107 } catch (WebServiceException wse) {
108 remedyActionTaken = true;
109 //no rewrapping
110 throw wse;
111 } catch (RuntimeException re) {
112 remedyActionTaken = true;
114 throw new WebServiceException(re);
116 }
117 if (!handlerResult) {
118 remedyActionTaken = true;
119 }
120 return handlerResult;
121 }
123 void closeHandlers(MessageContext mc) {
124 closeClientsideHandlers(mc);
126 }
128 void setUpProcessor() {
129 if (handlers == null) {
130 // Take a snapshot, User may change chain after invocation, Same chain
131 // should be used for the entire MEP
132 handlers = new ArrayList<Handler>();
133 HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
134 List<MessageHandler> msgHandlersSnapShot= handlerConfig.getMessageHandlers();
135 if (!msgHandlersSnapShot.isEmpty()) {
136 handlers.addAll(msgHandlersSnapShot);
137 roles = new HashSet<String>();
138 roles.addAll(handlerConfig.getRoles());
139 processor = new SOAPHandlerProcessor(true, this, getBinding(), handlers);
140 }
141 }
142 }
146 MessageUpdatableContext getContext(Packet p) {
147 MessageHandlerContextImpl context = new MessageHandlerContextImpl(seiModel, getBinding(), port, p, roles);
148 return context;
149 }
152 }