Jersey core server implementation for building RESTful Web Services with JAX-RS.
—
Web Application Description Language (WADL) generation and configuration for automatic API documentation. Provides machine-readable descriptions of RESTful web services including resources, methods, parameters, and representations.
Core WADL context providing access to WADL generation and configuration.
/**
* WADL application context providing access to WADL generation functionality.
*/
public interface WadlApplicationContext {
/**
* Get the WADL application representation.
* @return WADL Application object
*/
Application getApplication();
/**
* Get the WADL grammars section.
* @return Grammars containing schema definitions
*/
Grammars getGrammars();
/**
* Set whether WADL generation is enabled.
* @param wadlGenerationEnabled true to enable WADL generation
*/
void setWadlGenerationEnabled(boolean wadlGenerationEnabled);
/**
* Check if WADL generation is enabled.
* @return true if WADL generation is enabled
*/
boolean isWadlGenerationEnabled();
/**
* Get the WADL generator configuration.
* @return WadlGeneratorConfig instance
*/
WadlGeneratorConfig getWadlGeneratorConfig();
/**
* Set the WADL generator configuration.
* @param wadlGeneratorConfig Configuration to set
*/
void setWadlGeneratorConfig(WadlGeneratorConfig wadlGeneratorConfig);
}Interface for generating WADL documents from Jersey resource models.
/**
* WADL generator interface for creating WADL documents.
*/
public interface WadlGenerator {
/**
* Initialize the WADL generator.
*/
void init();
/**
* Create the root WADL application element.
* @return WADL Application object
*/
Application createApplication();
/**
* Create WADL resources element.
* @return WADL Resources container
*/
Resources createResources();
/**
* Create WADL resource element from Jersey resource.
* @param resource Jersey Resource model
* @param path Resource path
* @return WADL Resource element
*/
Resource createResource(org.glassfish.jersey.server.model.Resource resource, String path);
/**
* Create WADL method element from Jersey resource method.
* @param resource Jersey Resource model
* @param resourceMethod Jersey ResourceMethod model
* @return WADL Method element
*/
Method createMethod(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod);
/**
* Create WADL request element.
* @param resource Jersey Resource model
* @param resourceMethod Jersey ResourceMethod model
* @return WADL Request element
*/
Request createRequest(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod);
/**
* Create WADL response element.
* @param resource Jersey Resource model
* @param resourceMethod Jersey ResourceMethod model
* @return WADL Response element
*/
Response createResponse(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod);
/**
* Create WADL parameter element.
* @param resource Jersey Resource model
* @param resourceMethod Jersey ResourceMethod model
* @param parameter Jersey Parameter model
* @return WADL Param element
*/
Param createParam(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod,
org.glassfish.jersey.server.model.Parameter parameter);
/**
* Create WADL representation element.
* @param resource Jersey Resource model
* @param resourceMethod Jersey ResourceMethod model
* @param mediaType Media type for the representation
* @return WADL Representation element
*/
Representation createRequestRepresentation(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod,
MediaType mediaType);
/**
* Create WADL response representation element.
* @param resource Jersey Resource model
* @param resourceMethod Jersey ResourceMethod model
* @param mediaType Media type for the representation
* @return WADL Representation element
*/
Representation createResponseRepresentation(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod,
MediaType mediaType);
/**
* Get external grammars to include.
* @return External grammars or null
*/
ExternalGrammarDefinition createExternalGrammar();
/**
* Add any additional content to the WADL.
* @param r Jersey Resource model
* @param rm Jersey ResourceMethod model
* @param existingItems Existing WADL items
* @return Additional WADL elements to include
*/
List<Object> createGenericResource(org.glassfish.jersey.server.model.Resource r,
org.glassfish.jersey.server.model.ResourceMethod rm,
List<Object> existingItems);
}Jersey feature for enabling and configuring WADL support.
/**
* WADL feature for enabling WADL generation in Jersey applications.
*/
public class WadlFeature implements Feature {
/**
* Default constructor creating WADL feature with default configuration.
*/
public WadlFeature();
/**
* Configure the feature in the given context.
* @param context Feature context for configuration
* @return true if feature was successfully configured
*/
@Override
public boolean configure(FeatureContext context);
/**
* Disable WADL generation.
* @return WadlFeature with WADL generation disabled
*/
public static WadlFeature disableWadl();
/**
* Enable WADL generation with default configuration.
* @return WadlFeature with WADL generation enabled
*/
public static WadlFeature enableWadl();
}Usage Examples:
import org.glassfish.jersey.server.wadl.WadlFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
// Enable WADL in ResourceConfig
ResourceConfig config = new ResourceConfig()
.packages("com.example.resources")
.register(WadlFeature.class);
// Or enable WADL with specific configuration
ResourceConfig config2 = new ResourceConfig()
.packages("com.example.resources")
.register(WadlFeature.enableWadl());
// Disable WADL generation
ResourceConfig config3 = new ResourceConfig()
.packages("com.example.resources")
.register(WadlFeature.disableWadl());
// Configure WADL via properties
ResourceConfig config4 = new ResourceConfig()
.packages("com.example.resources")
.property(ServerProperties.WADL_FEATURE_DISABLE, false); // Enable WADL
// Access WADL at runtime
@Path("/application.wadl")
public class WadlResource {
@Context
private WadlApplicationContext wadlContext;
@GET
@Produces("application/xml")
public Application getWadl() {
return wadlContext.getApplication();
}
}Complete WADL model representation classes for building WADL documents.
/**
* WADL Application root element.
*/
public class Application {
/**
* Get the doc elements for documentation.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get the grammars section.
* @return Grammars element
*/
public Grammars getGrammars();
/**
* Set the grammars section.
* @param value Grammars to set
*/
public void setGrammars(Grammars value);
/**
* Get the resources collections.
* @return List of Resources elements
*/
public List<Resources> getResources();
/**
* Get resource types.
* @return List of ResourceType elements
*/
public List<ResourceType> getResourceType();
/**
* Get methods defined at application level.
* @return List of Method elements
*/
public List<Method> getMethod();
/**
* Get representations defined at application level.
* @return List of Representation elements
*/
public List<Representation> getRepresentation();
/**
* Get fault representations.
* @return List of fault Representation elements
*/
public List<Representation> getFault();
}
/**
* WADL Resources collection element.
*/
public class Resources {
/**
* Get documentation elements.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get resource elements.
* @return List of Resource elements
*/
public List<Resource> getResource();
/**
* Get base URI for these resources.
* @return Base URI string
*/
public String getBase();
/**
* Set base URI for these resources.
* @param value Base URI to set
*/
public void setBase(String value);
}
/**
* WADL Resource element representing a REST resource.
*/
public class Resource {
/**
* Get documentation elements.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get parameters for this resource.
* @return List of Param elements
*/
public List<Param> getParam();
/**
* Get methods available on this resource.
* @return List of Method elements
*/
public List<Method> getMethod();
/**
* Get sub-resources.
* @return List of Resource elements
*/
public List<Resource> getResource();
/**
* Get resource path.
* @return Path string
*/
public String getPath();
/**
* Set resource path.
* @param value Path to set
*/
public void setPath(String value);
/**
* Get resource ID.
* @return Resource ID string
*/
public String getId();
/**
* Set resource ID.
* @param value ID to set
*/
public void setId(String value);
/**
* Get resource type references.
* @return List of resource type references
*/
public List<String> getType();
}
/**
* WADL Method element representing an HTTP method.
*/
public class Method {
/**
* Get documentation elements.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get request definition.
* @return Request element
*/
public Request getRequest();
/**
* Set request definition.
* @param value Request to set
*/
public void setRequest(Request value);
/**
* Get response definitions.
* @return List of Response elements
*/
public List<Response> getResponse();
/**
* Get HTTP method name.
* @return HTTP method (GET, POST, etc.)
*/
public String getName();
/**
* Set HTTP method name.
* @param value Method name to set
*/
public void setName(String value);
/**
* Get method ID.
* @return Method ID string
*/
public String getId();
/**
* Set method ID.
* @param value ID to set
*/
public void setId(String value);
}
/**
* WADL Request element describing request structure.
*/
public class Request {
/**
* Get documentation elements.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get request parameters.
* @return List of Param elements
*/
public List<Param> getParam();
/**
* Get request representations.
* @return List of Representation elements
*/
public List<Representation> getRepresentation();
}
/**
* WADL Response element describing response structure.
*/
public class Response {
/**
* Get documentation elements.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get response parameters.
* @return List of Param elements
*/
public List<Param> getParam();
/**
* Get response representations.
* @return List of Representation elements
*/
public List<Representation> getRepresentation();
/**
* Get fault representations.
* @return List of fault Representation elements
*/
public List<Representation> getFault();
/**
* Get HTTP status codes.
* @return List of status codes
*/
public List<Long> getStatus();
}
/**
* WADL Param element describing parameters.
*/
public class Param {
/**
* Get documentation elements.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get parameter options.
* @return List of Option elements
*/
public List<Option> getOption();
/**
* Get link to parameter definition.
* @return Link element
*/
public Link getLink();
/**
* Set link to parameter definition.
* @param value Link to set
*/
public void setLink(Link value);
/**
* Get parameter name.
* @return Parameter name
*/
public String getName();
/**
* Set parameter name.
* @param value Name to set
*/
public void setName(String value);
/**
* Get parameter style.
* @return ParamStyle enumeration value
*/
public ParamStyle getStyle();
/**
* Set parameter style.
* @param value ParamStyle to set
*/
public void setStyle(ParamStyle value);
/**
* Get parameter type.
* @return QName representing parameter type
*/
public QName getType();
/**
* Set parameter type.
* @param value Type to set
*/
public void setType(QName value);
/**
* Get default value.
* @return Default value string
*/
public String getDefault();
/**
* Set default value.
* @param value Default value to set
*/
public void setDefault(String value);
/**
* Check if parameter is required.
* @return true if required
*/
public boolean isRequired();
/**
* Set whether parameter is required.
* @param value true if required
*/
public void setRequired(boolean value);
/**
* Check if parameter is repeating.
* @return true if repeating
*/
public boolean isRepeating();
/**
* Set whether parameter is repeating.
* @param value true if repeating
*/
public void setRepeating(boolean value);
}
/**
* Parameter style enumeration.
*/
public enum ParamStyle {
QUERY, HEADER, TEMPLATE, MATRIX, FORM, PLAIN
}
/**
* WADL Representation element describing data representations.
*/
public class Representation {
/**
* Get documentation elements.
* @return List of Doc elements
*/
public List<Doc> getDoc();
/**
* Get representation parameters.
* @return List of Param elements
*/
public List<Param> getParam();
/**
* Get media type.
* @return Media type string
*/
public String getMediaType();
/**
* Set media type.
* @param value Media type to set
*/
public void setMediaType(String value);
/**
* Get element name.
* @return QName of element
*/
public QName getElement();
/**
* Set element name.
* @param value Element QName to set
*/
public void setElement(QName value);
/**
* Get profile URI.
* @return Profile URI string
*/
public String getProfile();
/**
* Set profile URI.
* @param value Profile URI to set
*/
public void setProfile(String value);
}Usage Examples:
import com.sun.research.ws.wadl.*;
import org.glassfish.jersey.server.wadl.WadlGenerator;
// Custom WADL generator implementation
public class CustomWadlGenerator implements WadlGenerator {
@Override
public void init() {
// Initialize generator
}
@Override
public Application createApplication() {
Application app = new Application();
// Add application-level documentation
Doc doc = new Doc();
doc.setTitle("My REST API");
doc.getContent().add("This is a comprehensive REST API for managing resources.");
app.getDoc().add(doc);
return app;
}
@Override
public Resources createResources() {
Resources resources = new Resources();
resources.setBase("http://localhost:8080/api");
// Add resources documentation
Doc doc = new Doc();
doc.setTitle("API Resources");
doc.getContent().add("Collection of all available API resources.");
resources.getDoc().add(doc);
return resources;
}
@Override
public Resource createResource(org.glassfish.jersey.server.model.Resource resource, String path) {
Resource wadlResource = new Resource();
wadlResource.setPath(path);
wadlResource.setId(generateResourceId(resource));
// Add resource documentation
Doc doc = new Doc();
doc.setTitle("Resource: " + path);
doc.getContent().add("Operations available on " + path);
wadlResource.getDoc().add(doc);
return wadlResource;
}
@Override
public Method createMethod(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod) {
Method wadlMethod = new Method();
wadlMethod.setName(resourceMethod.getHttpMethod());
wadlMethod.setId(generateMethodId(resourceMethod));
// Add method documentation
Doc doc = new Doc();
doc.setTitle(resourceMethod.getHttpMethod() + " " + resource.getPath());
doc.getContent().add("Performs " + resourceMethod.getHttpMethod() + " operation");
wadlMethod.getDoc().add(doc);
return wadlMethod;
}
@Override
public Request createRequest(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod) {
Request request = new Request();
// Add parameters
for (org.glassfish.jersey.server.model.Parameter param : resourceMethod.getInvocable().getParameters()) {
Param wadlParam = createParam(resource, resourceMethod, param);
request.getParam().add(wadlParam);
}
return request;
}
@Override
public Param createParam(org.glassfish.jersey.server.model.Resource resource,
org.glassfish.jersey.server.model.ResourceMethod resourceMethod,
org.glassfish.jersey.server.model.Parameter parameter) {
Param wadlParam = new Param();
wadlParam.setName(parameter.getSourceName());
wadlParam.setRequired(!parameter.hasDefaultValue());
// Set parameter style based on source
switch (parameter.getSource()) {
case PATH:
wadlParam.setStyle(ParamStyle.TEMPLATE);
break;
case QUERY:
wadlParam.setStyle(ParamStyle.QUERY);
break;
case HEADER:
wadlParam.setStyle(ParamStyle.HEADER);
break;
case FORM:
wadlParam.setStyle(ParamStyle.FORM);
break;
default:
wadlParam.setStyle(ParamStyle.PLAIN);
}
// Set default value if available
if (parameter.hasDefaultValue()) {
wadlParam.setDefault(parameter.getDefaultValue());
}
return wadlParam;
}
// Additional method implementations...
private String generateResourceId(org.glassfish.jersey.server.model.Resource resource) {
return "resource_" + resource.getPath().replaceAll("[^a-zA-Z0-9]", "_");
}
private String generateMethodId(org.glassfish.jersey.server.model.ResourceMethod method) {
return method.getHttpMethod().toLowerCase() + "_" + method.getInvocable().getHandlingMethod().getName();
}
}
// Register custom WADL generator
ResourceConfig config = new ResourceConfig()
.packages("com.example.resources")
.register(WadlFeature.class)
.property(ServerProperties.WADL_GENERATOR_CONFIG, CustomWadlGenerator.class.getName());Install with Tessl CLI
npx tessl i tessl/maven-org-glassfish-jersey-core--jersey-server