我正在使用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) 在我的应用程序中,我得到了一个 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 之后。有什么想法可以让两者都工作吗?
提前致谢。
我正在构建一个受 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 中,它位于隐藏的输入字段中)?提前致谢。
笔记:
调用:
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) 我试图渲染一个表示时间戳的<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