1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/handler/MessageContextImpl.java Thu Apr 04 19:05:24 2013 -0700 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/handler/MessageContextImpl.java Tue Apr 09 14:51:13 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -28,7 +28,6 @@ 1.11 import com.sun.xml.internal.ws.api.message.Attachment; 1.12 import com.sun.xml.internal.ws.api.message.AttachmentSet; 1.13 import com.sun.xml.internal.ws.api.message.Packet; 1.14 -import com.sun.xml.internal.ws.util.ReadOnlyPropertyException; 1.15 1.16 import javax.activation.DataHandler; 1.17 import javax.xml.ws.handler.MessageContext; 1.18 @@ -37,29 +36,24 @@ 1.19 import java.util.Map; 1.20 import java.util.Set; 1.21 1.22 + 1.23 /** 1.24 * 1.25 * @author WS Development Team 1.26 */ 1.27 1.28 class MessageContextImpl implements MessageContext { 1.29 - private Map<String,Object> fallbackMap = null; 1.30 - private Set<String> handlerScopeProps; 1.31 - Packet packet; 1.32 + private final Set<String> handlerScopeProps; 1.33 + private final Packet packet; 1.34 + private final Map<String, Object> asMapIncludingInvocationProperties; 1.35 1.36 - 1.37 - void fallback() { 1.38 - if(fallbackMap == null) { 1.39 - fallbackMap = new HashMap<String,Object>(); 1.40 - fallbackMap.putAll(packet.createMapView()); 1.41 - fallbackMap.putAll(packet.invocationProperties); 1.42 - } 1.43 - } 1.44 /** Creates a new instance of MessageContextImpl */ 1.45 public MessageContextImpl(Packet packet) { 1.46 this.packet = packet; 1.47 - handlerScopeProps = packet.getHandlerScopePropertyNames(false); 1.48 + this.asMapIncludingInvocationProperties = packet.asMapIncludingInvocationProperties(); 1.49 + this.handlerScopeProps = packet.getHandlerScopePropertyNames(false); 1.50 } 1.51 + 1.52 protected void updatePacket() { 1.53 throw new UnsupportedOperationException("wrong call"); 1.54 } 1.55 @@ -86,65 +80,32 @@ 1.56 } 1.57 1.58 public int size() { 1.59 - fallback(); 1.60 - return fallbackMap.size(); 1.61 + return asMapIncludingInvocationProperties.size(); 1.62 } 1.63 1.64 public boolean isEmpty() { 1.65 - fallback(); 1.66 - return fallbackMap.isEmpty(); 1.67 + return asMapIncludingInvocationProperties.isEmpty(); 1.68 } 1.69 1.70 public boolean containsKey(Object key) { 1.71 - if(fallbackMap == null) { 1.72 - if(packet.supports(key)) 1.73 - return true; 1.74 - return packet.invocationProperties.containsKey(key); 1.75 - } else { 1.76 - fallback(); 1.77 - return fallbackMap.containsKey(key); 1.78 - } 1.79 + return asMapIncludingInvocationProperties.containsKey(key); 1.80 } 1.81 1.82 public boolean containsValue(Object value) { 1.83 - fallback(); 1.84 - return fallbackMap.containsValue(value); 1.85 + return asMapIncludingInvocationProperties.containsValue(value); 1.86 } 1.87 1.88 public Object put(String key, Object value) { 1.89 - if (fallbackMap == null) { 1.90 - if (packet.supports(key)) { 1.91 - return packet.put(key, value); // strongly typed 1.92 - } 1.93 - if (!packet.invocationProperties.containsKey(key)) { 1.94 - //New property, default to Scope.HANDLER 1.95 - handlerScopeProps.add(key); 1.96 - } 1.97 - return packet.invocationProperties.put(key, value); 1.98 - 1.99 - } else { 1.100 - fallback(); 1.101 - if (!fallbackMap.containsKey(key)) { 1.102 - //new property, default to Scope.HANDLER 1.103 - handlerScopeProps.add(key); 1.104 - } 1.105 - return fallbackMap.put(key, value); 1.106 + if (!asMapIncludingInvocationProperties.containsKey(key)) { 1.107 + //new property, default to Scope.HANDLER 1.108 + handlerScopeProps.add(key); 1.109 } 1.110 + return asMapIncludingInvocationProperties.put(key, value); 1.111 } 1.112 public Object get(Object key) { 1.113 if(key == null) 1.114 return null; 1.115 - Object value; 1.116 - if(fallbackMap == null) { 1.117 - if (packet.supports(key)) { 1.118 - value = packet.get(key); // strongly typed 1.119 - } else { 1.120 - value = packet.invocationProperties.get(key); 1.121 - } 1.122 - } else { 1.123 - fallback(); 1.124 - value = fallbackMap.get(key); 1.125 - } 1.126 + Object value = asMapIncludingInvocationProperties.get(key); 1.127 //add the attachments from the Message to the corresponding attachment property 1.128 if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) || 1.129 key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){ 1.130 @@ -153,7 +114,16 @@ 1.131 atts = new HashMap<String, DataHandler>(); 1.132 AttachmentSet attSet = packet.getMessage().getAttachments(); 1.133 for(Attachment att : attSet){ 1.134 - atts.put(att.getContentId(), att.asDataHandler()); 1.135 + String cid = att.getContentId(); 1.136 + if (cid.indexOf("@jaxws.sun.com") == -1) { 1.137 + Object a = atts.get(cid); 1.138 + if (a == null) { 1.139 + a = atts.get("<" + cid + ">"); 1.140 + if (a == null) atts.put(att.getContentId(), att.asDataHandler()); 1.141 + } 1.142 + } else { 1.143 + atts.put(att.getContentId(), att.asDataHandler()); 1.144 + } 1.145 } 1.146 return atts; 1.147 } 1.148 @@ -161,61 +131,29 @@ 1.149 } 1.150 1.151 public void putAll(Map<? extends String, ? extends Object> t) { 1.152 - fallback(); 1.153 for(String key: t.keySet()) { 1.154 - if(!fallbackMap.containsKey(key)) { 1.155 + if(!asMapIncludingInvocationProperties.containsKey(key)) { 1.156 //new property, default to Scope.HANDLER 1.157 handlerScopeProps.add(key); 1.158 } 1.159 } 1.160 - fallbackMap.putAll(t); 1.161 + asMapIncludingInvocationProperties.putAll(t); 1.162 } 1.163 1.164 public void clear() { 1.165 - fallback(); 1.166 - fallbackMap.clear(); 1.167 + asMapIncludingInvocationProperties.clear(); 1.168 } 1.169 public Object remove(Object key){ 1.170 - fallback(); 1.171 handlerScopeProps.remove(key); 1.172 - return fallbackMap.remove(key); 1.173 + return asMapIncludingInvocationProperties.remove(key); 1.174 } 1.175 public Set<String> keySet() { 1.176 - fallback(); 1.177 - return fallbackMap.keySet(); 1.178 + return asMapIncludingInvocationProperties.keySet(); 1.179 } 1.180 public Set<Map.Entry<String, Object>> entrySet(){ 1.181 - fallback(); 1.182 - return fallbackMap.entrySet(); 1.183 + return asMapIncludingInvocationProperties.entrySet(); 1.184 } 1.185 public Collection<Object> values() { 1.186 - fallback(); 1.187 - return fallbackMap.values(); 1.188 + return asMapIncludingInvocationProperties.values(); 1.189 } 1.190 - 1.191 - 1.192 - /** 1.193 - * Fill a {@link Packet} with values of this {@link MessageContext}. 1.194 - */ 1.195 - void fill(Packet packet) { 1.196 - if(fallbackMap != null) { 1.197 - for (Entry<String, Object> entry : fallbackMap.entrySet()) { 1.198 - String key = entry.getKey(); 1.199 - if (packet.supports(key)) { 1.200 - try { 1.201 - packet.put(key, entry.getValue()); 1.202 - } catch (ReadOnlyPropertyException e) { 1.203 - // Nothing to do 1.204 - } 1.205 - } else { 1.206 - packet.invocationProperties.put(key, entry.getValue()); 1.207 - } 1.208 - } 1.209 - 1.210 - //Remove properties which are removed by user. 1.211 - packet.createMapView().keySet().retainAll(fallbackMap.keySet()); 1.212 - packet.invocationProperties.keySet().retainAll(fallbackMap.keySet()); 1.213 - } 1.214 - } 1.215 - 1.216 }