or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

authentication.mdcatalina-core.mdconnectors.mdembedded-tomcat.mdindex.mdlogging.mdservlet-api.mdsession-management.mdutilities.mdvalves.mdweb-resources.md

web-resources.mddocs/

0

# Web Resources

1

2

Resource management system for serving static content, loading classes, accessing JAR files, and managing web application resources. Supports multiple resource sets, caching, virtual directories, overlays, and efficient resource lookup.

3

4

## Capabilities

5

6

### WebResourceRoot

7

8

Root resource management interface for a web application.

9

10

```java { .api }

11

public interface WebResourceRoot extends Lifecycle {

12

// Resource lookup

13

WebResource getResource(String path);

14

WebResource getClassLoaderResource(String path);

15

WebResource[] getResources(String path);

16

WebResource[] getClassLoaderResources(String path);

17

WebResource[] listResources(String path);

18

19

// Resource sets

20

void addPreResources(WebResourceSet webResourceSet);

21

WebResourceSet[] getPreResources();

22

void addJarResources(WebResourceSet webResourceSet);

23

WebResourceSet[] getJarResources();

24

void addPostResources(WebResourceSet webResourceSet);

25

WebResourceSet[] getPostResources();

26

void createWebResourceSet(ResourceSetType type, String webAppMount, String base,

27

String archivePath, String internalPath);

28

void createWebResourceSet(ResourceSetType type, String webAppMount, URL url, String internalPath);

29

30

// Context

31

Context getContext();

32

void setContext(Context context);

33

34

// Caching

35

void setCachingAllowed(boolean cachingAllowed);

36

boolean isCachingAllowed();

37

void setCacheTtl(long ttl);

38

long getCacheTtl();

39

void setCacheMaxSize(long cacheMaxSize);

40

long getCacheMaxSize();

41

void setCacheObjectMaxSize(int cacheObjectMaxSize);

42

int getCacheObjectMaxSize();

43

44

// Archive indexing

45

void setArchiveIndexStrategy(String archiveIndexStrategy);

46

String getArchiveIndexStrategy();

47

48

// JAR scanning

49

void registerTrackedResource(TrackedWebResource trackedResource);

50

void deregisterTrackedResource(TrackedWebResource trackedResource);

51

52

// Directory operations

53

boolean mkdir(String path);

54

boolean write(String path, InputStream is, boolean overwrite);

55

56

// Resource listing

57

void backgroundProcess();

58

59

// Additional resource methods

60

String[] list(String path);

61

Set<String> listWebAppPaths(String path);

62

63

// Symbolic link configuration

64

void setAllowLinking(boolean allowLinking);

65

boolean getAllowLinking();

66

67

// File tracking

68

void setTrackLockedFiles(boolean trackLockedFiles);

69

boolean getTrackLockedFiles();

70

71

// Archive index strategy

72

ArchiveIndexStrategy getArchiveIndexStrategyEnum();

73

74

// Base URLs

75

List<URL> getBaseUrls();

76

77

// Cache management

78

void gc();

79

default CacheStrategy getCacheStrategy();

80

default void setCacheStrategy(CacheStrategy strategy);

81

82

// Read-only mode

83

default void setReadOnly(boolean readOnly);

84

default boolean isReadOnly();

85

}

86

```

87

88

### ResourceSetType Enum

89

90

Type of web resource set for specifying resource ordering.

91

92

```java { .api }

93

public enum ResourceSetType {

94

PRE, // Pre-resources (highest priority)

95

RESOURCE_JAR, // Resource JARs

96

POST, // Post-resources

97

CLASSES_JAR; // Classes JARs (lowest priority)

98

}

99

```

100

101

### WebResource

102

103

Represents a file or directory within a web application.

104

105

```java { .api }

106

public interface WebResource {

107

// Timing

108

long getLastModified();

109

String getLastModifiedHttp();

110

long getCreation();

111

112

// Existence

113

boolean exists();

114

boolean isVirtual();

115

boolean isDirectory();

116

boolean isFile();

117

118

// Operations

119

boolean delete();

120

121

// Identity

122

String getName();

123

long getContentLength();

124

String getCanonicalPath();

125

String getWebappPath();

126

String getETag();

127

URL getURL();

128

CodeSource getCodeBase();

129

130

// Content

131

boolean canRead();

132

byte[] getContent();

133

InputStream getInputStream();

134

135

// Certificates

136

Certificate[] getCertificates();

137

Manifest getManifest();

138

139

// MIME type

140

void setMimeType(String mimeType);

141

String getMimeType();

142

143

// Resource root

144

WebResourceRoot getWebResourceRoot();

145

}

146

```

147

148

### WebResourceSet

149

150

Set of resources from a specific location.

151

152

```java { .api }

153

public interface WebResourceSet extends Lifecycle {

154

// Resource root

155

void setRoot(WebResourceRoot root);

156

157

// Resource lookup

158

WebResource getResource(String path);

159

String[] list(String path);

160

Set<String> listWebAppPaths(String path);

161

162

// Directory operations

163

boolean mkdir(String path);

164

boolean write(String path, InputStream is, boolean overwrite);

165

166

// Configuration

167

void setReadOnly(boolean readOnly);

168

boolean isReadOnly();

169

170

// Classloader resource

171

boolean getClassLoaderOnly();

172

void setClassLoaderOnly(boolean classLoaderOnly);

173

boolean getStaticOnly();

174

void setStaticOnly(boolean staticOnly);

175

176

// JAR/Archive handling

177

URL getBaseUrl();

178

}

179

```

180

181

## Usage Examples

182

183

### Configure Resource Caching

184

185

```java

186

import org.apache.catalina.startup.Tomcat;

187

import org.apache.catalina.Context;

188

import org.apache.catalina.WebResourceRoot;

189

import org.apache.catalina.webresources.StandardRoot;

190

191

public class ResourceCachingExample {

192

public static void main(String[] args) throws Exception {

193

Tomcat tomcat = new Tomcat();

194

tomcat.setPort(8080);

195

196

Context ctx = tomcat.addWebapp("/", "/path/to/webapp");

197

198

// Configure resource caching

199

StandardRoot resources = new StandardRoot(ctx);

200

resources.setCachingAllowed(true);

201

resources.setCacheTtl(5000); // 5 seconds

202

resources.setCacheMaxSize(10240); // 10MB

203

resources.setCacheObjectMaxSize(512); // 512KB

204

205

ctx.setResources(resources);

206

207

tomcat.start();

208

tomcat.getServer().await();

209

}

210

}

211

```

212