|
|
@ -2,15 +2,9 @@ package com.cloud.kicc.commonbiz.controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.cloud.kicc.common.core.api.R; |
|
|
|
import com.cloud.kicc.common.core.api.R; |
|
|
|
import com.cloud.kicc.common.core.constant.AppConstants; |
|
|
|
import com.cloud.kicc.common.core.constant.AppConstants; |
|
|
|
import com.cloud.kicc.common.security.annotation.Inner; |
|
|
|
|
|
|
|
import com.cloud.kicc.commonbiz.service.IMapLogisticSseService; |
|
|
|
import com.cloud.kicc.commonbiz.service.IMapLogisticSseService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.security.core.context.SecurityContext; |
|
|
|
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder; |
|
|
|
|
|
|
|
import org.springframework.security.oauth2.client.OAuth2ClientContext; |
|
|
|
|
|
|
|
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; |
|
|
|
|
|
|
|
import org.springframework.security.oauth2.provider.OAuth2Authentication; |
|
|
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.TokenStore; |
|
|
|
import org.springframework.security.oauth2.provider.token.TokenStore; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
@ -38,24 +32,15 @@ public class MapLogisticSseController { |
|
|
|
|
|
|
|
|
|
|
|
private final TokenStore tokenStore; |
|
|
|
private final TokenStore tokenStore; |
|
|
|
|
|
|
|
|
|
|
|
private final OAuth2ClientContext oAuth2ClientContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inner(false) |
|
|
|
@GetMapping("/subscribe") |
|
|
|
@GetMapping(value = "/subscribe") |
|
|
|
public SseEmitter subscribe(String clientId, ServletResponse response) { |
|
|
|
public SseEmitter subscribe(String accessToken, String clientId, ServletResponse response) { |
|
|
|
|
|
|
|
OAuth2Authentication oAuth2Authentication = tokenStore.readAuthentication(accessToken); |
|
|
|
|
|
|
|
SecurityContext context = SecurityContextHolder.createEmptyContext(); |
|
|
|
|
|
|
|
context.setAuthentication(oAuth2Authentication); |
|
|
|
|
|
|
|
DefaultOAuth2AccessToken defaultOAuth2AccessToken = new DefaultOAuth2AccessToken(accessToken); |
|
|
|
|
|
|
|
oAuth2ClientContext.setAccessToken(defaultOAuth2AccessToken); |
|
|
|
|
|
|
|
SecurityContextHolder.setContext(context); |
|
|
|
|
|
|
|
response.setContentType("text/event-stream;charset=UTF-8"); |
|
|
|
response.setContentType("text/event-stream;charset=UTF-8"); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
return iMapLogisticSseService.SseSubscribe(clientId); |
|
|
|
return iMapLogisticSseService.SseSubscribe(clientId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/sendMessage") |
|
|
|
@GetMapping("/sendMessage") |
|
|
|
|
|
|
|
|
|
|
|
public R sendMessage(String userId, String json) { |
|
|
|
public R sendMessage(String userId, String json) { |
|
|
|
iMapLogisticSseService.sendMessage(userId, sseSignalContainer -> sseSignalContainer.getSseEmitter().send(json)); |
|
|
|
iMapLogisticSseService.sendMessage(userId, sseSignalContainer -> sseSignalContainer.getSseEmitter().send(json)); |
|
|
|
return R.ok(); |
|
|
|
return R.ok(); |
|
|
|