use of org.eclipse.jetty.websocket.api.UpgradeException in project incubator-pulsar by apache.
the class ProxyPublishConsumeTest method producerBacklogQuotaExceededTest.
@Test(timeOut = 30000)
public void producerBacklogQuotaExceededTest() throws Exception {
admin.namespaces().createNamespace("my-property/use/ns-ws-quota");
admin.namespaces().setBacklogQuota("my-property/use/ns-ws-quota", new BacklogQuota(10, BacklogQuota.RetentionPolicy.producer_request_hold));
final String topic = "my-property/use/ns-ws-quota/my-topic5";
final String subscription = "my-sub";
final String consumerUri = "ws://localhost:" + port + "/ws/consumer/persistent/" + topic + "/" + subscription;
final String producerUri = "ws://localhost:" + port + "/ws/producer/persistent/" + topic;
URI consumeUri = URI.create(consumerUri);
URI produceUri = URI.create(producerUri);
WebSocketClient consumeClient = new WebSocketClient();
WebSocketClient produceClient1 = new WebSocketClient();
WebSocketClient produceClient2 = new WebSocketClient();
SimpleConsumerSocket consumeSocket = new SimpleConsumerSocket();
SimpleProducerSocket produceSocket1 = new SimpleProducerSocket();
SimpleProducerSocket produceSocket2 = new SimpleProducerSocket();
// Create subscription
try {
consumeClient.start();
ClientUpgradeRequest consumeRequest = new ClientUpgradeRequest();
Future<Session> consumerFuture = consumeClient.connect(consumeSocket, consumeUri, consumeRequest);
consumerFuture.get();
} finally {
stopWebSocketClient(consumeClient);
}
// Fill the backlog
try {
produceClient1.start();
ClientUpgradeRequest produceRequest = new ClientUpgradeRequest();
Future<Session> producerFuture = produceClient1.connect(produceSocket1, produceUri, produceRequest);
producerFuture.get();
produceSocket1.sendMessage(100);
} finally {
stopWebSocketClient(produceClient1);
}
Thread.sleep((TIME_TO_CHECK_BACKLOG_QUOTA + 1) * 1000);
// New producer fails to connect
try {
produceClient2.start();
ClientUpgradeRequest produceRequest = new ClientUpgradeRequest();
Future<Session> producerFuture = produceClient2.connect(produceSocket2, produceUri, produceRequest);
producerFuture.get();
Assert.fail("should fail: backlog quota exceeded");
} catch (Exception e) {
// Expected
Assert.assertTrue(e.getCause() instanceof UpgradeException);
Assert.assertEquals(((UpgradeException) e.getCause()).getResponseStatusCode(), HttpServletResponse.SC_SERVICE_UNAVAILABLE);
} finally {
stopWebSocketClient(produceClient2);
admin.persistentTopics().skipAllMessages("persistent://" + topic, subscription);
admin.persistentTopics().delete("persistent://" + topic);
admin.namespaces().removeBacklogQuota("my-property/use/ns-ws-quota");
admin.namespaces().deleteNamespace("my-property/use/ns-ws-quota");
}
}
use of org.eclipse.jetty.websocket.api.UpgradeException in project incubator-pulsar by apache.
the class ProxyPublishConsumeTest method conflictingProducerTest.
@Test(timeOut = 10000)
public void conflictingProducerTest() throws Exception {
final String producerUri = "ws://localhost:" + port + "/ws/producer/persistent/my-property/use/my-ns/my-topic4?producerName=my-producer";
URI produceUri = URI.create(producerUri);
WebSocketClient produceClient1 = new WebSocketClient();
WebSocketClient produceClient2 = new WebSocketClient();
SimpleProducerSocket produceSocket1 = new SimpleProducerSocket();
SimpleProducerSocket produceSocket2 = new SimpleProducerSocket();
try {
produceClient1.start();
ClientUpgradeRequest produceRequest1 = new ClientUpgradeRequest();
Future<Session> producerFuture1 = produceClient1.connect(produceSocket1, produceUri, produceRequest1);
producerFuture1.get();
try {
produceClient2.start();
ClientUpgradeRequest produceRequest2 = new ClientUpgradeRequest();
Future<Session> producerFuture2 = produceClient2.connect(produceSocket2, produceUri, produceRequest2);
producerFuture2.get();
Assert.fail("should fail: conflicting producer name");
} catch (Exception e) {
// Expected
Assert.assertTrue(e.getCause() instanceof UpgradeException);
Assert.assertEquals(((UpgradeException) e.getCause()).getResponseStatusCode(), HttpServletResponse.SC_CONFLICT);
} finally {
stopWebSocketClient(produceClient2);
}
} finally {
stopWebSocketClient(produceClient1);
}
}
use of org.eclipse.jetty.websocket.api.UpgradeException in project incubator-pulsar by apache.
the class ProxyPublishConsumeTest method conflictingConsumerTest.
@Test(timeOut = 10000)
public void conflictingConsumerTest() throws Exception {
final String consumerUri = "ws://localhost:" + port + "/ws/consumer/persistent/my-property/use/my-ns/my-topic3/sub1?subscriptionType=Exclusive";
URI consumeUri = URI.create(consumerUri);
WebSocketClient consumeClient1 = new WebSocketClient();
WebSocketClient consumeClient2 = new WebSocketClient();
SimpleConsumerSocket consumeSocket1 = new SimpleConsumerSocket();
SimpleConsumerSocket consumeSocket2 = new SimpleConsumerSocket();
try {
consumeClient1.start();
ClientUpgradeRequest consumeRequest1 = new ClientUpgradeRequest();
Future<Session> consumerFuture1 = consumeClient1.connect(consumeSocket1, consumeUri, consumeRequest1);
consumerFuture1.get();
try {
consumeClient2.start();
ClientUpgradeRequest consumeRequest2 = new ClientUpgradeRequest();
Future<Session> consumerFuture2 = consumeClient2.connect(consumeSocket2, consumeUri, consumeRequest2);
consumerFuture2.get();
Assert.fail("should fail: conflicting subscription name");
} catch (Exception e) {
// Expected
Assert.assertTrue(e.getCause() instanceof UpgradeException);
Assert.assertEquals(((UpgradeException) e.getCause()).getResponseStatusCode(), HttpServletResponse.SC_CONFLICT);
} finally {
stopWebSocketClient(consumeClient2);
}
} finally {
stopWebSocketClient(consumeClient1);
}
}
use of org.eclipse.jetty.websocket.api.UpgradeException in project jetty.project by eclipse.
the class WebSocketUpgradeRequest method onComplete.
@Override
public void onComplete(Result result) {
if (LOG.isDebugEnabled()) {
LOG.debug("onComplete() - {}", result);
}
URI requestURI = result.getRequest().getURI();
Response response = result.getResponse();
int responseStatusCode = response.getStatus();
String responseLine = responseStatusCode + " " + response.getReason();
if (result.isFailed()) {
if (LOG.isDebugEnabled()) {
if (result.getFailure() != null)
LOG.debug("General Failure", result.getFailure());
if (result.getRequestFailure() != null)
LOG.debug("Request Failure", result.getRequestFailure());
if (result.getResponseFailure() != null)
LOG.debug("Response Failure", result.getResponseFailure());
}
Throwable failure = result.getFailure();
if ((failure instanceof java.net.ConnectException) || (failure instanceof UpgradeException)) {
// handle as-is
handleException(failure);
} else {
// wrap in UpgradeException
handleException(new UpgradeException(requestURI, responseStatusCode, responseLine, failure));
}
}
if (responseStatusCode != HttpStatus.SWITCHING_PROTOCOLS_101) {
// Failed to upgrade (other reason)
handleException(new UpgradeException(requestURI, responseStatusCode, responseLine));
}
}
use of org.eclipse.jetty.websocket.api.UpgradeException in project jetty.project by eclipse.
the class ClientConnectTest method testBadHandshake_GetOK_WithSecWebSocketAccept.
@Test
public void testBadHandshake_GetOK_WithSecWebSocketAccept() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection connection = server.accept();
List<String> requestLines = connection.readRequestLines();
String key = connection.parseWebSocketKey(requestLines);
// Send OK to GET but not upgrade
StringBuilder resp = new StringBuilder();
// intentionally 200 (not 101)
resp.append("HTTP/1.1 200 OK\r\n");
// Include a value accept key
resp.append("Sec-WebSocket-Accept: ").append(AcceptHash.hashKey(key)).append("\r\n");
resp.append("Content-Length: 0\r\n");
resp.append("\r\n");
connection.respond(resp.toString());
// The attempt to get upgrade response future should throw error
try {
future.get(30, TimeUnit.SECONDS);
Assert.fail("Expected ExecutionException -> UpgradeException");
} catch (ExecutionException e) {
// Expected Path
UpgradeException ue = assertExpectedError(e, wsocket, UpgradeException.class);
Assert.assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
Assert.assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
Assert.assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(200));
}
}
Aggregations