private String createMessageStr(WebSocketChannel channel, Message message) throws Exception { RequestFormatType requestFormatType = webSocketChannelRequestFormatMap.get(channel); return createMessageStr(message, requestFormatType); }
public WebServer(DaemonConfigTO daemonConfig) throws Exception { this.webSocketChannelRequestFormatMap = Maps.newConcurrentMap(); initCaches(); initEventBus(); initServer(daemonConfig); }
List<UserTO> users = readWebServerUsers(daemonConfigTO); IdentityManager identityManager = new MapIdentityManager(users); String certificateCommonName = webServerConfig.getCertificateCommonName(); if (certificateAutoGenerate && certificateCommonNameChanged(certificateCommonName)) { generateNewKeyPairAndCertificate(certificateCommonName); HttpHandler securityPathHttpHandler = addSecurity(pathHttpHandler, identityManager); SSLContext sslContext = UserConfig.createUserSSLContext();
private void handleFileRequest(HttpServerExchange exchange) throws FileNotFoundException, IOException { String tempFileToken = exchange.getRelativePath().substring("/file/".length()); File tempFile = daemonWebServer.getFileTokenTempFileFromCache(tempFileToken); if (tempFile != null) { logger.log(Level.INFO, "- Temp file: " + tempFileToken); IOUtils.copy(new FileInputStream(tempFile), exchange.getOutputStream()); exchange.endExchange(); } else { logger.log(Level.WARNING, "Invalid request received; Cannot find file token " + tempFileToken); eventBus.post(new BadRequestResponse(-1, "Invalid request.")); } } }
daemonWebServer.addClientChannel(channel, requestFormatType);
private void sendTo(WebSocketChannel clientChannel, Message message) throws Exception { String messageStr = createMessageStr(clientChannel, message); logger.log(Level.INFO, "Sending message to " + clientChannel + ": " + messageStr); WebSockets.sendText(messageStr, clientChannel, null); }
private String createMessageStr(Response response) throws Exception { RequestFormatType requestFormatType = requestIdRestFormatCache.getIfPresent(response.getRequestId()); return createMessageStr(response, requestFormatType); }
private void sendTo(HttpServerExchange serverExchange, Response response) throws Exception { String responseStr = createMessageStr(response); logger.log(Level.INFO, "Sending message to " + serverExchange.getHostAndPort() + ": " + responseStr); serverExchange.getResponseSender().send(responseStr); serverExchange.endExchange(); }