diff -r 8c0b6bccfe47 -r 0989ad8c0860 src/share/jaxws_classes/com/sun/xml/internal/ws/handler/MessageContextImpl.java --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/handler/MessageContextImpl.java Thu Apr 04 19:05:24 2013 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/handler/MessageContextImpl.java Tue Apr 09 14:51:13 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,6 @@ import com.sun.xml.internal.ws.api.message.Attachment; import com.sun.xml.internal.ws.api.message.AttachmentSet; import com.sun.xml.internal.ws.api.message.Packet; -import com.sun.xml.internal.ws.util.ReadOnlyPropertyException; import javax.activation.DataHandler; import javax.xml.ws.handler.MessageContext; @@ -37,29 +36,24 @@ import java.util.Map; import java.util.Set; + /** * * @author WS Development Team */ class MessageContextImpl implements MessageContext { - private Map fallbackMap = null; - private Set handlerScopeProps; - Packet packet; + private final Set handlerScopeProps; + private final Packet packet; + private final Map asMapIncludingInvocationProperties; - - void fallback() { - if(fallbackMap == null) { - fallbackMap = new HashMap(); - fallbackMap.putAll(packet.createMapView()); - fallbackMap.putAll(packet.invocationProperties); - } - } /** Creates a new instance of MessageContextImpl */ public MessageContextImpl(Packet packet) { this.packet = packet; - handlerScopeProps = packet.getHandlerScopePropertyNames(false); + this.asMapIncludingInvocationProperties = packet.asMapIncludingInvocationProperties(); + this.handlerScopeProps = packet.getHandlerScopePropertyNames(false); } + protected void updatePacket() { throw new UnsupportedOperationException("wrong call"); } @@ -86,65 +80,32 @@ } public int size() { - fallback(); - return fallbackMap.size(); + return asMapIncludingInvocationProperties.size(); } public boolean isEmpty() { - fallback(); - return fallbackMap.isEmpty(); + return asMapIncludingInvocationProperties.isEmpty(); } public boolean containsKey(Object key) { - if(fallbackMap == null) { - if(packet.supports(key)) - return true; - return packet.invocationProperties.containsKey(key); - } else { - fallback(); - return fallbackMap.containsKey(key); - } + return asMapIncludingInvocationProperties.containsKey(key); } public boolean containsValue(Object value) { - fallback(); - return fallbackMap.containsValue(value); + return asMapIncludingInvocationProperties.containsValue(value); } public Object put(String key, Object value) { - if (fallbackMap == null) { - if (packet.supports(key)) { - return packet.put(key, value); // strongly typed - } - if (!packet.invocationProperties.containsKey(key)) { - //New property, default to Scope.HANDLER - handlerScopeProps.add(key); - } - return packet.invocationProperties.put(key, value); - - } else { - fallback(); - if (!fallbackMap.containsKey(key)) { - //new property, default to Scope.HANDLER - handlerScopeProps.add(key); - } - return fallbackMap.put(key, value); + if (!asMapIncludingInvocationProperties.containsKey(key)) { + //new property, default to Scope.HANDLER + handlerScopeProps.add(key); } + return asMapIncludingInvocationProperties.put(key, value); } public Object get(Object key) { if(key == null) return null; - Object value; - if(fallbackMap == null) { - if (packet.supports(key)) { - value = packet.get(key); // strongly typed - } else { - value = packet.invocationProperties.get(key); - } - } else { - fallback(); - value = fallbackMap.get(key); - } + Object value = asMapIncludingInvocationProperties.get(key); //add the attachments from the Message to the corresponding attachment property if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) || key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){ @@ -153,7 +114,16 @@ atts = new HashMap(); AttachmentSet attSet = packet.getMessage().getAttachments(); for(Attachment att : attSet){ - atts.put(att.getContentId(), att.asDataHandler()); + String cid = att.getContentId(); + if (cid.indexOf("@jaxws.sun.com") == -1) { + Object a = atts.get(cid); + if (a == null) { + a = atts.get("<" + cid + ">"); + if (a == null) atts.put(att.getContentId(), att.asDataHandler()); + } + } else { + atts.put(att.getContentId(), att.asDataHandler()); + } } return atts; } @@ -161,61 +131,29 @@ } public void putAll(Map t) { - fallback(); for(String key: t.keySet()) { - if(!fallbackMap.containsKey(key)) { + if(!asMapIncludingInvocationProperties.containsKey(key)) { //new property, default to Scope.HANDLER handlerScopeProps.add(key); } } - fallbackMap.putAll(t); + asMapIncludingInvocationProperties.putAll(t); } public void clear() { - fallback(); - fallbackMap.clear(); + asMapIncludingInvocationProperties.clear(); } public Object remove(Object key){ - fallback(); handlerScopeProps.remove(key); - return fallbackMap.remove(key); + return asMapIncludingInvocationProperties.remove(key); } public Set keySet() { - fallback(); - return fallbackMap.keySet(); + return asMapIncludingInvocationProperties.keySet(); } public Set> entrySet(){ - fallback(); - return fallbackMap.entrySet(); + return asMapIncludingInvocationProperties.entrySet(); } public Collection values() { - fallback(); - return fallbackMap.values(); + return asMapIncludingInvocationProperties.values(); } - - - /** - * Fill a {@link Packet} with values of this {@link MessageContext}. - */ - void fill(Packet packet) { - if(fallbackMap != null) { - for (Entry entry : fallbackMap.entrySet()) { - String key = entry.getKey(); - if (packet.supports(key)) { - try { - packet.put(key, entry.getValue()); - } catch (ReadOnlyPropertyException e) { - // Nothing to do - } - } else { - packet.invocationProperties.put(key, entry.getValue()); - } - } - - //Remove properties which are removed by user. - packet.createMapView().keySet().retainAll(fallbackMap.keySet()); - packet.invocationProperties.keySet().retainAll(fallbackMap.keySet()); - } - } - }