Skip to content

Commit

Permalink
Check the validity of config before start websocket service (apache#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
Technoboy- committed Mar 15, 2024
1 parent 7130248 commit 58e28bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.LongAdder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
import org.apache.pulsar.client.api.CompressionType;
import org.apache.pulsar.client.api.HashingScheme;
Expand Down Expand Up @@ -100,11 +101,18 @@ public ProducerHandler(WebSocketService service, HttpServletRequest request, Ser
request.getRemotePort(), topic);
}
} catch (Exception e) {
log.warn("[{}:{}] Failed in creating producer on topic {}: {}", request.getRemoteAddr(),
request.getRemotePort(), topic, e.getMessage());
int errorCode = getErrorCode(e);
boolean isKnownError = errorCode != HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
if (isKnownError) {
log.warn("[{}:{}] Failed in creating producer on topic {}: {}", request.getRemoteAddr(),
request.getRemotePort(), topic, e.getMessage());
} else {
log.error("[{}:{}] Failed in creating producer on topic {}: {}", request.getRemoteAddr(),
request.getRemotePort(), topic, e.getMessage(), e);
}

try {
response.sendError(getErrorCode(e), getErrorMessage(e));
response.sendError(errorCode, getErrorMessage(e));
} catch (IOException e1) {
log.warn("[{}:{}] Failed to send error: {}", request.getRemoteAddr(), request.getRemotePort(),
e1.getMessage(), e1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public static void main(String[] args) throws Exception {
try {
// load config file and start proxy service
String configFile = args[0];
log.info("Loading configuration from {}", configFile);
WebSocketProxyConfiguration config = PulsarConfigurationLoader.create(configFile,
WebSocketProxyConfiguration.class);
WebSocketProxyConfiguration config = loadConfig(configFile);
ProxyServer proxyServer = new ProxyServer(config);
WebSocketService service = new WebSocketService(config);
start(proxyServer, service);
Expand Down Expand Up @@ -106,6 +104,14 @@ public static void start(ProxyServer proxyServer, WebSocketService service) thro
service.start();
}

private static WebSocketProxyConfiguration loadConfig(String configFile) throws Exception {
log.info("Loading configuration from {}", configFile);
WebSocketProxyConfiguration config = PulsarConfigurationLoader.create(configFile,
WebSocketProxyConfiguration.class);
PulsarConfigurationLoader.isComplete(config);
return config;
}

private static final Logger log = LoggerFactory.getLogger(WebSocketServiceStarter.class);

}

0 comments on commit 58e28bb

Please sign in to comment.