當前位置: 首頁>>代碼示例>>Java>>正文


Java OnError類代碼示例

本文整理匯總了Java中javax.websocket.OnError的典型用法代碼示例。如果您正苦於以下問題:Java OnError類的具體用法?Java OnError怎麽用?Java OnError使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OnError類屬於javax.websocket包,在下文中一共展示了OnError類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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;
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:19,代碼來源:SnakeAnnotation.java

示例2: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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);
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:18,代碼來源:BasicWebSocketEndpoint.java

示例3: EventDriverMetrics

import javax.websocket.OnError; //導入依賴的package包/類
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();
}
 
開發者ID:LivePersonInc,項目名稱:dropwizard-websockets,代碼行數:19,代碼來源:EventDriverMetrics.java

示例4: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:ls1intum,項目名稱:jReto,代碼行數:17,代碼來源:ConnectionRequestEndpoint.java

示例5: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:ls1intum,項目名稱:jReto,代碼行數:17,代碼來源:ConnectionAcceptEndpoint.java

示例6: errorInSession

import javax.websocket.OnError; //導入依賴的package包/類
@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);
        });
    });
}
 
開發者ID:marat-gainullin,項目名稱:platypus-js,代碼行數:17,代碼來源:JsServerModuleEndPoint.java

示例7: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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);
	}
}
 
開發者ID:dansiviter,項目名稱:cito,代碼行數:15,代碼來源:AbstractEndpoint.java

示例8: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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()));
	}
}
 
開發者ID:XMeterSaaSService,項目名稱:Blog_sample_project,代碼行數:8,代碼來源:EchoService.java

示例9: error

import javax.websocket.OnError; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:9,代碼來源:MCRWebCLIResourceSockets.java

示例10: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:10,代碼來源:MCRProcessingEndpoint.java

示例11: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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())));
}
 
開發者ID:gameontext,項目名稱:sample-room-java,代碼行數:11,代碼來源:RoomEndpoint.java

示例12: onError

import javax.websocket.OnError; //導入依賴的package包/類
@OnError
public void onError(Session session, Throwable throwable) {
    // NOP
    // log only if required
    // if (LOGGER.isLoggable(Level.WARNING)) {
    // LOGGER.log(Level.WARNING, throwable.getMessage());
    // }
}
 
開發者ID:webfirmframework,項目名稱:tomcat-8-wffweb-demo-apps,代碼行數:9,代碼來源:WSServerForIndexPage.java

示例13: onError

import javax.websocket.OnError; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:13,代碼來源:WebSocketMessenger.java

示例14: onError

import javax.websocket.OnError; //導入依賴的package包/類
@OnError
public void onError(Session session, Throwable t) {
    if(session!=null){
        sessions.remove(session);
    }
    System.out.println("Websocket connection has broken");
    t.printStackTrace();
}
 
開發者ID:ilanpillemer,項目名稱:real1ty,代碼行數:9,代碼來源:Application.java

示例15: onWebSocketError

import javax.websocket.OnError; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:petezybrick,項目名稱:iote2e,代碼行數:12,代碼來源:ServerSideSocketIote2eRequest.java


注:本文中的javax.websocket.OnError類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。