or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

data-transfer-objects.mdhistory-server.mdindex.mdjar-management.mdrest-api-specifications.mdutilities-extensions.mdweb-server-bootstrap.md

web-server-bootstrap.mddocs/

0

# Web Server Bootstrap

1

2

Core infrastructure for setting up and managing the Netty-based web server that provides the foundation for embedding Flink's web interface in applications. The WebFrontendBootstrap class handles all aspects of server lifecycle management.

3

4

## Core Imports

5

6

```java

7

import org.apache.flink.runtime.webmonitor.utils.WebFrontendBootstrap;

8

import org.apache.flink.runtime.rest.handler.router.Router;

9

import org.apache.flink.runtime.io.network.netty.SSLHandlerFactory;

10

import org.apache.flink.configuration.Configuration;

11

import org.apache.flink.shaded.netty4.io.netty.bootstrap.ServerBootstrap;

12

import org.slf4j.Logger;

13

import java.io.File;

14

```

15

16

## Capabilities

17

18

### WebFrontendBootstrap

19

20

Main bootstrap class for setting up the Netty-based web server with routing, SSL support, and configuration management.

21

22

```java { .api }

23

/**

24

* Bootstrap class for the Netty-based web server providing Flink's web interface.

25

* Handles server setup, configuration, and lifecycle management.

26

*/

27

public class WebFrontendBootstrap {

28

/**

29

* Create a new web frontend bootstrap with full configuration.

30

*

31

* @param router The router for handling HTTP requests

32

* @param log Logger instance for server operations

33

* @param directory Directory for file uploads (JAR files)

34

* @param serverSSLFactory Factory for SSL handlers, null for HTTP-only

35

* @param configuredAddress Server bind address (null for auto-detect)

36

* @param configuredPort Server port number

37

* @param config Flink configuration

38

* @throws InterruptedException If server binding is interrupted

39

* @throws UnknownHostException If address resolution fails

40

*/

41

public WebFrontendBootstrap(

42

Router router,

43

Logger log,

44

File directory,

45

@Nullable SSLHandlerFactory serverSSLFactory,

46

String configuredAddress,

47

int configuredPort,

48

Configuration config

49

) throws InterruptedException, UnknownHostException;

50

51

/**

52

* Get the underlying Netty ServerBootstrap for advanced configuration.

53

*

54

* @return The configured ServerBootstrap instance

55

*/

56

public ServerBootstrap getBootstrap();

57

58

/**

59

* Get the actual port the server is bound to.

60

* May differ from configured port if 0 was specified for auto-assignment.

61

*

62

* @return The server port number

63

*/

64

public int getServerPort();

65

66

/**

67

* Get the REST server address for client connections.

68

*

69

* @return The server address as a string

70

*/

71

public String getRestAddress();

72

73

/**

74

* Gracefully shutdown the web server and release all resources.

75

* Blocks until shutdown is complete.

76

*/

77

public void shutdown();

78

}

79

```

80

81

**Usage Examples:**

82

83

```java

84

import org.apache.flink.runtime.webmonitor.utils.WebFrontendBootstrap;

85

import org.apache.flink.configuration.Configuration;

86

import org.apache.flink.shaded.netty4.io.netty.handler.logging.LoggingHandler;

87

import java.io.File;

88

89

// Basic HTTP server setup

90

Configuration config = new Configuration();

91

File uploadDir = new File("/tmp/flink-uploads");

92

uploadDir.mkdirs();

93

94

WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(

95

router, // Configured router with handlers

96

log, // SLF4J logger instance

97

uploadDir, // Directory for JAR uploads

98

null, // No SSL

99

"0.0.0.0", // Bind to all interfaces

100

8081, // Port number

101

config // Flink configuration

102

);

103

104

// Start server and get actual port

105

int actualPort = bootstrap.getServerPort();

106

String address = bootstrap.getRestAddress();

107

System.out.println("Server running at " + address + ":" + actualPort);

108

109

// Shutdown when application terminates

110

Runtime.getRuntime().addShutdownHook(new Thread(bootstrap::shutdown));

111

```

112

113

```java

114

// SSL-enabled server setup

115

import org.apache.flink.runtime.net.SSLHandlerFactory;

116

117

SSLHandlerFactory sslFactory = createSSLHandlerFactory(); // Custom SSL setup

118

WebFrontendBootstrap sslBootstrap = new WebFrontendBootstrap(

119

router,

120

log,

121

uploadDir,

122

sslFactory, // Enable SSL

123

"localhost",

124

8443, // HTTPS port

125

config

126

);

127

```

128

129

### Server Lifecycle Management

130

131

The WebFrontendBootstrap handles complete server lifecycle including startup, configuration, and graceful shutdown.

132

133

```java { .api }

134

/**

135

* Get the actual port the server is bound to.

136

* Useful when port 0 is specified for automatic port assignment.

137

*

138

* @return The server port number

139

*/

140

public int getServerPort();

141

142

/**

143

* Get the REST server address that clients should connect to.

144

*

145

* @return The server address as a string

146

*/

147

public String getRestAddress();

148

149

/**

150

* Gracefully shutdown the web server and release all resources.

151

* This method blocks until the shutdown process is complete.

152

*/

153

public void shutdown();

154

```

155

156

### Integration with Router

157

158

The WebFrontendBootstrap integrates with a Router instance that defines the HTTP request handling logic.

159

160

**Usage Example:**

161

162

```java

163

import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.router.Router;

164

165

// Create router with handlers

166

Router router = new Router();

167

router.GET("/api/overview", overviewHandler);

168

router.POST("/jars/upload", jarUploadHandler);

169

router.GET("/jars", jarListHandler);

170

171

// Use router with bootstrap

172

WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(

173

router, // Configured router

174

log,

175

uploadDir,

176

null,

177

"localhost",

178

8081,

179

config

180

);

181

```

182

183

### Configuration Integration

184

185

The bootstrap accepts a Flink Configuration object for server-wide settings and integrates with Flink's configuration system.

186

187

**Configuration Examples:**

188

189

```java

190

import org.apache.flink.configuration.Configuration;

191

import org.apache.flink.configuration.WebOptions;

192

193

Configuration config = new Configuration();

194

config.setString(WebOptions.ADDRESS, "0.0.0.0");

195

config.setInteger(WebOptions.PORT, 8081);

196

config.setString(WebOptions.UPLOAD_DIR, "/tmp/flink-web");

197

198

WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(

199

router,

200

log,

201

new File(config.getString(WebOptions.UPLOAD_DIR)),

202

null,

203

config.getString(WebOptions.ADDRESS),

204

config.getInteger(WebOptions.PORT),

205

config

206

);

207

```

208

209

## Error Handling

210

211

The WebFrontendBootstrap includes built-in error handling for common server setup issues:

212

213

- **Port binding failures**: Automatic handling of port conflicts

214

- **SSL configuration errors**: Proper error reporting for SSL setup issues

215

- **Upload directory access**: Validation and creation of upload directories

216

- **Resource cleanup**: Guaranteed resource cleanup on shutdown