Skip to content

Commit

Permalink
Issue #4814 - Attributes.getAttributeNames() is now defaulted
Browse files Browse the repository at this point in the history
The Attributes.getAttributeNames() will use the
.getAttributeNameSet() by default now.

Updated all Attributes.Wrapper impls to use this new behavior

Signed-off-by: Joakim Erdfelt <[email protected]>
  • Loading branch information
joakime committed Apr 27, 2020
1 parent d460786 commit 663ef83
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
package org.eclipse.jetty.server;

import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -294,13 +293,11 @@ public Object getAttribute(String key)
}

@Override
public Enumeration<String> getAttributeNames()
public Set<String> getAttributeNameSet()
{
HashSet<String> set = new HashSet<>();
Enumeration<String> e = _attributes.getAttributeNames();
while (e.hasMoreElements())
for (String name : _attributes.getAttributeNameSet())
{
String name = e.nextElement();
if (!name.startsWith(__INCLUDE_PREFIX) &&
!name.startsWith(__FORWARD_PREFIX))
set.add(name);
Expand All @@ -321,7 +318,7 @@ public Enumeration<String> getAttributeNames()
set.remove(FORWARD_QUERY_STRING);
}

return Collections.enumeration(set);
return set;
}

@Override
Expand Down Expand Up @@ -419,13 +416,11 @@ else if (key.startsWith(__INCLUDE_PREFIX))
}

@Override
public Enumeration<String> getAttributeNames()
public Set<String> getAttributeNameSet()
{
HashSet<String> set = new HashSet<>();
Enumeration<String> e = _attributes.getAttributeNames();
while (e.hasMoreElements())
for (String name : _attributes.getAttributeNameSet())
{
String name = e.nextElement();
if (!name.startsWith(__INCLUDE_PREFIX))
set.add(name);
}
Expand All @@ -445,7 +440,7 @@ public Enumeration<String> getAttributeNames()
set.remove(INCLUDE_QUERY_STRING);
}

return Collections.enumeration(set);
return set;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package org.eclipse.jetty.server;

import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -363,7 +361,7 @@ public Object getAttribute(String name)
}

@Override
public Enumeration<String> getAttributeNames()
public Set<String> getAttributeNameSet()
{
Set<String> names = new HashSet<>(_attributes.getAttributeNameSet());
names.add(JAVAX_SERVLET_REQUEST_X_509_CERTIFICATE);
Expand All @@ -373,7 +371,7 @@ public Enumeration<String> getAttributeNames()
String sessionAttribute = getSslSessionAttribute();
if (!StringUtil.isEmpty(sessionAttribute))
names.add(sessionAttribute);
return Collections.enumeration(names);
return names;
}
}
}
12 changes: 5 additions & 7 deletions jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.eclipse.jetty.util;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Set;

Expand All @@ -35,7 +36,10 @@ public interface Attributes

Set<String> getAttributeNameSet();

Enumeration<String> getAttributeNames();
default Enumeration<String> getAttributeNames()
{
return Collections.enumeration(getAttributeNameSet());
}

void clearAttributes();

Expand Down Expand Up @@ -80,12 +84,6 @@ public Object getAttribute(String name)
return _attributes.getAttribute(name);
}

@Override
public Enumeration<String> getAttributeNames()
{
return _attributes.getAttributeNames();
}

@Override
public Set<String> getAttributeNameSet()
{
Expand Down

0 comments on commit 663ef83

Please sign in to comment.