From 8d5013e15fde549d90ba0c05b8be0c042fd77b2f Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 3 Oct 2013 14:05:04 -0700 Subject: [PATCH] 418625 - WebSocket / Jsr RemoteEndpoint.sendObject(java.nio.HeapByteBuffer) doesn't find encoder + Adding fallback lookup using isAssignable(type) if basic map based lookup fails first. Remembers successful isAssignable(type) match for future lookups via basic map approach. --- .../jsr356/metadata/CoderMetadataSet.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/metadata/CoderMetadataSet.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/metadata/CoderMetadataSet.java index 9835c05a895..8f5f9e81a77 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/metadata/CoderMetadataSet.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/metadata/CoderMetadataSet.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.websocket.jsr356.metadata; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -144,12 +145,37 @@ public abstract class CoderMetadataSet> implements { Integer idx = typeMap.get(type); if (idx == null) + { + // Quick lookup failed, try slower lookup via isAssignable instead + idx = getMetadataByAssignableType(type); + if (idx != null) + { + // add new entry map + typeMap.put(type,idx); + } + } + + // If idx is STILL null, we've got no match + if (idx == null) { return null; } return metadatas.get(idx); } + private Integer getMetadataByAssignableType(Class type) + { + for (Map.Entry, Integer> entry : typeMap.entrySet()) + { + if (entry.getKey().isAssignableFrom(type)) + { + return entry.getValue(); + } + } + + return null; + } + @Override public Iterator iterator() {