Java 类javax.websocket.OnError 实例源码

项目:apache-tomcat-7.0.73-with-comment    文件:SnakeAnnotation.java   
@OnError
public void onError(Throwable t) throws Throwable {
    // Most likely cause is a user closing their browser. Check to see if
    // the root cause is EOF and if it is ignore it.
    // Protect against infinite loops.
    int count = 0;
    Throwable root = t;
    while (root.getCause() != null && count < 20) {
        root = root.getCause();
        count ++;
    }
    if (root instanceof EOFException) {
        // Assume this is triggered by the user closing their browser and
        // ignore it.
    } else {
        throw t;
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:SnakeAnnotation.java   
@OnError
public void onError(Throwable t) throws Throwable {
    // Most likely cause is a user closing their browser. Check to see if
    // the root cause is EOF and if it is ignore it.
    // Protect against infinite loops.
    int count = 0;
    Throwable root = t;
    while (root.getCause() != null && count < 20) {
        root = root.getCause();
        count ++;
    }
    if (root instanceof EOFException) {
        // Assume this is triggered by the user closing their browser and
        // ignore it.
    } else {
        throw t;
    }
}
项目:che    文件:BasicWebSocketEndpoint.java   
@OnError
public void onError(Throwable t, Session session) {
  Optional<String> endpointIdOptional = registry.get(session);

  String combinedEndpointId;
  if (endpointIdOptional.isPresent()) {
    combinedEndpointId = endpointIdOptional.get();

    LOG.debug("Web socket session error");
    LOG.debug("Endpoint: {}", combinedEndpointId);
    LOG.debug("Error: {}", t);
  } else {
    LOG.warn("Web socket session error");
    LOG.debug("Unidentified session");
    LOG.debug("Error: {}", t);
  }
}
项目:dropwizard-websockets    文件:EventDriverMetrics.java   
public EventDriverMetrics(final Class<?> endpointClass, MetricRegistry metrics) {
    final Class<?> klass = endpointClass;
    Metered metered = klass.getAnnotation(Metered.class);
    Timed timed = klass.getAnnotation(Timed.class);
    ExceptionMetered em = klass.getAnnotation(ExceptionMetered.class);
    this.onTextMeter = metered != null
            ? Optional.of(metrics.meter(MetricRegistry.name(metered.name(), klass.getName(), OnMessage.class.getSimpleName())))
            : Optional.empty();
    this.countOpened = metered != null
            ? Optional.of(metrics.counter(MetricRegistry.name(metered.name(), klass.getName(), OPEN_CONNECTIONS)))
            : Optional.empty();
    this.timer = timed != null
            ? Optional.of(metrics.timer(MetricRegistry.name(timed.name(), klass.getName())))
            : Optional.empty();
    this.exceptionMetered = em != null
            ? Optional.of(metrics.meter(MetricRegistry.name(em.name(), klass.getName(), OnError.class.getSimpleName())))
            : Optional.empty();
}
项目:jReto    文件:ConnectionRequestEndpoint.java   
@OnError
public void onError(Session session, Throwable t) {
    LOGGER.log(Level.WARNING, "Error occured {0}", t);

    try {
        this.acceptingSession
                .close(
                        new CloseReason(
                                CloseReason.CloseCodes.CLOSED_ABNORMALLY, 
                                "An exception occured: "+t.toString()
                        )
                );
    } catch (IOException ex) {
        Logger.getLogger(ConnectionAcceptEndpoint.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:jReto    文件:ConnectionAcceptEndpoint.java   
@OnError
public void onError(Session session, Throwable t) {
    LOGGER.log(Level.WARNING, "Error occured {0}", t);

    try {
        this.requestingSession
                .close(
                        new CloseReason(
                                CloseReason.CloseCodes.CLOSED_ABNORMALLY, 
                                "An exception occured: "+t.toString()
                        )
                );
    } catch (IOException ex) {
        Logger.getLogger(ConnectionAcceptEndpoint.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:platypus-js    文件:JsServerModuleEndPoint.java   
@OnError
public void errorInSession(Session websocketSession, Throwable aError) throws Exception {
    PlatypusServerCore platypusCore = lookupPlaypusServerCore();
    in(platypusCore, websocketSession, (com.eas.server.Session aSession) -> {
        Logger.getLogger(JsServerModuleEndPoint.class.getName()).log(Level.FINE, "WebSocket container OnError {0}.", aSession.getId());
        JSObject errorEvent = Scripts.getSpace().makeObj();
        errorEvent.setMember("message", aError.getMessage());
        errorEvent.setMember("id", websocketSession.getId());
        Logger.getLogger(JsServerModuleEndPoint.class.getName()).log(Level.SEVERE, null, aError);
        platypusCore.executeMethod(moduleName, WS_ON_ERROR, new Object[]{errorEvent}, true, (Object aResult) -> {
            Logger.getLogger(JsServerModuleEndPoint.class.getName()).log(Level.FINE, "{0} method of {1} module called successfully.", new Object[]{WS_ON_ERROR, moduleName});
        }, (Exception ex) -> {
            Logger.getLogger(JsServerModuleEndPoint.class.getName()).log(Level.SEVERE, null, ex);
        });
    });
}
项目:class-guard    文件:SnakeAnnotation.java   
@OnError
public void onError(Throwable t) throws Throwable {
    // Most likely cause is a user closing their browser. Check to see if
    // the root cause is EOF and if it is ignore it.
    // Protect against infinite loops.
    int count = 0;
    Throwable root = t;
    while (root.getCause() != null && count < 20) {
        root = root.getCause();
        count ++;
    }
    if (root instanceof EOFException) {
        // Assume this is triggered by the user closing their browser and
        // ignore it.
    } else {
        throw t;
    }
}
项目:apache-tomcat-7.0.57    文件:SnakeAnnotation.java   
@OnError
public void onError(Throwable t) throws Throwable {
    // Most likely cause is a user closing their browser. Check to see if
    // the root cause is EOF and if it is ignore it.
    // Protect against infinite loops.
    int count = 0;
    Throwable root = t;
    while (root.getCause() != null && count < 20) {
        root = root.getCause();
        count ++;
    }
    if (root instanceof EOFException) {
        // Assume this is triggered by the user closing their browser and
        // ignore it.
    } else {
        throw t;
    }
}
项目:apache-tomcat-7.0.57    文件:SnakeAnnotation.java   
@OnError
public void onError(Throwable t) throws Throwable {
    // Most likely cause is a user closing their browser. Check to see if
    // the root cause is EOF and if it is ignore it.
    // Protect against infinite loops.
    int count = 0;
    Throwable root = t;
    while (root.getCause() != null && count < 20) {
        root = root.getCause();
        count ++;
    }
    if (root instanceof EOFException) {
        // Assume this is triggered by the user closing their browser and
        // ignore it.
    } else {
        throw t;
    }
}
项目:tomcat7-eap6-examples    文件:SnakeAnnotation.java   
@OnError
public void onError(Throwable t) throws Throwable {
    // Most likely cause is a user closing their browser. Check to see if
    // the root cause is EOF and if it is ignore it.
    // Protect against infinite loops.
    int count = 0;
    Throwable root = t;
    while (root.getCause() != null && count < 20) {
        root = root.getCause();
        count ++;
    }
    if (root instanceof EOFException) {
        // Assume this is triggered by the user closing their browser and
        // ignore it.
    } else {
        throw t;
    }
}
项目:cito    文件:AbstractEndpoint.java   
@OnError
@Override
public void onError(Session session, Throwable cause) {
    final String errorId = RandomStringUtils.randomAlphanumeric(8).toUpperCase();
    this.log.warn("WebSocket error. [id={},principle={},errorId={}]", session.getId(), session.getUserPrincipal(), errorId, cause);
    try (QuietClosable c = webSocketContext(this.beanManager).activate(session)) {
        this.errorEvent.select(cito.annotation.OnError.Literal.onError()).fire(cause);
        final Frame errorFrame = Frame.error().body(MediaType.TEXT_PLAIN_TYPE, format("%s [errorId=%s]", cause.getMessage(), errorId)).build();
        session.getBasicRemote().sendObject(errorFrame);
        session.close(new CloseReason(CloseCodes.PROTOCOL_ERROR, format("See server log. [errorId=%s]", errorId)));
    } catch (IOException | EncodeException e) {
        this.log.error("Unable to send error frame! [id={},principle={}]", session.getId(), session.getUserPrincipal(), e);
    }
}
项目:Blog_sample_project    文件:EchoService.java   
@OnError
public void onError(Session session, Throwable t) {
    System.out.println(MessageFormat.format("Find exception {0} for web-socket session {1}.", t.getMessage(), session.getId()));
    if(!session.isOpen()) {
        System.out.println(MessageFormat.format("The web-socket {0} was already closed, now is going to remove the notification listeners.", session.getId()));
    }
}
项目:mycore    文件:MCRWebCLIResourceSockets.java   
@OnError
public void error(Throwable t) {
    if (t instanceof SocketTimeoutException) {
        LOGGER.warn("Socket Session timed out, clossing connection");
    } else {
        LOGGER.error("Error in WebSocket Session", t);
    }
}
项目:mycore    文件:MCRProcessingEndpoint.java   
@OnError
public void onError(Session session, Throwable error) {
    if (error instanceof SocketTimeoutException) {
        this.close(session);
        LOGGER.warn("Websocket error {}: websocket timeout", session.getId());
        return;
    }
    LOGGER.error("Websocket error {}", session.getId(), error);
}
项目:sample-room-java    文件:RoomEndpoint.java   
@OnError
public void onError(Session session, Throwable t) {
    Log.log(Level.FINE, this, "A problem occurred on connection", t);

    // TODO: Careful with what might revealed about implementation details!!
    // We're opting for making debug easy..
    tryToClose(session,
            new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION,
                    trimReason(t.getClass().getName())));
}
项目:tomcat-8-wffweb-demo-apps    文件:WSServerForIndexPage.java   
@OnError
public void onError(Session session, Throwable throwable) {
    // NOP
    // log only if required
    // if (LOGGER.isLoggable(Level.WARNING)) {
    // LOGGER.log(Level.WARNING, throwable.getMessage());
    // }
}
项目:mdw    文件:WebSocketMessenger.java   
@OnError
public void onError(Session session, Throwable t) {
    if (t instanceof IOException && t.getMessage().startsWith(
            "java.io.IOException: An established connection was aborted")) {
        // avoid nuisance logging when browser closes connection
        if (logger.isMdwDebugEnabled())
            logger.severeException(t.getMessage(), t);
    }
    else {
        logger.severeException(t.getMessage(), t);
    }
}
项目:real1ty    文件:Application.java   
@OnError
public void onError(Session session, Throwable t) {
    if(session!=null){
        sessions.remove(session);
    }
    System.out.println("Websocket connection has broken");
    t.printStackTrace();
}
项目:iote2e    文件:ServerSideSocketIote2eRequest.java   
/**
 * On web socket error.
 *
 * @param cause the cause
 */
@OnError
public void onWebSocketError(Throwable cause) {
    boolean isRemove = ThreadEntryPointIote2eRequest.serverSideSocketIote2eRequest.remove(keyCommon, this);
    logger.info("Socket Error: " + cause.getMessage() + ", isRemove=" + isRemove);
    shutdownThreadIgniteSubscribe();
}
项目:iote2e    文件:ServerSideSocketNearRealTime.java   
/**
 * On web socket error.
 *
 * @param cause the cause
 */
@OnError
public void onWebSocketError(Throwable cause) {
    boolean isRemove = ThreadEntryPointNearRealTime.serverSideSocketNearRealTimes.remove(Iote2eConstants.SOCKET_KEY_NRT, this);
    logger.info("Socket Error: " + cause.getMessage() + ", isRemove=" + isRemove);
    shutdownThreadIgniteSubscribe();
}
项目:Gobang    文件:StatusEndPoint.java   
@OnError
@Override
public void onError(Session session, Throwable throwable) {
    if (throwable == null) {
        return;
    }
    throwable.printStackTrace();
    if (session != null) {
        sessions.remove(session);
    }
}
项目:jkool-client-java-api    文件:JKWSClient.java   
/**
 * Callback hook for Connection error events.
 *
 * @param userSession
 *            the userSession which is opened.
 */
@OnError
public void onError(Session userSession, Throwable ex) {
    if (this.messageHandler != null) {
        this.messageHandler.onError(this, userSession, ex);
    }
}
项目:ws-client    文件:WSclient.java   
@OnError
public void error(Session session, Throwable e) {
    System.out.println(session.getId() + " was error.");
    e.printStackTrace();
    // trayにメッセージを表示。
    tray.displayMessage("エラー", e.getMessage(), TrayIcon.MessageType.ERROR);
    if (session.isOpen()) {
        try {
            session.close();
        } catch (IOException ex) {
        }
    }
}
项目:hopsworks    文件:NotebookServer.java   
@OnError
public void onError(Session conn, Throwable exc) {
  if (impl != null) {
    impl.removeConnectionFromAllNote(conn);
    impl.removeConnectedSockets(conn, notebookServerImplFactory);
  }
}
项目:msf4j    文件:EndpointDispatcher.java   
/**
 * Extract OnError method from the endpoint if exists
 *
 * @param webSocketEndpoint Endpoint to extract method.
 * @return method optional to handle errors.
 */
public Optional<Method> getOnErrorMethod(Object webSocketEndpoint) {
    Method[] methods = webSocketEndpoint.getClass().getMethods();
    Method returnMethod = null;
    for (Method method : methods) {
        if (method.isAnnotationPresent(OnError.class)) {
            returnMethod = method;
        }
    }
    return Optional.ofNullable(returnMethod);
}
项目:StreamSis    文件:OBSStudioClient.java   
@OnError
public void onError(Session session, Throwable thr) {
    if (thr instanceof ConnectException) {
        logger.error("Connection failed.");
        status.set(ConnectionStatus.CONNECTIONERROR);
        return;
    }
    logger.error("Unknown error during connection occurred.", thr);
}
项目:sample.daytrader7    文件:MarketSummaryWebSocket.java   
@OnError
public void onError(Throwable t) {
    if (Log.doTrace()) {
        Log.trace("MarketSummaryWebSocket:onError -- session -->" + currentSession + "<--");
    }
    t.printStackTrace();
}
项目:gameon-mediator    文件:MediatorEndpoint.java   
@OnError
public void onError(@PathParam("userId") String userId, Session session, Throwable t) {
    Log.log(Level.FINER, session, "oops for client " + userId + " connection", t);

    WSUtils.tryToClose(session, new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION,
            WSUtils.trimReason(t.getClass().getName())));
}
项目:platypus-js    文件:JsClientEndPoint.java   
@OnError
public void onError(Session websocketSession, Throwable aError) {
    if (onerror != null) {
        space.process(context, () -> {
            JSObject errorEvent = Scripts.getSpace().makeObj();
            errorEvent.setMember("message", aError.getMessage());
            onerror.call(session.getPublished(), new Object[]{errorEvent});
        });
    }
}
项目:west-java-client    文件:WebSocketClientHandler.java   
@OnError
public void onError(final Session session, final Throwable e) throws Exception {
    if (log.isDebugEnabled())
        log.debug("WebSocket Client Error.\n", e);
    if (handler != null &&
            handler instanceof IWebSocketSessionAwareMessageHandler)
        ((IWebSocketSessionAwareMessageHandler) handler).handleError(session, e);
}
项目:oracle-samples    文件:ETFEndpoint.java   
@OnError
public void error(Session session, Throwable t) {
    /* Remove this connection from the queue */
    queue.remove(session);
    logger.log(Level.INFO, t.toString());
    logger.log(Level.INFO, "Connection error.");
}
项目:BIMserver    文件:Jsr356Impl.java   
@OnError
public void onError(Throwable exception, Session session) {
    if (exception instanceof IOException) {
        // Let this one slide, usually indicates a disconnected client
        LOGGER.error("", exception);
    } else {
        LOGGER.error("", exception);
    }
}
项目:feathercon    文件:WebSocketEndpointConfiguration.java   
private void requireHandlerMethods(Class endpointClass) {
    boolean hasOnOpenAnnotation = false;
    boolean hasOnMessageAnnotation = false;
    boolean hasOnCloseAnnotation = false;
    boolean hasOnErrorAnnotation = false;

    Method[] methods = endpointClass.getMethods();
    for (Method method : methods) {
        Annotation[] annotations = method.getAnnotations();
        for (Annotation annotation : annotations) {
            if (annotation instanceof OnOpen) {
                hasOnOpenAnnotation = true;
                continue;
            }
            if (annotation instanceof OnClose) {
                hasOnCloseAnnotation = true;
                continue;
            }
            if (annotation instanceof OnMessage) {
                hasOnMessageAnnotation = true;
                continue;
            }
            if (annotation instanceof OnError) {
                hasOnErrorAnnotation = true;
                continue;
            }
        }
    }
    if (!(hasOnOpenAnnotation && hasOnMessageAnnotation && hasOnCloseAnnotation && hasOnErrorAnnotation)) {
        throw new IllegalArgumentException(String.format("Class %s must have methods annotated with OnOpen, OnClose, OnMessage, and OnError javax.websocket annotations", endpointClass));
    }
}
项目:fll-sw    文件:DisplayWebSocket.java   
@OnError
public void error(final Session session,
                  final Throwable t) {
  synchronized (SESSIONS_LOCK) {
    LOGGER.error("Caught websocket error, closing session", t);

    internalRemoveSession(session);
  }
}
项目:fll-sw    文件:UnverifiedRunsWebSocket.java   
@OnError
public void error(final Session session,
                  final Throwable t) {
  synchronized (SESSIONS_LOCK) {
    LOGGER.error("Caught websocket error, closing session", t);

    internalRemoveSession(session);
  }
}
项目:fll-sw    文件:MhubMessageHandler.java   
@OnError
public void error(final Session session,
                  final Throwable t) {
  synchronized (lock) {
    LOGGER.error("Caught websocket error, closing session", t);

    internalRemoveSession(session);
  }
}
项目:matlab-connector    文件:RemoteMatlabClient.java   
@OnError
public void onError(Throwable thr) {
    synchronized (responses) {
        MatlabException ex = asMatlabException(thr);
        // we can't say which request caused this...
        responses.values().stream().filter(this::notDone)
                .forEach(f -> f.setException(ex));
    }
}
项目:matlab-connector    文件:MatlabServerEndpoint.java   
@OnError
public void onError(Session session, Throwable t)
        throws IOException, EncodeException {
    log.error("Caught exception while handling request for session " + session.getId(), t);
    if (t instanceof MatlabException) {
        session.getBasicRemote().sendObject(t);
    } else {
        session.getBasicRemote()
                .sendObject(new MatlabException("Could not execute request", t));
    }
}
项目:guice-websocket    文件:EchoEndpoint.java   
@OnError
public void onWebSocketError(Session session, Throwable throwable) {
    LOGGER.error("An error occurred while communicating with the client, session: {}", session, throwable);
    clientsSessions.remove(session);
}