use of org.eclipse.jetty.websocket.api.WebSocketException in project jetty.project by eclipse.
the class EventMethod method call.
public void call(Object obj, Object... args) {
if ((this.pojo == null) || (this.method == null)) {
LOG.warn("Cannot execute call: pojo={}, method={}", pojo, method);
// no call event method determined
return;
}
if (obj == null) {
LOG.warn("Cannot call {} on null object", this.method);
return;
}
if (args.length > paramTypes.length) {
Object[] trimArgs = dropFirstArg(args);
call(obj, trimArgs);
return;
}
if (args.length < paramTypes.length) {
throw new IllegalArgumentException("Call arguments length [" + args.length + "] must always be greater than or equal to captured args length [" + paramTypes.length + "]");
}
try {
this.method.invoke(obj, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
String err = String.format("Cannot call method %s on %s with args: %s", method, pojo, QuoteUtil.join(args, ","));
throw new WebSocketException(err, e);
}
}
use of org.eclipse.jetty.websocket.api.WebSocketException in project jetty.project by eclipse.
the class WebSocketExtensionFactory method newInstance.
@Override
public Extension newInstance(ExtensionConfig config) {
if (config == null) {
return null;
}
String name = config.getName();
if (StringUtil.isBlank(name)) {
return null;
}
Class<? extends Extension> extClass = getExtension(name);
if (extClass == null) {
return null;
}
try {
Extension ext = container.getObjectFactory().createInstance(extClass);
if (ext instanceof AbstractExtension) {
AbstractExtension aext = (AbstractExtension) ext;
aext.init(container);
aext.setConfig(config);
}
return ext;
} catch (InstantiationException | IllegalAccessException e) {
throw new WebSocketException("Cannot instantiate extension: " + extClass, e);
}
}
use of org.eclipse.jetty.websocket.api.WebSocketException in project jetty.project by eclipse.
the class BinaryWholeMessage method messageComplete.
@SuppressWarnings("unchecked")
@Override
public void messageComplete() {
super.finished = true;
byte[] data = out.toByteArray();
DecoderFactory.Wrapper decoder = msgWrapper.getDecoder();
Decoder.Binary<Object> binaryDecoder = (Binary<Object>) decoder.getDecoder();
try {
Object obj = binaryDecoder.decode(BufferUtil.toBuffer(data));
wholeHandler.onMessage(obj);
} catch (DecodeException e) {
throw new WebSocketException("Unable to decode binary data", e);
}
}
use of org.eclipse.jetty.websocket.api.WebSocketException in project jetty.project by eclipse.
the class EventDriverTest method testAnnotated_Error.
@Test
public void testAnnotated_Error() throws Exception {
AnnotatedTextSocket socket = new AnnotatedTextSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
conn.open();
driver.incomingError(new WebSocketException("oof"));
driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
socket.capture.assertEventCount(3);
socket.capture.pop().assertEventStartsWith("onConnect");
socket.capture.pop().assertEventStartsWith("onError(WebSocketException: oof)");
socket.capture.pop().assertEventStartsWith("onClose(1000,");
}
}
use of org.eclipse.jetty.websocket.api.WebSocketException in project joynr by bmwcarit.
the class WebSocketJettyClient method writeBytes.
@Override
public synchronized void writeBytes(Address to, byte[] message, long timeout, TimeUnit unit, final SuccessAction successAction, final FailureAction failureAction) {
if (messageListener == null) {
throw new JoynrDelayMessageException(20, "WebSocket write failed: receiver has not been set yet");
}
if (sessionFuture == null) {
try {
reconnect();
} catch (Exception e) {
throw new JoynrDelayMessageException(10, "WebSocket reconnect failed. Will try later", e);
}
}
try {
Session session = sessionFuture.get(timeout, unit);
session.getRemote().sendBytes(ByteBuffer.wrap(message), new WriteCallback() {
@Override
public void writeSuccess() {
successAction.execute();
}
@Override
public void writeFailed(Throwable error) {
if (error instanceof WebSocketException) {
reconnect();
failureAction.execute(new JoynrDelayMessageException(reconnectDelay, error.getMessage()));
} else {
failureAction.execute(error);
}
}
});
} catch (WebSocketException | ExecutionException e) {
reconnect();
throw new JoynrDelayMessageException(10, "WebSocket write timed out", e);
} catch (TimeoutException e) {
throw new JoynrDelayMessageException("WebSocket write timed out", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
Aggregations