Skip to content

Commit

Permalink
Merge 9b25de0 into efa9042
Browse files Browse the repository at this point in the history
  • Loading branch information
asgeirn committed Feb 25, 2019
2 parents efa9042 + 9b25de0 commit 83ccd18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.springframework.boot:spring-boot-starter-actuator')

testCompile('no.fint:fint-test-utils:0.0.4')
testCompile('no.fint:fint-test-utils:0.0.5-rc-1')
testCompile("cglib:cglib-nodep:${cglibVersion}")
testCompile("org.spockframework:spock-spring:${spockSpringVersion}")
testCompile("org.spockframework:spock-core:${spockSpringVersion}")
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/no/fint/provider/events/sse/SseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -41,14 +42,17 @@ public class SseController {
public ResponseEntity<SseEmitter> subscribe(
@ApiParam(Constants.SWAGGER_X_ORG_ID) @RequestHeader(HeaderConstants.ORG_ID) String orgId,
@ApiParam("ID of client.") @RequestHeader(HeaderConstants.CLIENT) String client,
@ApiParam("Global unique id for the client. Typically a UUID.") @PathVariable String id) {
@ApiParam("Global unique id for the client. Typically a UUID.") @PathVariable String id) throws IOException {
log.info("{}: Client {}, ID {}", orgId, client, id);
if (adminService.register(orgId, client)) {
SseEmitter emitter = sseService.subscribe(id, orgId, client);
fintEvents.registerDownstreamListener(orgId, downstreamSubscriber);
return ResponseEntity.ok(emitter);
} else {
return ResponseEntity.badRequest().header("x-Error", "Invalid orgID " + orgId).build();
// TODO: This trick will "stall" clients that aren't enabled, so they won't keep reconnecting.
SseEmitter emitter = new SseEmitter();
emitter.send(SseEmitter.event().comment("Invalid orgID " + orgId));
return ResponseEntity.ok().header("x-Error", "Invalid orgID " + orgId).body(emitter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import no.fint.events.FintEvents
import no.fint.provider.events.admin.AdminService
import no.fint.provider.events.subscriber.DownstreamSubscriber
import no.fint.test.utils.MockMvcSpecification
import org.hamcrest.CoreMatchers
import org.springframework.test.web.servlet.MockMvc

class SseControllerSpec extends MockMvcSpecification {
Expand Down Expand Up @@ -47,7 +48,7 @@ class SseControllerSpec extends MockMvcSpecification {
1 * adminService.register('rogfk.no', 'client') >> false
0 * sseService.subscribe('123', 'rogfk.no', 'client')
0 * fintEvents.registerDownstreamListener('rogfk.no', downstreamSubscriber)
response.andExpect(status().is4xxClientError())
response.andExpect(header().string('x-Error', CoreMatchers.startsWith('Invalid orgID')))

}

Expand Down

0 comments on commit 83ccd18

Please sign in to comment.