CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-eclipse-jetty--jetty-http

Core HTTP protocol support library for Eclipse Jetty providing header handling, parsing, generation, compliance validation, and content processing capabilities

Pending
Overview
Eval results
Files

path-mapping.mddocs/

Path Mapping

Flexible path specification matching for routing and dispatch with support for servlet-style, regex, and URI template patterns, plus efficient mapping collections.

Capabilities

PathSpec Interface

Core path specification interface for matching and path extraction.

/**
 * Path specification interface for matching and path extraction
 */
interface PathSpec extends Comparable<PathSpec> {
    /** Get original path specification string */
    String getDeclaration();
    
    /** Get path prefix (for prefix matches) */
    String getPrefix();
    
    /** Get path suffix (for suffix matches) */
    String getSuffix();
    
    /** Get path specification group for ordering */
    PathSpecGroup getGroup();
    
    /** Get specification length for priority */
    int getSpecLength();
    
    /** Get path depth for priority */
    int getPathDepth();
    
    /** Check if path matches this specification */
    boolean matches(String path);
    
    /** Get matched path information */
    MatchedPath matched(String path);
    
    /** Extract path info from matched path */
    String getPathInfo(String path);
    
    /** Extract matched portion from path */
    String getPathMatch(String path);
}

MatchedPath Interface

Result of path matching with match and info extraction.

/**
 * Result of path matching with details
 */
interface MatchedPath {
    /** Get matched portion of path */
    String getPathMatch();
    
    /** Get remaining path info */
    String getPathInfo();
    
    /** Get path specification that matched */
    PathSpec getPathSpec();
}

PathSpec Implementations

Various path specification implementations for different matching patterns.

/**
 * Base class for path specifications
 */
abstract class AbstractPathSpec implements PathSpec {
    /** Create with path specification string */
    AbstractPathSpec(String pathSpec);
    
    /** Get path specification string */
    String getDeclaration();
    
    /** Compare specifications for ordering */
    int compareTo(PathSpec other);
}

/**
 * Servlet-style path specifications
 * Supports: /exact, /prefix/*, *.extension, /
 */
class ServletPathSpec extends AbstractPathSpec {
    /** Create servlet path specification */
    ServletPathSpec(String servletPathSpec);
    
    /** Check if exact match specification */
    boolean isExact();
    
    /** Check if prefix match specification */
    boolean isPrefix();
    
    /** Check if suffix match specification */
    boolean isSuffix();
    
    /** Check if default/root specification */
    boolean isDefault();
    
    /** Get variable portion length */
    int getVariableLength();
}

/**
 * Regular expression path specifications
 */
class RegexPathSpec extends AbstractPathSpec {
    /** Create regex path specification */
    RegexPathSpec(String regex);
    
    /** Get compiled pattern */
    Pattern getPattern();
    
    /** Get regex group count */
    int getGroupCount();
}

/**
 * URI template path specifications  
 * Supports: /users/{id}, /api/{version}/users/{userId}
 */
class UriTemplatePathSpec extends AbstractPathSpec {
    /** Create URI template path specification */
    UriTemplatePathSpec(String template);
    
    /** Get template variable names */
    List<String> getVariableNames();
    
    /** Get number of template variables */
    int getVariableCount();
    
    /** Extract path parameters from matched path */
    Map<String, String> getPathParams(String path);
    
    /** Check if template has variables */
    boolean hasVariables();
}

PathSpecGroup Enumeration

Groups path specifications by matching priority and type.

/**
 * Groups path specs by matching priority
 */
enum PathSpecGroup {
    /** Exact path matches (highest priority) */
    EXACT,
    
    /** Prefix with glob patterns (/path/*) */  
    PREFIX_GLOB,
    
    /** Suffix with glob patterns (*.ext) */
    SUFFIX_GLOB,
    
    /** Regular expression patterns */
    REGEX,
    
    /** Default/fallback matches (lowest priority) */
    DEFAULT;
    
    /** Get group priority (lower number = higher priority) */  
    int getPriority();
}

Path Mapping Collections

Collections for managing and matching multiple path specifications.

/**
 * Collection of path mappings with efficient matching
 */
class PathMappings<E> extends AbstractMap<PathSpec, E> 
    implements Iterable<MappedResource<E>> {
    
    /** Create empty path mappings */
    PathMappings();
    
    /** Get best matching resource for path */
    MappedResource<E> getMatched(String path);
    
    /** Get all matching resources for path (ordered by priority) */
    List<MappedResource<E>> getMatches(String path);
    
    /** Add path specification mapping */
    boolean put(PathSpec pathSpec, E resource);
    
    /** Add path specification mapping with string */
    E put(String pathSpec, E resource);
    
    /** Remove path specification mapping */
    boolean remove(PathSpec pathSpec);
    
    /** Remove all mappings */
    void clear();
    
    /** Get number of mappings */
    int size();
    
    /** Check if mappings are empty */
    boolean isEmpty();
    
    /** Get all path specifications */
    Set<PathSpec> keySet();
    
    /** Get all mapped resources */
    Collection<E> values();
    
    /** Get all mappings as entries */
    Set<Entry<PathSpec, E>> entrySet();
    
    /** Iterator over mapped resources */
    Iterator<MappedResource<E>> iterator();
}

/**
 * Set of path specifications with efficient matching
 */
class PathSpecSet extends AbstractSet<String> implements Predicate<String> {
    /** Create empty path spec set */
    PathSpecSet();
    
    /** Test if path matches any specification */
    boolean test(String path);
    
    /** Add path specification string */
    boolean add(String pathSpec);
    
    /** Remove path specification string */
    boolean remove(String pathSpec);
    
    /** Check if contains specification */
    boolean contains(Object pathSpec);
    
    /** Get number of specifications */
    int size();
    
    /** Check if set is empty */
    boolean isEmpty();
    
    /** Clear all specifications */
    void clear();
    
    /** Iterator over specification strings */
    Iterator<String> iterator();
}

Supporting Classes

Classes for representing mapping results and matched resources.

/**
 * Path mapping result with resource and match information
 */
class MappedResource<E> implements Comparable<MappedResource<E>>, 
    Map.Entry<PathSpec, E> {
    
    /** Create mapped resource */
    MappedResource(E resource, PathSpec pathSpec, MatchedPath matchedPath);
    
    /** Get mapped resource */
    E getResource();
    
    /** Get path specification */
    PathSpec getPathSpec();
    
    /** Get matched path information */
    MatchedPath getMatchedPath();
    
    /** Get matched portion of path */
    String getPathMatch();
    
    /** Get remaining path info */
    String getPathInfo();
    
    /** Get resource (Map.Entry interface) */
    E getValue();
    
    /** Get path spec (Map.Entry interface) */  
    PathSpec getKey();
    
    /** Compare resources by path spec priority */
    int compareTo(MappedResource<E> other);
}

/**
 * Resource matched to a specific path
 */
class MatchedResource<E> {
    /** Create from mapping entry and matched path */
    static <E> MatchedResource<E> of(Map.Entry<PathSpec, E> mapping, 
                                    MatchedPath matchedPath);
    
    /** Get matched resource */
    E getResource();
    
    /** Get path specification */
    PathSpec getPathSpec();
    
    /** Get matched path information */
    MatchedPath getMatchedPath();
}

Usage Examples:

import org.eclipse.jetty.http.pathmap.*;
import java.util.Map;

// Create servlet-style path specifications
PathSpec exactSpec = new ServletPathSpec("/api/users");
PathSpec prefixSpec = new ServletPathSpec("/api/*");
PathSpec suffixSpec = new ServletPathSpec("*.json");
PathSpec defaultSpec = new ServletPathSpec("/");

// Test path matching
boolean matches = exactSpec.matches("/api/users");        // true
boolean prefixMatch = prefixSpec.matches("/api/users/123"); // true
boolean suffixMatch = suffixSpec.matches("/data.json");    // true

// Extract path information
String pathInfo = prefixSpec.getPathInfo("/api/users/123"); // "/users/123"
String pathMatch = prefixSpec.getPathMatch("/api/users/123"); // "/api"

// Regular expression path specs
PathSpec regexSpec = new RegexPathSpec("^/users/([0-9]+)$");
boolean regexMatch = regexSpec.matches("/users/123"); // true

MatchedPath matched = regexSpec.matched("/users/123");
String matchedPortion = matched.getPathMatch(); // "/users/123"

// URI template path specs with parameter extraction
UriTemplatePathSpec templateSpec = new UriTemplatePathSpec("/users/{userId}/posts/{postId}");
boolean templateMatch = templateSpec.matches("/users/123/posts/456"); // true

Map<String, String> params = templateSpec.getPathParams("/users/123/posts/456");
String userId = params.get("userId");   // "123"
String postId = params.get("postId");   // "456"

List<String> variableNames = templateSpec.getVariableNames(); // ["userId", "postId"]

// Path mappings for routing
PathMappings<String> routes = new PathMappings<>();

// Add route mappings
routes.put("/api/users", "UserController");
routes.put("/api/users/*", "UserController");
routes.put("/api/posts/*", "PostController");
routes.put("*.json", "JsonRenderer");
routes.put("/", "DefaultController");

// Find best match for a path
MappedResource<String> match = routes.getMatched("/api/users/123");
if (match != null) {
    String controller = match.getResource();    // "UserController"
    String pathInfo = match.getPathInfo();      // "/123"
    PathSpec spec = match.getPathSpec();        // ServletPathSpec("/api/users/*")
}

// Get all matches (ordered by priority)
List<MappedResource<String>> allMatches = routes.getMatches("/api/users/123.json");
// Will include both "/api/users/*" and "*.json" matches

// Path specification set for filtering
PathSpecSet allowedPaths = new PathSpecSet();
allowedPaths.add("/api/*");
allowedPaths.add("/public/*");
allowedPaths.add("*.css");
allowedPaths.add("*.js");

// Test if path is allowed
boolean allowed = allowedPaths.test("/api/users"); // true
boolean blocked = allowedPaths.test("/admin/config"); // false

// Use as Predicate in streams
List<String> paths = Arrays.asList("/api/users", "/admin/config", "/public/style.css");
List<String> allowedOnly = paths.stream()
    .filter(allowedPaths)
    .collect(Collectors.toList()); // ["/api/users", "/public/style.css"]

// Path spec comparison and ordering
List<PathSpec> specs = Arrays.asList(
    new ServletPathSpec("*.json"),          // Lower priority (suffix)
    new ServletPathSpec("/api/users"),      // Higher priority (exact)
    new ServletPathSpec("/api/*"),          // Medium priority (prefix)
    new ServletPathSpec("/")                // Lowest priority (default)
);

Collections.sort(specs); // Sorts by priority: exact, prefix, suffix, default

// Working with path spec groups
PathSpecGroup group = exactSpec.getGroup();    // PathSpecGroup.EXACT
int priority = group.getPriority();           // Lower numbers = higher priority

// Advanced routing with custom resources
class RouteHandler {
    private final String method;
    private final String handler;
    
    RouteHandler(String method, String handler) {
        this.method = method;
        this.handler = handler;
    }
    
    // getters...
}

PathMappings<RouteHandler> apiRoutes = new PathMappings<>();
apiRoutes.put("/api/users", new RouteHandler("GET", "listUsers"));
apiRoutes.put("/api/users/*", new RouteHandler("GET", "getUser"));

// URI template with multiple variables
UriTemplatePathSpec complexTemplate = new UriTemplatePathSpec(
    "/api/{version}/users/{userId}/posts/{postId}/comments/{commentId}"
);

Map<String, String> complexParams = complexTemplate.getPathParams(
    "/api/v1/users/123/posts/456/comments/789"
);
// Results: {version=v1, userId=123, postId=456, commentId=789}

// Path spec properties
ServletPathSpec prefixPathSpec = new ServletPathSpec("/api/*");
boolean isPrefix = prefixPathSpec.isPrefix();     // true
boolean isExact = prefixPathSpec.isExact();       // false
int specLength = prefixPathSpec.getSpecLength();  // 5 (length of "/api/")
int pathDepth = prefixPathSpec.getPathDepth();    // 1 (one path segment)

Install with Tessl CLI

npx tessl i tessl/maven-org-eclipse-jetty--jetty-http

docs

compression-utilities.md

content-management.md

cookie-handling.md

http-headers.md

http-methods-status.md

http-parsing-generation.md

index.md

multipart-processing.md

path-mapping.md

uri-processing.md

tile.json