Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][ws] Check the validity of config before start websocket service #22231

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
import org.apache.pulsar.client.api.CompressionType;
Expand Down Expand Up @@ -118,11 +119,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 @@ -75,9 +75,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 @@ -109,6 +107,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);

}
Loading