@Override
public void openClientSocket(String url, ClientEndpointConfig cec, Map<String, Object> properties, ClientEngine clientEngine) throws DeploymentException, IOException {
final UpgradeRequest upgradeRequest = clientEngine.createUpgradeRequest(URI.create(url), null);
final ServerApplicationConfig serverApplicationConfig = getServerApplicationConfig(cec);
final TyrusServerContainer tyrusServerContainer = new TyrusServerContainer(serverApplicationConfig) {
private final WebSocketEngine webSocketEngine = TyrusWebSocketEngine.builder(getClientManager()).build();
@Override
public void register(Class<?> endpointClass) throws DeploymentException {
webSocketEngine.register(endpointClass, "/");
}
@Override
public void register(ServerEndpointConfig serverEndpointConfig) throws DeploymentException {
webSocketEngine.register(serverEndpointConfig, "/");
}
@Override
public WebSocketEngine getWebSocketEngine() {
return webSocketEngine;
}
};
tyrusServerContainer.doneDeployment();
// placeholder values, not used anywhere in this case.
tyrusServerContainer.start("/inmemory", 0);
final TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
StringBuilder sb = new StringBuilder();
sb.append(upgradeRequest.getRequestURI().getPath());
if (upgradeRequest.getRequestURI().getQuery() != null) {
sb.append('?').append(upgradeRequest.getRequestURI().getQuery());
}
if (sb.length() == 0) {
sb.append('/');
}
final RequestContext requestContext = new RequestContext.Builder().requestURI(URI.create(sb.toString())).build();
requestContext.getHeaders().putAll(upgradeRequest.getHeaders());
final WebSocketEngine.UpgradeInfo upgradeInfo = tyrusServerContainer.getWebSocketEngine().upgrade(requestContext, upgradeResponse);
switch (upgradeInfo.getStatus()) {
case HANDSHAKE_FAILED:
throw new DeploymentException("");
case NOT_APPLICABLE:
throw new DeploymentException("");