Skip to content

Commit

Permalink
added test websockets (#2593)
Browse files Browse the repository at this point in the history
* added test websockets

* opened up app

* updated

* updated

* adding more debugging

* did a round trip

* updated

* cleaned up

* further cleanup
  • Loading branch information
nathandunn committed Mar 16, 2021
1 parent 8ba683f commit 7b148ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
4 changes: 1 addition & 3 deletions grails-app/controllers/org/bbop/apollo/AuthController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -50,15 +50,13 @@ 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}")
}
else {
redirect(uri: targetUri)
}

return
}
}
Expand Down

0 comments on commit 7b148ed

Please sign in to comment.