From 7b148ed832938a93621a57478c7456d181199052 Mon Sep 17 00:00:00 2001 From: Nathan Dunn Date: Tue, 16 Mar 2021 10:14:03 -0700 Subject: [PATCH] added test websockets (#2593) * added test websockets * opened up app * updated * updated * adding more debugging * did a round trip * updated * cleaned up * further cleanup --- .../apollo/AnnotationEditorController.groovy | 28 +++++++++++++++++++ .../org/bbop/apollo/AuthController.groovy | 4 +-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/grails-app/controllers/org/bbop/apollo/AnnotationEditorController.groovy b/grails-app/controllers/org/bbop/apollo/AnnotationEditorController.groovy index 0e1b4270cf..6f90e1c588 100644 --- a/grails-app/controllers/org/bbop/apollo/AnnotationEditorController.groovy +++ b/grails-app/controllers/org/bbop/apollo/AnnotationEditorController.groovy @@ -1270,6 +1270,7 @@ class AnnotationEditorController extends AbstractApolloController implements Ann @SendTo("/topic/AnnotationNotification") @Timed protected String annotationEditor(String inputString, Principal principal) { + log.debug("Web socket connected: ${inputString}") inputString = annotationEditorService.cleanJSONString(inputString) JSONObject rootElement = (JSONObject) JSON.parse(inputString) rootElement.put(FeatureStringEnum.USERNAME.value, principal.name) @@ -1280,6 +1281,13 @@ class AnnotationEditorController extends AbstractApolloController implements Ann log.debug "operationName: ${operationName}" def p = task { switch (operationName) { + case "ping": + return "pong" + break + // test case + case "broadcast": + broadcastMessage("pong",principal?.name) + break case "logout": SecurityUtils.subject.logout() break @@ -1334,6 +1342,26 @@ class AnnotationEditorController extends AbstractApolloController implements Ann } + /** + * Note: this is a test websocket method + * @param message + * @param username + * @return + */ + protected def broadcastMessage(String message,String username){ + println "bradcasting message: ${message}" + brokerMessagingTemplate.convertAndSend("/topic/AnnotationNotification", message) + println "broadcast message: ${message}" + if(username){ + println "send error to user" + sendError(new RuntimeException("whoops"),username) + println "sent error to user" + } + println "sending annotation vent" + sendAnnotationEvent("annotation event of some kind") + println "sent annotation event" + } + // TODO: handle errors without broadcasting protected def sendError(Throwable exception, String username) { log.error "exception ${exception}" diff --git a/grails-app/controllers/org/bbop/apollo/AuthController.groovy b/grails-app/controllers/org/bbop/apollo/AuthController.groovy index 73fd3f4e77..63009fcf03 100644 --- a/grails-app/controllers/org/bbop/apollo/AuthController.groovy +++ b/grails-app/controllers/org/bbop/apollo/AuthController.groovy @@ -30,7 +30,7 @@ class AuthController { // If a controller redirected to this page, redirect back // to it. Otherwise redirect to the root URI. def targetUri = params.targetUri ?: "/" - + // Handle requests saved by Shiro filters. SavedRequest savedRequest = WebUtils.getSavedRequest(request) if (savedRequest) { @@ -50,7 +50,6 @@ class AuthController { // will be thrown if the username is unrecognised or the // password is incorrect. permissionService.authenticateWithToken(authToken,request) -// SecurityUtils.subject.login(authToken) if(targetUri) { if (targetUri.contains("http://") || targetUri.contains("https://") || targetUri.contains("ftp://")) { redirect(uri: "${request.contextPath}${targetUri}") @@ -58,7 +57,6 @@ class AuthController { else { redirect(uri: targetUri) } - return } }