CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-glassfish-jersey-core--jersey-server

Jersey core server implementation for building RESTful Web Services with JAX-RS.

Pending
Overview
Eval results
Files

resource-model.mddocs/

Resource Model

Runtime representation and processing of JAX-RS resources, including model validation, method invocation, parameter handling, and complete metadata about resources and their methods for routing and execution. The resource model system provides the foundation for Jersey's request routing and method dispatch.

Capabilities

Resource

Core resource representation providing programmatic resource construction and factory methods for creating resources from classes or paths.

/**
 * Resource representation providing programmatic resource construction capabilities.
 */
public final class Resource implements Routed, ResourceModelComponent {
    
    // Factory methods for creating resource builders
    /**
     * Create an unbound resource builder.
     * @return Resource.Builder instance
     */
    public static Builder builder();
    
    /**
     * Create a resource builder with specified path.
     * @param path Resource path template
     * @return Resource.Builder instance with path set
     */
    public static Builder builder(String path);
    
    /**
     * Create a resource builder from annotated resource class.
     * @param resourceClass JAX-RS annotated resource class
     * @return Resource.Builder instance initialized from class
     */
    public static Builder builder(Class<?> resourceClass);
    
    /**
     * Create a resource builder from resource class with validation control.
     * @param resourceClass JAX-RS annotated resource class
     * @param disableValidation Whether to disable validation
     * @return Resource.Builder instance initialized from class
     */
    public static Builder builder(Class<?> resourceClass, boolean disableValidation);
    
    /**
     * Create a resource builder from existing resource.
     * @param resource Existing resource to copy
     * @return Resource.Builder instance initialized from resource
     */
    public static Builder builder(Resource resource);
    
    // Direct resource creation methods
    /**
     * Create resource directly from annotated class.
     * @param resourceClass JAX-RS annotated resource class
     * @return Resource instance created from class
     */
    public static Resource from(Class<?> resourceClass);
    
    /**
     * Create resource from class with validation control.
     * @param resourceClass JAX-RS annotated resource class
     * @param disableValidation Whether to disable validation
     * @return Resource instance created from class
     */
    public static Resource from(Class<?> resourceClass, boolean disableValidation);
    
    // Utility methods
    /**
     * Check if class is acceptable as JAX-RS resource.
     * @param c Class to check
     * @return true if class can be used as resource
     */
    public static boolean isAcceptable(Class<?> c);
    
    /**
     * Get path template from resource class @Path annotation.
     * @param resourceClass Resource class with @Path annotation
     * @return Path template string or null if no @Path annotation
     */
    public static String getPath(Class<?> resourceClass);
}

Usage Examples:

import org.glassfish.jersey.server.model.Resource;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.GET;

@Path("/users")
public class UserResource {
    @GET
    public String getUsers() {
        return "Users list";
    }
}

// Create resource from annotated class
Resource userResource = Resource.from(UserResource.class);

// Create resource using builder pattern
Resource customResource = Resource.builder("/api/v1/users")
    .addMethod("GET")
    .handledBy(UserResource.class, "getUsers")
    .build();

// Check if class is valid resource
boolean isValid = Resource.isAcceptable(UserResource.class);

// Get path from class
String path = Resource.getPath(UserResource.class); // Returns "/users"

Resource.Builder

Builder for programmatic resource construction with method handling, child resources, and validation control.

/**
 * Builder for constructing Resource instances programmatically.
 */
public static final class Builder {
    
    // Method management
    /**
     * Add resource method to the resource being built.
     * @param resourceMethod ResourceMethod to add
     * @return Builder instance for chaining
     */
    public Builder addMethod(ResourceMethod resourceMethod);
    
    /**
     * Add HTTP method handler to the resource.
     * @param httpMethod HTTP method (GET, POST, etc.)
     * @return ResourceMethod.Builder for configuring the method
     */
    public ResourceMethod.Builder addMethod(String httpMethod);
    
    /**
     * Update/replace existing resource method.
     * @param resourceMethod ResourceMethod to update
     * @return Builder instance for chaining
     */
    public Builder updateMethod(ResourceMethod resourceMethod);
    
    // Child resource management
    /**
     * Add child resource to this resource.
     * @param resource Child Resource to add
     * @return Builder instance for chaining
     */
    public Builder addChildResource(Resource resource);
    
    /**
     * Replace existing child resource.
     * @param replacedResource Resource to replace
     * @param newResource New resource to add
     * @return Builder instance for chaining
     */
    public Builder replaceChildResource(Resource replacedResource, Resource newResource);
    
    // Resource merging
    /**
     * Merge this resource with another resource.
     * @param resource Resource to merge with
     * @return Builder instance for chaining
     */
    public Builder mergeWith(Resource resource);
    
    /**
     * Merge this resource with another builder.
     * @param resourceBuilder Builder to merge with
     * @return Builder instance for chaining
     */
    public Builder mergeWith(Builder resourceBuilder);
    
    // Configuration
    /**
     * Mark resource as extended resource.
     * @param extended Whether resource is extended
     * @return Builder instance for chaining
     */
    public Builder extended(boolean extended);
    
    /**
     * Set resource path template.
     * @param path Path template for the resource
     * @return Builder instance for chaining
     */
    public Builder path(String path);
    
    /**
     * Build the resource instance.
     * @return Constructed Resource instance
     * @throws IllegalStateException if resource configuration is invalid
     */
    public Resource build();
}

Usage Examples:

import org.glassfish.jersey.server.model.Resource;
import org.glassfish.jersey.server.model.ResourceMethod;

// Build complex resource programmatically
Resource apiResource = Resource.builder("/api/v1/users")
    .addMethod("GET")
        .handledBy(UserResource.class, "getAllUsers")
        .build()
    .addMethod("POST")
        .handledBy(UserResource.class, "createUser")
        .consumes("application/json")
        .build()
    .addChildResource(
        Resource.builder("/{id}")
            .addMethod("GET")
                .handledBy(UserResource.class, "getUser")
                .build()
            .build()
    )
    .build();

// Merge resources
Resource baseResource = Resource.from(BaseResource.class);
Resource extendedResource = Resource.builder()
    .mergeWith(baseResource)
    .addMethod("PUT")
        .handledBy(ExtendedResource.class, "updateResource")
        .build()
    .build();

ResourceModel

Complete resource model representation containing all registered resources and their metadata for runtime processing.

/**
 * Resource model encapsulating the complete resource information for a JAX-RS application.
 * Contains all resources, sub-resources, and their associated metadata.
 */
public final class ResourceModel implements ResourceModelComponent {
    
    /**
     * Create a new resource model builder.
     * @return ResourceModel.Builder instance
     */
    public static Builder builder();
    
    /**
     * Create a new resource model builder with automatic validation.
     * @param disableValidation Whether to disable validation during build
     * @return ResourceModel.Builder instance
     */
    public static Builder builder(boolean disableValidation);
    
    /**
     * Get all root resources in this model.
     * @return Set of root Resource instances
     */
    public Set<Resource> getResources();
    
    /**
     * Get all sub-resource models.
     * @return Set of sub-resource ResourceModel instances
     */
    public Set<ResourceModel> getSubResourceModels();
    
    /**
     * Check if the model is empty.
     * @return true if model has no resources, false otherwise
     */
    public boolean isEmpty();
    
    /**
     * Accept a resource model visitor for traversal.
     * @param visitor ResourceModelVisitor to accept
     */
    public void accept(ResourceModelVisitor visitor);
    
    /**
     * Get validation issues found in the model.
     * @return List of validation errors
     */
    public List<ResourceModelIssue> getValidationIssues();
}

Usage Examples:

import org.glassfish.jersey.server.model.ResourceModel;
import org.glassfish.jersey.server.model.Resource;

// Build resource model
ResourceModel.Builder builder = ResourceModel.builder();
builder.addResource(Resource.from(UserResource.class));
builder.addResource(Resource.from(OrderResource.class));
ResourceModel model = builder.build();

// Access resources
Set<Resource> resources = model.getResources();
for (Resource resource : resources) {
    String path = resource.getPath();
    List<ResourceMethod> methods = resource.getResourceMethods();
}

// Check for sub-resource models
Set<ResourceModel> subModels = model.getSubResourceModels();
boolean isEmpty = model.isEmpty();

// Validate model
List<ResourceModelIssue> issues = model.getValidationIssues();
if (!issues.isEmpty()) {
    for (ResourceModelIssue issue : issues) {
        System.err.println("Validation issue: " + issue.getMessage());
    }
}

ResourceModel.Builder

Builder for constructing resource models with validation and configuration options.

/**
 * Builder for constructing ResourceModel instances.
 */
public static final class Builder {
    
    /**
     * Add a resource to the model.
     * @param resource Resource to add
     * @return Builder instance for chaining
     */
    public Builder addResource(Resource resource);
    
    /**
     * Add multiple resources to the model.
     * @param resources Collection of resources to add
     * @return Builder instance for chaining
     */
    public Builder addResources(Collection<Resource> resources);
    
    /**
     * Build the resource model.
     * @return Constructed ResourceModel instance
     * @throws ModelValidationException if validation fails
     */
    public ResourceModel build();
    
    /**
     * Build the resource model with validation control.
     * @param validate Whether to validate the model during build
     * @return Constructed ResourceModel instance
     * @throws ModelValidationException if validation enabled and fails
     */
    public ResourceModel build(boolean validate);
}

RuntimeResource

Runtime representation of resources providing access to resource metadata and method information at runtime.

/**
 * Runtime resource representation providing resource metadata and method routing information.
 */
public final class RuntimeResource implements ResourceModelComponent {
    
    /**
     * Get the full resource path including parent paths.
     * @return Full resource path
     */
    public String getFullPath();
    
    /**
     * Get the resource path template.
     * @return Path template string
     */
    public String getPathTemplate();
    
    /**
     * Get all resource methods for this resource.
     * @return List of ResourceMethod instances
     */
    public List<ResourceMethod> getResourceMethods();
    
    /**
     * Get resource method by HTTP method.
     * @param httpMethod HTTP method name (GET, POST, etc.)
     * @return ResourceMethod for the HTTP method or null if not found
     */
    public ResourceMethod getResourceMethod(String httpMethod);
    
    /**
     * Get all sub-resource methods.
     * @return List of sub-resource ResourceMethod instances
     */
    public List<ResourceMethod> getSubResourceMethods();
    
    /**
     * Get all sub-resource locators.
     * @return List of ResourceMethod instances that are sub-resource locators
     */
    public List<ResourceMethod> getSubResourceLocators();
    
    /**
     * Get child runtime resources.
     * @return List of child RuntimeResource instances
     */
    public List<RuntimeResource> getChildResources();
    
    /**
     * Get parent runtime resource.
     * @return Parent RuntimeResource or null if this is a root resource
     */
    public RuntimeResource getParent();
    
    /**
     * Get regular expression pattern for path matching.
     * @return Pattern for matching resource paths
     */
    public Pattern getPathPattern();
}

Usage Examples:

import org.glassfish.jersey.server.model.RuntimeResource;
import org.glassfish.jersey.server.model.ResourceMethod;
import java.util.regex.Pattern;

// Access runtime resource information
RuntimeResource runtimeResource = getRuntimeResource();

String fullPath = runtimeResource.getFullPath(); // "/api/users/{id}"
String pathTemplate = runtimeResource.getPathTemplate(); // "/users/{id}"
Pattern pathPattern = runtimeResource.getPathPattern();

// Access resource methods
List<ResourceMethod> methods = runtimeResource.getResourceMethods();
ResourceMethod getMethod = runtimeResource.getResourceMethod("GET");
ResourceMethod postMethod = runtimeResource.getResourceMethod("POST");

// Access sub-resources
List<ResourceMethod> subResourceMethods = runtimeResource.getSubResourceMethods();
List<ResourceMethod> subResourceLocators = runtimeResource.getSubResourceLocators();
List<RuntimeResource> childResources = runtimeResource.getChildResources();

// Navigate resource hierarchy
RuntimeResource parent = runtimeResource.getParent();
if (parent != null) {
    String parentPath = parent.getFullPath();
}

RuntimeResourceModel

Container for runtime resource models providing organized access to all runtime resources.

/**
 * Container for runtime resource models providing organized access to runtime resources.
 */
public final class RuntimeResourceModel {
    
    /**
     * Get all runtime resources in the model.
     * @return List of all RuntimeResource instances
     */
    public List<RuntimeResource> getRuntimeResources();
    
    /**
     * Get runtime resources organized by path patterns.
     * @return Map of path patterns to RuntimeResource lists
     */
    public Map<Pattern, List<RuntimeResource>> getResourcesByPattern();
    
    /**
     * Find runtime resource by path.
     * @param path Resource path to find
     * @return RuntimeResource matching the path or null
     */
    public RuntimeResource findRuntimeResource(String path);
    
    /**
     * Check if the model is empty.
     * @return true if no runtime resources exist
     */
    public boolean isEmpty();
}

ModelProcessor

Interface for processing and transforming resource models during application initialization.

/**
 * Interface for processing resource models during application startup.
 * Allows customization and transformation of the resource model.
 */
public interface ModelProcessor {
    
    /**
     * Process the main resource model.
     * @param resourceModel Resource model to process
     * @param configuration Application configuration
     * @return Processed resource model (may be the same or a new instance)
     */
    ResourceModel processResourceModel(ResourceModel resourceModel, Configuration configuration);
    
    /**
     * Process a sub-resource model.
     * @param subResourceModel Sub-resource model to process
     * @param configuration Application configuration
     * @return Processed sub-resource model (may be the same or a new instance)
     */
    ResourceModel processSubResource(ResourceModel subResourceModel, Configuration configuration);
}

Usage Examples:

import org.glassfish.jersey.server.model.ModelProcessor;
import org.glassfish.jersey.server.model.ResourceModel;
import jakarta.ws.rs.core.Configuration;

// Custom model processor implementation
public class CustomModelProcessor implements ModelProcessor {
    
    @Override
    public ResourceModel processResourceModel(ResourceModel resourceModel, Configuration configuration) {
        // Add custom validation
        validateCustomRules(resourceModel);
        
        // Transform model if needed
        ResourceModel.Builder builder = ResourceModel.builder();
        for (Resource resource : resourceModel.getResources()) {
            // Apply transformations
            Resource transformedResource = transformResource(resource);
            builder.addResource(transformedResource);
        }
        
        return builder.build();
    }
    
    @Override 
    public ResourceModel processSubResource(ResourceModel subResourceModel, Configuration configuration) {
        // Process sub-resources similarly
        return processResourceModel(subResourceModel, configuration);
    }
    
    private void validateCustomRules(ResourceModel model) {
        for (Resource resource : model.getResources()) {
            // Custom validation logic
            if (!isValidResource(resource)) {
                throw new ModelValidationException("Invalid resource: " + resource.getPath());
            }
        }
    }
}

ResourceMethodInvoker

Handler for resource method invocation providing the bridge between the resource model and actual method execution.

/**
 * Resource method invoker handling the execution of resource methods.
 * Implements Endpoint and ResourceInfo interfaces.
 */
public final class ResourceMethodInvoker implements Endpoint, ResourceInfo {
    
    /**
     * Get the resource method being invoked.
     * @return ResourceMethod instance
     */
    public ResourceMethod getResourceMethod();
    
    /**
     * Get the resource class containing the method.
     * @return Resource class
     */
    public Class<?> getResourceClass();
    
    /**
     * Get the Java method being invoked.
     * @return Method instance
     */
    public Method getResourceMethod();
    
    /**
     * Check if the method is asynchronous.
     * @return true if method supports asynchronous execution
     */
    public boolean isManagedAsyncDeclared();
    
    /**
     * Check if the method is suspended.
     * @return true if method execution is suspended
     */
    public boolean isSuspendDeclared();
    
    /**
     * Apply the method invocation.
     * @param requestContext Request context
     * @return Method invocation result
     */
    public Object apply(ContainerRequest requestContext);
}

Parameter

Method parameter representation providing complete parameter metadata for injection and validation.

/**
 * Server-side parameter representation extending the base Parameter class.
 * Provides server-specific parameter information and metadata.
 */
public class Parameter extends org.glassfish.jersey.model.Parameter implements AnnotatedElement {
    
    /**
     * Parameter source enumeration.
     */
    public enum Source {
        PATH, QUERY, HEADER, COOKIE, FORM, MATRIX, BEAN_PARAM, CONTEXT, ENTITY, UNKNOWN
    }
    
    /**
     * Get the parameter source.
     * @return Parameter source type
     */
    public Source getSource();
    
    /**
     * Get the parameter source name.
     * @return Source name (query parameter name, path parameter name, etc.)
     */
    public String getSourceName();
    
    /**
     * Check if parameter has a default value.
     * @return true if default value is specified
     */
    public boolean hasDefaultValue();
    
    /**
     * Get the parameter default value.
     * @return Default value string or null
     */
    public String getDefaultValue();
    
    /**
     * Check if parameter is encoded.
     * @return true if parameter value should not be decoded
     */
    public boolean isEncoded();
    
    /**
     * Get parameter annotations.
     * @return Array of parameter annotations
     */
    public Annotation[] getAnnotations();
    
    /**
     * Get parameter type.
     * @return Parameter class type
     */
    public Class<?> getRawType();
    
    /**
     * Get parameter generic type.
     * @return Parameter generic type
     */
    public Type getType();
}

Usage Examples:

import org.glassfish.jersey.server.model.Parameter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

// Access parameter information
Parameter parameter = getMethodParameter();

Parameter.Source source = parameter.getSource(); // PATH, QUERY, etc.
String sourceName = parameter.getSourceName(); // "id", "name", etc.
boolean hasDefault = parameter.hasDefaultValue();
String defaultValue = parameter.getDefaultValue();

// Type information
Class<?> rawType = parameter.getRawType(); // String.class, Integer.class, etc.
Type genericType = parameter.getType(); // For generic types like List<String>

// Annotations
Annotation[] annotations = parameter.getAnnotations();
for (Annotation annotation : annotations) {
    if (annotation instanceof PathParam) {
        PathParam pathParam = (PathParam) annotation;
        String pathParamValue = pathParam.value();
    }
}

// Encoding information
boolean isEncoded = parameter.isEncoded();

Model Validation

Exception handling and validation for resource models.

/**
 * Exception thrown when resource model validation fails.
 */
public class ModelValidationException extends RuntimeException {
    
    /**
     * Create validation exception with message.
     * @param message Error message
     */
    public ModelValidationException(String message);
    
    /**
     * Create validation exception with message and cause.
     * @param message Error message
     * @param cause Underlying cause
     */
    public ModelValidationException(String message, Throwable cause);
    
    /**
     * Get validation issues.
     * @return List of validation issues that caused the exception
     */
    public List<ResourceModelIssue> getIssues();
}

/**
 * Individual resource model validation issue.
 */
public final class ResourceModelIssue {
    
    /**
     * Get issue severity level.
     * @return Severity (ERROR, WARNING, INFO)
     */
    public Severity getSeverity();
    
    /**
     * Get issue message.
     * @return Descriptive error message
     */
    public String getMessage();
    
    /**
     * Get the source object that caused the issue.
     * @return Source object (Resource, ResourceMethod, etc.)
     */
    public Object getSource();
}

Install with Tessl CLI

npx tessl i tessl/maven-org-glassfish-jersey-core--jersey-server

docs

async-processing.md

configuration-properties.md

index.md

monitoring.md

request-processing.md

resource-configuration.md

resource-model.md

spi.md

wadl.md

tile.json