小编Sec*_*one的帖子

WebSocket:永远不会调用OnClose()

我正在使用WebSocket端点实现一个应用程序.这是一些代码:

@ApplicationScoped
@ServerEndpoint(value="/socket", encoders = {MessageEncoder.class, CommandEncoder.class})
public class SocketEndpoint {

    /** Default-Logger */
    private final static Logger LOG = LoggerFactory.getLogger(SocketEndpoint.class);

    @Inject
    SessionHandler sessionHandler;

    @OnOpen
    public void open(Session session, EndpointConfig config) {
        LOG.debug("Connected session => '{}' - '{}'", session, config);
        sessionHandler.initSession(session);
    }

    @OnMessage
    public void onMessage(Session session, String messageJson) {
        // do something
    }

    @OnClose
    public void onClose(Session session, CloseReason reason) {
        LOG.debug("Closing session => '{}' - '{}'", session, reason);
        sessionHandler.removeSession(session);
    }

    @OnError
    public void onError(Session session, Throwable ex) { …
Run Code Online (Sandbox Code Playgroud)

java encoder websocket oncloselistener

14
推荐指数
1
解决办法
1635
查看次数

onUserInteraction() 什么时候被调用?

在我的应用程序中,我得到了一个 thrad,它每 60 秒检查一次来自网络服务(在 onCreate() 中定义)的数据:

new Thread(new Runnable() {
    @Override
    public void run() {     
        while (true) {
            try {               
                Thread.sleep(PERIOD);
                if(condition) do_something();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}).start();
Run Code Online (Sandbox Code Playgroud)

另外,在用户不活动一段时间后,我得到了一个执行方法的处理程序:

private Handler disconnectHandler = new Handler();

private Runnable disconnectCallback = new Runnable() {
    @Override
    public void run() {
        do_something_else();
    }
};

public void resetDisconnectTimer(){
    disconnectHandler.removeCallbacks(disconnectCallback);
    disconnectHandler.postDelayed(disconnectCallback, TIMEOUT);
}

@Override
public void onUserInteraction() {
    super.onUserInteraction();
    resetDisconnectTimer();
}
Run Code Online (Sandbox Code Playgroud)

现在我遇到了在 PERIOD 之后调用 onUserInteraction() 的问题,而不仅仅是在 TIMEOUT 之后。有什么想法可以让两者都工作吗?

提前致谢。

multithreading android sleep user-interaction postdelayed

6
推荐指数
2
解决办法
1万
查看次数

Keycloak:在 AngularJS 应用程序中更新用户密码

我正在构建一个受 Keycloak 保护的 AngularJS 应用程序。每个用户都应在其用户配置文件中更新其密码。

调用 Keycloak API 获取密码

GET /auth/realms/{realm_name}/account/password

从 Keycloak 返回 HTML 内容。我想构建自己的表单来更新用户的密码。

在我发现的 Keycloak 文档中

POST /auth/realms/{realm_name}/account/password

这需要属性

{
    'password' => user's current password
    'password-new' => new password
    'password-confirm' => new password again
    'stateChecker' => token from keycloak
}
Run Code Online (Sandbox Code Playgroud)

打电话

POST /auth/realms/{realm_name}/account/password

没有 'stateChecker' 属性会导致错误。需要这个属性。

所以这里是我的问题:

  • 如何stateChecker从 keycloak 获取登录用户的值(在 Keycloak 中,它位于隐藏的输入字段中)?
  • 是否有另一种可能通过 REST API 调用更改用户密码?

提前致谢。

笔记:

调用:

POST /auth/realms/{realm_name}/account/password

带有硬编码的属性和值

{
    'password': 'somepasswd',
    'password-new': 'someNEWpasswd',
    'password-confirm': 'someNEWpasswd',
    'stateChecker': '<token copied and pasted from …
Run Code Online (Sandbox Code Playgroud)

authentication rest change-password angularjs keycloak

4
推荐指数
1
解决办法
3462
查看次数

将时间戳绑定到日期时间 - 本地输入的绑定模型

我试图渲染一个表示时间戳的<input type="datetime-local>字段ng-model:

<input type="datetime-local" ng-model="object.value">
Run Code Online (Sandbox Code Playgroud)

$scope.object.value = 1433109600000;
Run Code Online (Sandbox Code Playgroud)

控制台显示[ngModel:datefmt]错误.

如何正确绑定$scope.object.value到输入字段?(时间戳来自nestest对象中的Web服务)

一些Plnkr:http://plnkr.co/edit/TGpKVNF1tv0b1h6JPBT8?p = preview

javascript datetime timestamp angularjs angular-ngmodel

2
推荐指数
1
解决办法
3867
查看次数