Search in sources :

Example 1 with WebSocketException

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);
    }
}
Also used : WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with WebSocketException

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);
    }
}
Also used : Extension(org.eclipse.jetty.websocket.api.extensions.Extension) WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException)

Example 3 with WebSocketException

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);
    }
}
Also used : WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException) DecoderFactory(org.eclipse.jetty.websocket.jsr356.DecoderFactory) Binary(javax.websocket.Decoder.Binary) Decoder(javax.websocket.Decoder) DecodeException(javax.websocket.DecodeException)

Example 4 with WebSocketException

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,");
    }
}
Also used : LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) AnnotatedTextSocket(examples.AnnotatedTextSocket) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 5 with WebSocketException

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();
    }
}
Also used : WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) WriteCallback(org.eclipse.jetty.websocket.api.WriteCallback) ExecutionException(java.util.concurrent.ExecutionException) WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException) TimeoutException(java.util.concurrent.TimeoutException) JoynrShutdownException(io.joynr.exceptions.JoynrShutdownException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExecutionException(java.util.concurrent.ExecutionException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) Session(org.eclipse.jetty.websocket.api.Session) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

WebSocketException (org.eclipse.jetty.websocket.api.WebSocketException)13 IOException (java.io.IOException)3 Session (org.eclipse.jetty.websocket.api.Session)3 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ProtocolException (java.net.ProtocolException)2 SocketException (java.net.SocketException)2 ByteBuffer (java.nio.ByteBuffer)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 DecodeException (javax.websocket.DecodeException)2 Decoder (javax.websocket.Decoder)2 WriteCallback (org.eclipse.jetty.websocket.api.WriteCallback)2 DecoderFactory (org.eclipse.jetty.websocket.jsr356.DecoderFactory)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TimeoutTask (com.serotonin.m2m2.util.timeout.TimeoutTask)1 AnnotatedTextSocket (examples.AnnotatedTextSocket)1 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)1 JoynrShutdownException (io.joynr.exceptions.JoynrShutdownException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1