|
|
|
@ -18,6 +18,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
@@ -18,6 +18,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; |
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletResponse; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
*<p> |
|
|
|
|
* 物流地图SSE长连接 控制层 |
|
|
|
@ -40,14 +44,16 @@ public class MapLogisticSseController {
@@ -40,14 +44,16 @@ public class MapLogisticSseController {
|
|
|
|
|
private final OAuth2ClientContext oAuth2ClientContext; |
|
|
|
|
|
|
|
|
|
@Inner(false) |
|
|
|
|
@GetMapping(value = "/subscribe", produces = { MediaType.TEXT_EVENT_STREAM_VALUE }) |
|
|
|
|
public SseEmitter subscribe(String accessToken, String clientId) { |
|
|
|
|
@GetMapping(value = "/subscribe") |
|
|
|
|
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.setCharacterEncoding("UTF-8"); |
|
|
|
|
return iMapLogisticSseService.SseSubscribe(clientId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|