Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-util/src/main')
-rw-r--r--jetty-util/src/main/config/modules/logging.mod6
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java118
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExclude.java6
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/Loader.java146
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java9
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/Promise.java69
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java185
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java12
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java2
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java4
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java4
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java40
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java2
13 files changed, 424 insertions, 179 deletions
diff --git a/jetty-util/src/main/config/modules/logging.mod b/jetty-util/src/main/config/modules/logging.mod
index 4f30a8862d..8f6f15a5b6 100644
--- a/jetty-util/src/main/config/modules/logging.mod
+++ b/jetty-util/src/main/config/modules/logging.mod
@@ -1,6 +1,6 @@
-#
-# Jetty std err/out logging
-#
+[description]
+Redirects JVMs stderr and stdout to a log file,
+including output from Jetty's default StdErrLog logging.
[xml]
etc/jetty-logging.xml
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
index 33da374b04..e9c5104dbe 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Callback.java
@@ -16,28 +16,14 @@
// ========================================================================
//
-/*
- * Copyright (c) 2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package org.eclipse.jetty.util;
+import java.util.concurrent.CompletableFuture;
+
/**
* <p>A callback abstraction that handles completed/failed events of asynchronous operations.</p>
*
- * <p>Semantically this is equivalent to an optimise Promise&lt;Void&gt;, but callback is a more meaningful
+ * <p>Semantically this is equivalent to an optimise Promise&lt;Void&gt;, but callback is a more meaningful
* name than EmptyPromise</p>
*/
public interface Callback
@@ -46,8 +32,7 @@ public interface Callback
* Instance of Adapter that can be used when the callback methods need an empty
* implementation without incurring in the cost of allocating a new Adapter object.
*/
- static Callback NOOP = new Callback(){};
-
+ Callback NOOP = new Callback(){};
/**
* <p>Callback invoked when the operation completes.</p>
@@ -71,25 +56,102 @@ public interface Callback
{
return false;
}
-
-
+
+ /**
+ * <p>Creates a non-blocking callback from the given incomplete CompletableFuture.</p>
+ * <p>When the callback completes, either succeeding or failing, the
+ * CompletableFuture is also completed, respectively via
+ * {@link CompletableFuture#complete(Object)} or
+ * {@link CompletableFuture#completeExceptionally(Throwable)}.</p>
+ *
+ * @param completable the CompletableFuture to convert into a callback
+ * @return a callback that when completed, completes the given CompletableFuture
+ */
+ static Callback from(CompletableFuture<?> completable)
+ {
+ return from(completable, false);
+ }
+
+ /**
+ * <p>Creates a callback from the given incomplete CompletableFuture,
+ * with the given {@code blocking} characteristic.</p>
+ *
+ * @param completable the CompletableFuture to convert into a callback
+ * @param blocking whether the callback is blocking
+ * @return a callback that when completed, completes the given CompletableFuture
+ */
+ static Callback from(CompletableFuture<?> completable, boolean blocking)
+ {
+ if (completable instanceof Callback)
+ return (Callback)completable;
+
+ return new Callback()
+ {
+ @Override
+ public void succeeded()
+ {
+ completable.complete(null);
+ }
+
+ @Override
+ public void failed(Throwable x)
+ {
+ completable.completeExceptionally(x);
+ }
+
+ @Override
+ public boolean isNonBlocking()
+ {
+ return !blocking;
+ }
+ };
+ }
+
/**
* Callback interface that declares itself as non-blocking
*/
interface NonBlocking extends Callback
{
@Override
- public default boolean isNonBlocking()
+ default boolean isNonBlocking()
{
return true;
}
}
-
-
+
/**
- * <p>Empty implementation of {@link Callback}</p>
+ * <p>A CompletableFuture that is also a Callback.</p>
*/
- @Deprecated
- static class Adapter implements Callback
- {}
+ class Completable extends CompletableFuture<Void> implements Callback
+ {
+ private final boolean blocking;
+
+ public Completable()
+ {
+ this(false);
+ }
+
+ public Completable(boolean blocking)
+ {
+ this.blocking = blocking;
+ }
+
+ @Override
+ public void succeeded()
+ {
+ complete(null);
+ }
+
+ @Override
+ public void failed(Throwable x)
+ {
+ completeExceptionally(x);
+ }
+
+ @Override
+ public boolean isNonBlocking()
+ {
+ return !blocking;
+ }
+ }
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExclude.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExclude.java
index 39d80e2291..340761d99f 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExclude.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExclude.java
@@ -58,6 +58,7 @@ public class IncludeExclude<ITEM>
/**
* Default constructor over {@link HashSet}
*/
+ @SuppressWarnings("unchecked")
public IncludeExclude()
{
this(HashSet.class);
@@ -68,6 +69,7 @@ public class IncludeExclude<ITEM>
* @param setClass The type of {@link Set} to using internally
* @param predicate A predicate function to test if a passed ITEM is matched by the passed SET}
*/
+ @SuppressWarnings("unchecked")
public <SET extends Set<ITEM>> IncludeExclude(Class<SET> setClass)
{
try
@@ -114,7 +116,7 @@ public class IncludeExclude<ITEM>
_includes.add(element);
}
- public void include(ITEM... element)
+ public void include(@SuppressWarnings("unchecked") ITEM... element)
{
for (ITEM e: element)
_includes.add(e);
@@ -125,7 +127,7 @@ public class IncludeExclude<ITEM>
_excludes.add(element);
}
- public void exclude(ITEM... element)
+ public void exclude(@SuppressWarnings("unchecked") ITEM... element)
{
for (ITEM e: element)
_excludes.add(e);
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Loader.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Loader.java
index 062029cef4..885551ffd3 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Loader.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Loader.java
@@ -18,15 +18,11 @@
package org.eclipse.jetty.util;
-import java.io.File;
import java.net.URL;
-import java.net.URLClassLoader;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import org.eclipse.jetty.util.resource.Resource;
-
/* ------------------------------------------------------------ */
/** ClassLoader Helper.
* This helper class allows classes to be loaded either from the
@@ -46,140 +42,52 @@ import org.eclipse.jetty.util.resource.Resource;
public class Loader
{
/* ------------------------------------------------------------ */
- public static URL getResource(Class<?> loadClass,String name)
+ public static URL getResource(String name)
{
- URL url =null;
- ClassLoader context_loader=Thread.currentThread().getContextClassLoader();
- if (context_loader!=null)
- url=context_loader.getResource(name);
-
- if (url==null && loadClass!=null)
- {
- ClassLoader load_loader=loadClass.getClassLoader();
- if (load_loader!=null && load_loader!=context_loader)
- url=load_loader.getResource(name);
- }
-
- if (url==null)
- url=ClassLoader.getSystemResource(name);
-
- return url;
+ ClassLoader loader=Thread.currentThread().getContextClassLoader();
+ return loader==null?ClassLoader.getSystemResource(name):loader.getResource(name);
}
/* ------------------------------------------------------------ */
/** Load a class.
+ * <p>Load a class either from the thread context classloader or if none, the system
+ * loader</p>
+ * @param name the name of the new class to load
*
- * @param loadClass the class to use for the ClassLoader that was used
- * @param name the name of the new class to load, using the same ClassLoader as the <code>loadClass</code>
* @return Class
* @throws ClassNotFoundException if not able to find the class
*/
@SuppressWarnings("rawtypes")
- public static Class loadClass(Class loadClass,String name)
+ public static Class loadClass(String name)
throws ClassNotFoundException
{
- ClassNotFoundException ex=null;
- Class<?> c =null;
- ClassLoader context_loader=Thread.currentThread().getContextClassLoader();
- if (context_loader!=null )
- {
- try { c=context_loader.loadClass(name); }
- catch (ClassNotFoundException e) {ex=e;}
- }
-
- if (c==null && loadClass!=null)
- {
- ClassLoader load_loader=loadClass.getClassLoader();
- if (load_loader!=null && load_loader!=context_loader)
- {
- try { c=load_loader.loadClass(name); }
- catch (ClassNotFoundException e) {if(ex==null)ex=e;}
- }
- }
-
- if (c==null)
- {
- try { c=Class.forName(name); }
- catch (ClassNotFoundException e)
- {
- if(ex!=null)
- throw ex;
- throw e;
- }
- }
+ ClassLoader loader=Thread.currentThread().getContextClassLoader();
+ return (loader==null ) ? Class.forName(name) : loader.loadClass(name);
+ }
- return c;
- }
-
-
-
/* ------------------------------------------------------------ */
- public static ResourceBundle getResourceBundle(Class<?> loadClass,String name,boolean checkParents, Locale locale)
- throws MissingResourceException
+ /** Load a class.
+ * Load a class from the same classloader as the passed <code>loadClass</code>, or if none
+ * then use {@link #loadClass(String)}
+ *
+ * @return Class
+ * @throws ClassNotFoundException if not able to find the class
+ */
+ @SuppressWarnings("rawtypes")
+ public static Class loadClass(Class loaderClass, String name)
+ throws ClassNotFoundException
{
- MissingResourceException ex=null;
- ResourceBundle bundle =null;
- ClassLoader loader=Thread.currentThread().getContextClassLoader();
- while (bundle==null && loader!=null )
- {
- try { bundle=ResourceBundle.getBundle(name, locale, loader); }
- catch (MissingResourceException e) {if(ex==null)ex=e;}
- loader=(bundle==null&&checkParents)?loader.getParent():null;
- }
-
- loader=loadClass==null?null:loadClass.getClassLoader();
- while (bundle==null && loader!=null )
- {
- try { bundle=ResourceBundle.getBundle(name, locale, loader); }
- catch (MissingResourceException e) {if(ex==null)ex=e;}
- loader=(bundle==null&&checkParents)?loader.getParent():null;
- }
-
- if (bundle==null)
- {
- try { bundle=ResourceBundle.getBundle(name, locale); }
- catch (MissingResourceException e) {if(ex==null)ex=e;}
- }
-
- if (bundle!=null)
- return bundle;
- throw ex;
+ if (loaderClass!=null && loaderClass.getClassLoader()!=null)
+ return loaderClass.getClassLoader().loadClass(name);
+ return loadClass(name);
}
-
/* ------------------------------------------------------------ */
- /**
- * Generate the classpath (as a string) of all classloaders
- * above the given classloader.
- *
- * This is primarily used for jasper.
- * @param loader the classloader to use
- * @return the system class path
- * @throws Exception if unable to generate the classpath from the resource references
- */
- public static String getClassPath(ClassLoader loader) throws Exception
+ public static ResourceBundle getResourceBundle(String name,boolean checkParents,Locale locale)
+ throws MissingResourceException
{
- StringBuilder classpath=new StringBuilder();
- while (loader != null && (loader instanceof URLClassLoader))
- {
- URL[] urls = ((URLClassLoader)loader).getURLs();
- if (urls != null)
- {
- for (int i=0;i<urls.length;i++)
- {
- Resource resource = Resource.newResource(urls[i]);
- File file=resource.getFile();
- if (file!=null && file.exists())
- {
- if (classpath.length()>0)
- classpath.append(File.pathSeparatorChar);
- classpath.append(file.getAbsolutePath());
- }
- }
- }
- loader = loader.getParent();
- }
- return classpath.toString();
+ ClassLoader loader=Thread.currentThread().getContextClassLoader();
+ return loader==null ? ResourceBundle.getBundle(name, locale) : ResourceBundle.getBundle(name, locale, loader);
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
index 755e6bd830..119aba30c1 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
@@ -135,7 +135,14 @@ public class MultiPartInputStreamParser
protected void createFile ()
throws IOException
{
+ /* Some statics just to make the code below easier to understand
+ * This get optimized away during the compile anyway */
+ final boolean USER = true;
+ final boolean WORLD = false;
+
_file = File.createTempFile("MultiPart", "", MultiPartInputStreamParser.this._tmpDir);
+ _file.setReadable(false,WORLD); // (reset) disable it for everyone first
+ _file.setReadable(true,USER); // enable for user only
if (_deleteOnExit)
_file.deleteOnExit();
@@ -508,7 +515,7 @@ public class MultiPartInputStreamParser
line=(line==null?line:line.trim());
}
- if (line == null)
+ if (line == null || line.length() == 0)
throw new IOException("Missing initial multi part boundary");
// Empty multipart.
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Promise.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Promise.java
index 30ed7f11be..a20c0d18de 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/Promise.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Promise.java
@@ -18,6 +18,8 @@
package org.eclipse.jetty.util;
+import java.util.concurrent.CompletableFuture;
+
import org.eclipse.jetty.util.log.Log;
/**
@@ -33,25 +35,28 @@ public interface Promise<C>
* @param result the context
* @see #failed(Throwable)
*/
- public abstract void succeeded(C result);
+ default void succeeded(C result)
+ {
+ }
/**
* <p>Callback invoked when the operation fails.</p>
*
* @param x the reason for the operation failure
*/
- public void failed(Throwable x);
-
+ default void failed(Throwable x)
+ {
+ }
/**
- * <p>Empty implementation of {@link Promise}</p>
+ * <p>Empty implementation of {@link Promise}.</p>
*
- * @param <C> the type of the context object
+ * @param <U> the type of the result
*/
- public static class Adapter<C> implements Promise<C>
+ class Adapter<U> implements Promise<U>
{
@Override
- public void succeeded(C result)
+ public void succeeded(U result)
{
}
@@ -62,4 +67,54 @@ public interface Promise<C>
}
}
+ /**
+ * <p>Creates a promise from the given incomplete CompletableFuture.</p>
+ * <p>When the promise completes, either succeeding or failing, the
+ * CompletableFuture is also completed, respectively via
+ * {@link CompletableFuture#complete(Object)} or
+ * {@link CompletableFuture#completeExceptionally(Throwable)}.</p>
+ *
+ * @param completable the CompletableFuture to convert into a promise
+ * @return a promise that when completed, completes the given CompletableFuture
+ */
+ static <T> Promise<T> from(CompletableFuture<? super T> completable)
+ {
+ if (completable instanceof Promise)
+ return (Promise<T>)completable;
+
+ return new Promise<T>()
+ {
+ @Override
+ public void succeeded(T result)
+ {
+ completable.complete(result);
+ }
+
+ @Override
+ public void failed(Throwable x)
+ {
+ completable.completeExceptionally(x);
+ }
+ };
+ }
+
+ /**
+ * <p>A CompletableFuture that is also a Promise.</p>
+ *
+ * @param <S> the type of the result
+ */
+ class Completable<S> extends CompletableFuture<S> implements Promise<S>
+ {
+ @Override
+ public void succeeded(S result)
+ {
+ complete(result);
+ }
+
+ @Override
+ public void failed(Throwable x)
+ {
+ completeExceptionally(x);
+ }
+ }
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java
new file mode 100644
index 0000000000..4f86b4544b
--- /dev/null
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TopologicalSort.java
@@ -0,0 +1,185 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.util;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+
+/**
+ * Topological sort a list or array.
+ * <p>A Topological sort is used when you have a partial ordering expressed as
+ * dependencies between elements (also often represented as edges in a directed
+ * acyclic graph). A Topological sort should not be used when you have a total
+ * ordering expressed as a {@link Comparator} over the items. The algorithm has
+ * the additional characteristic that dependency sets are sorted by the original
+ * list order so that order is preserved when possible.</p>
+ * <p>
+ * The sort algorithm works by recursively visiting every item, once and
+ * only once. On each visit, the items dependencies are first visited and then the
+ * item is added to the sorted list. Thus the algorithm ensures that dependency
+ * items are always added before dependent items.</p>
+ *
+ * @param <T> The type to be sorted. It must be able to be added to a {@link HashSet}
+ */
+public class TopologicalSort<T>
+{
+ private final Map<T,Set<T>> _dependencies = new HashMap<>();
+
+ /**
+ * Add a dependency to be considered in the sort.
+ * @param dependent The dependent item will be sorted after all its dependencies
+ * @param dependency The dependency item, will be sorted before its dependent item
+ */
+ public void addDependency(T dependent, T dependency)
+ {
+ Set<T> set = _dependencies.get(dependent);
+ if (set==null)
+ {
+ set=new HashSet<>();
+ _dependencies.put(dependent,set);
+ }
+ set.add(dependency);
+ }
+
+ /** Sort the passed array according to dependencies previously set with
+ * {@link #addDependency(Object, Object)}. Where possible, ordering will be
+ * preserved if no dependency
+ * @param array The array to be sorted.
+ */
+ public void sort(T[] array)
+ {
+ List<T> sorted = new ArrayList<>();
+ Set<T> visited = new HashSet<>();
+ Comparator<T> comparator = new InitialOrderComparator<>(array);
+
+ // Visit all items in the array
+ for (T t : array)
+ visit(t,visited,sorted,comparator);
+
+ sorted.toArray(array);
+ }
+
+ /** Sort the passed list according to dependencies previously set with
+ * {@link #addDependency(Object, Object)}. Where possible, ordering will be
+ * preserved if no dependency
+ * @param list The list to be sorted.
+ */
+ public void sort(Collection<T> list)
+ {
+ List<T> sorted = new ArrayList<>();
+ Set<T> visited = new HashSet<>();
+ Comparator<T> comparator = new InitialOrderComparator<>(list);
+
+ // Visit all items in the list
+ for (T t : list)
+ visit(t,visited,sorted,comparator);
+
+ list.clear();
+ list.addAll(sorted);
+ }
+
+ /** Visit an item to be sorted.
+ * @param item The item to be visited
+ * @param visited The Set of items already visited
+ * @param sorted The list to sort items into
+ * @param comparator A comparator used to sort dependencies.
+ */
+ private void visit(T item, Set<T> visited, List<T> sorted,Comparator<T> comparator)
+ {
+ // If the item has not been visited
+ if(!visited.contains(item))
+ {
+ // We are visiting it now, so add it to the visited set
+ visited.add(item);
+
+ // Lookup the items dependencies
+ Set<T> dependencies = _dependencies.get(item);
+ if (dependencies!=null)
+ {
+ // Sort the dependencies
+ SortedSet<T> ordered_deps = new TreeSet<>(comparator);
+ ordered_deps.addAll(dependencies);
+
+ // recursively visit each dependency
+ for (T d:ordered_deps)
+ visit(d,visited,sorted,comparator);
+ }
+
+ // Now that we have visited all our dependencies, they and their
+ // dependencies will have been added to the sorted list. So we can
+ // now add the current item and it will be after its dependencies
+ sorted.add(item);
+ }
+ else if (!sorted.contains(item))
+ // If we have already visited an item, but it has not yet been put in the
+ // sorted list, then we must be in a cycle!
+ throw new IllegalStateException("cyclic at "+item);
+ }
+
+
+ /** A comparator that is used to sort dependencies in the order they
+ * were in the original list. This ensures that dependencies are visited
+ * in the original order and no needless reordering takes place.
+ * @param <T>
+ */
+ private static class InitialOrderComparator<T> implements Comparator<T>
+ {
+ private final Map<T,Integer> _indexes = new HashMap<>();
+ InitialOrderComparator(T[] initial)
+ {
+ int i=0;
+ for (T t : initial)
+ _indexes.put(t,i++);
+ }
+
+ InitialOrderComparator(Collection<T> initial)
+ {
+ int i=0;
+ for (T t : initial)
+ _indexes.put(t,i++);
+ }
+
+ @Override
+ public int compare(T o1, T o2)
+ {
+ Integer i1=_indexes.get(o1);
+ Integer i2=_indexes.get(o2);
+ if (i1==null || i2==null || i1.equals(o2))
+ return 0;
+ if (i1<i2)
+ return -1;
+ return 1;
+ }
+
+ }
+
+ @Override
+ public String toString()
+ {
+ return "TopologicalSort "+_dependencies;
+ }
+}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
index e776c9a4d5..f6c3419abe 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
@@ -453,7 +453,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
key = null;
value=null;
if (maxKeys>0 && map.size()>maxKeys)
- throw new IllegalStateException("Form too many keys");
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]",map.size(),maxKeys));
break;
case '=':
@@ -499,7 +499,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
break;
}
if (maxLength>=0 && (++totalLength > maxLength))
- throw new IllegalStateException("Form too large");
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]",map.size(),maxKeys));
}
if (key != null)
@@ -555,7 +555,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
key = null;
value=null;
if (maxKeys>0 && map.size()>maxKeys)
- throw new IllegalStateException("Form too many keys");
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]",map.size(),maxKeys));
break;
case '=':
@@ -629,7 +629,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
LOG.debug(e);
}
if (maxLength>=0 && (++totalLength > maxLength))
- throw new IllegalStateException("Form too large");
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]",map.size(),maxKeys));
}
if (key != null)
@@ -751,7 +751,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
key = null;
value=null;
if (maxKeys>0 && map.size()>maxKeys)
- throw new IllegalStateException("Form too many keys");
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]",map.size(),maxKeys));
break;
case '=':
if (key!=null)
@@ -797,7 +797,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
totalLength++;
if (maxLength>=0 && totalLength > maxLength)
- throw new IllegalStateException("Form too large");
+ throw new IllegalStateException(String.format("Form with too many keys [%d > %d]",map.size(),maxKeys));
}
size=output.size();
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java
index 57178cd48a..66b8fad26e 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java
@@ -95,7 +95,7 @@ public class JavaUtilLog extends AbstractLogger
{
try
{
- URL props = Loader.getResource(JavaUtilLog.class,properties);
+ URL props = Loader.getResource(properties);
if (props != null)
LogManager.getLogManager().readConfiguration(props.openStream());
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
index 396b95b268..602d124791 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
@@ -132,7 +132,7 @@ public class Log
static void loadProperties(String resourceName, Properties props)
{
- URL testProps = Loader.getResource(Log.class,resourceName);
+ URL testProps = Loader.getResource(resourceName);
if (testProps != null)
{
try (InputStream in = testProps.openStream())
@@ -169,7 +169,7 @@ public class Log
try
{
- Class<?> log_class = __logClass==null?null:Loader.loadClass(Log.class, __logClass);
+ Class<?> log_class = __logClass==null?null:Loader.loadClass(__logClass);
if (LOG == null || (log_class!=null && !LOG.getClass().equals(log_class)))
{
LOG = (Logger)log_class.newInstance();
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java
index 35e0cf5eda..153f08ca9e 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java
@@ -269,7 +269,7 @@ public abstract class Resource implements ResourceFactory, Closeable
/* ------------------------------------------------------------ */
/** Find a classpath resource.
* The {@link java.lang.Class#getResource(String)} method is used to lookup the resource. If it is not
- * found, then the {@link Loader#getResource(Class, String)} method is used.
+ * found, then the {@link Loader#getResource(String)} method is used.
* If it is still not found, then {@link ClassLoader#getSystemResource(String)} is used.
* Unlike {@link ClassLoader#getSystemResource(String)} this method does not check for normal resources.
* @param name The relative name of the resource
@@ -283,7 +283,7 @@ public abstract class Resource implements ResourceFactory, Closeable
URL url=Resource.class.getResource(name);
if (url==null)
- url=Loader.getResource(Resource.class,name);
+ url=Loader.getResource(name);
if (url==null)
return null;
return newResource(url,useCaches);
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java
index c763f94156..9c50e1abf3 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java
@@ -104,7 +104,20 @@ public abstract class Credential implements Serializable
String passwd = credentials.toString();
return _cooked.equals(UnixCrypt.crypt(passwd, _cooked));
}
-
+
+
+ @Override
+ public boolean equals (Object credential)
+ {
+ if (!(credential instanceof Crypt))
+ return false;
+
+ Crypt c = (Crypt)credential;
+
+ return _cooked.equals(c._cooked);
+ }
+
+
public static String crypt(String user, String pw)
{
return "CRYPT:" + UnixCrypt.crypt(pw, user);
@@ -167,12 +180,7 @@ public abstract class Credential implements Serializable
}
else if (credentials instanceof MD5)
{
- MD5 md5 = (MD5) credentials;
- if (_digest.length != md5._digest.length) return false;
- boolean digestMismatch = false;
- for (int i = 0; i < _digest.length; i++)
- digestMismatch |= (_digest[i] != md5._digest[i]);
- return !digestMismatch;
+ return equals((MD5)credentials);
}
else if (credentials instanceof Credential)
{
@@ -192,6 +200,24 @@ public abstract class Credential implements Serializable
return false;
}
}
+
+
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof MD5)
+ {
+ MD5 md5 = (MD5) obj;
+ if (_digest.length != md5._digest.length) return false;
+ boolean digestMismatch = false;
+ for (int i = 0; i < _digest.length; i++)
+ digestMismatch |= (_digest[i] != md5._digest[i]);
+ return !digestMismatch;
+ }
+
+ return false;
+ }
/* ------------------------------------------------------------ */
public static String digest(String password)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java
index b576972736..676263fe46 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java
@@ -83,7 +83,7 @@ public interface ExecutionStrategy
{
try
{
- Class<? extends ExecutionStrategy> c = Loader.loadClass(producer.getClass(),strategy);
+ Class<? extends ExecutionStrategy> c = Loader.loadClass(strategy);
Constructor<? extends ExecutionStrategy> m = c.getConstructor(Producer.class,Executor.class);
LOG.info("Use {} for {}",c.getSimpleName(),producer.getClass().getName());
return m.newInstance(producer,executor);

Back to the top