Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved PathSpec handling for servletName & pathInfo #7947

Merged
merged 17 commits into from Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -36,7 +36,12 @@ public int compareTo(PathSpec other)
return diff;

// Path Spec Name (alphabetical)
return getDeclaration().compareTo(other.getDeclaration());
diff = getDeclaration().compareTo(other.getDeclaration());
if (diff != 0)
return diff;

// Path Implementation
return getClass().getName().compareTo(other.getClass().getName());
}

@Override
Expand All @@ -55,7 +60,7 @@ public final boolean equals(Object obj)
@Override
public final int hashCode()
{
return Objects.hash(getDeclaration());
return Objects.hash(this.getClass().getSimpleName() + ":" + getDeclaration());
joakime marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
@@ -0,0 +1,81 @@
//
// ========================================================================
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// 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.http.pathmap;

public interface MatchedPath
gregw marked this conversation as resolved.
Show resolved Hide resolved
joakime marked this conversation as resolved.
Show resolved Hide resolved
{
MatchedPath EMPTY = new MatchedPath()
{
@Override
public String getPathMatch()
{
return null;
}

@Override
public String getPathInfo()
{
return null;
}

@Override
public String toString()
{
return "MatchedPath.EMPTY";
joakime marked this conversation as resolved.
Show resolved Hide resolved
}
};

static MatchedPath from(String pathMatch, String pathInfo)
{
return new MatchedPath()
{
@Override
public String getPathMatch()
{
return pathMatch;
}

@Override
public String getPathInfo()
{
return pathInfo;
}

@Override
public String toString()
{
return "MatchedPath.from[pathMatch=" + pathMatch + ", pathInfo=" + pathInfo + "]";
joakime marked this conversation as resolved.
Show resolved Hide resolved
}
};
}

/**
* Return the portion of the path that matches a path spec.
*
* @return the path name portion of the match.
*/
String getPathMatch();

/**
* Return the portion of the path that is after the path spec.
*
* @return the path info portion of the match, or null if there is no portion after the {@link #getPathMatch()}
*/
String getPathInfo();
}
@@ -0,0 +1,70 @@
//
// ========================================================================
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// 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.http.pathmap;

import java.util.Map;

public class MatchedResource<E>
joakime marked this conversation as resolved.
Show resolved Hide resolved
{
private final E resource;
private final PathSpec pathSpec;
private final MatchedPath matchedPath;

public MatchedResource(E resource, PathSpec pathSpec, MatchedPath matchedPath)
{
this.resource = resource;
this.pathSpec = pathSpec;
this.matchedPath = matchedPath;
}

public static <E> MatchedResource<E> of(Map.Entry<PathSpec, E> mapping, MatchedPath matchedPath)
{
return new MatchedResource<>(mapping.getValue(), mapping.getKey(), matchedPath);
}

public PathSpec getPathSpec()
{
return this.pathSpec;
}

public E getResource()
{
return this.resource;
}

/**
* Return the portion of the path that matches a path spec.
*
* @return the path name portion of the match.
*/
public String getPathMatch()
{
return matchedPath.getPathMatch();
}

/**
* Return the portion of the path that is after the path spec.
*
* @return the path info portion of the match, or null if there is no portion after the {@link #getPathMatch()}
*/
public String getPathInfo()
{
return matchedPath.getPathInfo();
}
}