小编Bla*_*lix的帖子

Java Eclipse Paho实现 - 自动重新连接

我正在尝试eclipse.paho在我的项目中实现连接Mqtt Broker(订阅和发布目的).问题是,当我使用订阅功能(实现MqttCallback界面)时,我无法想象如果连接丢失,我该如何重新连接.MqttCallback接口有一个connectionLost方法,但它对于导致连接丢失的调试很有用.我搜索但找不到建立自动重新连接的方法.你能建议一个关于这个问题的方法或文件吗?

java eclipse mqtt paho

7
推荐指数
2
解决办法
9849
查看次数

Spring Security 和带有 JWT 令牌的 Websocket

我有一个 Spring Boot 项目(2.0.0.RELEASE)。我使用基于 JWT 令牌的身份验证和授权来保护 REST。我还想将 Websocket 与 SockJS 结合使用,并使用 Token 进行套接字身份验证。我尝试实施关于这篇文章的内容,但是我无法成功。

\n\n

首先,我的安全配置如下;

\n\n
@Configuration\n@EnableWebSecurity\n@EnableGlobalMethodSecurity(prePostEnabled = true)\npublic class SecurityConfig extends WebSecurityConfigurerAdapter {\n\n    private final TokenAuthenticationService tokenAuthenticationService;\n    private final ObjectMapper mapper;\n\n    @Autowired\n    protected SecurityConfig(final TokenAuthenticationService tokenAuthenticationService, ObjectMapper mapper) {\n        super();\n        this.tokenAuthenticationService = tokenAuthenticationService;\n        this.mapper = mapper;\n    }\n\n    @Override\n    protected void configure(HttpSecurity http) throws Exception {\n        http.headers()\n                .frameOptions().disable()\n                .and()\n                .authorizeRequests()\n                .antMatchers("/api/v3/auth").permitAll()\n                .antMatchers("/api/v3/signup").permitAll()\n                .antMatchers("/api/v3/websocket/**").permitAll()\n                .anyRequest().authenticated()\n                .and()\n                .exceptionHandling().authenticationEntryPoint(new RestAuthenticationEntryPoint(mapper))\n                .and()\n                .addFilterBefore(new AuthenticationTokenFilter(tokenAuthenticationService), UsernamePasswordAuthenticationFilter.class)\n                .cors()\n                .and()\n                .csrf().disable();\n    }\n\n    @Bean\n    public CorsFilter …
Run Code Online (Sandbox Code Playgroud)

spring spring-security websocket spring-boot spring-websocket

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

带有动态密钥名称的Json String to Java Object

我正在尝试将这个结构化的json字符串解析为Java Object但是我每次尝试都失败了.

{
  "message": "Test Message",
  "status": true,
  "users": {
    "user_xy": [
      {
        "time": "2016-08-25 19:01:20.944614158 +0300 EEST",
        "age": 24,
        "props": {
          "pr1": 197,
          "pr2": 0.75,
          "pr3": 0.14,
          "pr4": -0.97
        }
      }
    ],
    "user_zt": [
      {
        "time": "2016-08-25 17:08:36.920891187 +0300 EEST",
        "age": 29,
        "props": {
          "pr1": 1.2332131860505051,
          "pr2": -0.6628148829634317,
          "pr3": -0.11622442112006928
        }
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

props字段可以包含1个属性或6个属性,它取决于db记录.用户名部分也会动态变化.

我可以用Jackson Lib成功解析这个结构化字符串吗?

java json jackson

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