@Test public void missingDefaultOffset() throws Exception { when(request.getURI()) .thenReturn(URI.create("ws: Map<String, Object> attributes = new HashMap<>(); underTest.beforeHandshake(request, null, null, attributes); assertThat(attributes.get(ROAD_NAME), is("road1")); assertThat(attributes.get(STREAM_NAME), is("stream1")); assertThat(attributes.get(DEFAULT_OFFSET), is(LATEST)); assertThat(attributes.get(GRANTS), is(singleton(PII))); }
@Override public boolean beforeHandshake( ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { log.info("Request received: {} {} - with headers: {}", request.getMethod(), request.getURI(), request.getHeaders()); Map<String, String> segments = URI_TEMPLATE.match(request.getURI().getPath()); attributes.put(VERSION, segments.get(VERSION)); attributes.put(ROAD_NAME, segments.get(ROAD_NAME)); attributes.put(STREAM_NAME, segments.get(STREAM_NAME)); MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUri(request.getURI()).build().getQueryParams(); DefaultOffset defaultOffset = Mono .justOrEmpty(parameters.getFirst(DEFAULT_OFFSET)) .map(DefaultOffset::valueOf) .defaultIfEmpty(LATEST) .block(); attributes.put(DEFAULT_OFFSET, defaultOffset); Set<Sensitivity> grants = Mono .justOrEmpty(parameters.get(GRANTS)) .flatMapMany(Flux::fromIterable) .filter(s -> !s.isEmpty()) .map(Sensitivity::valueOf) .collect(toSet()) .block(); attributes.put(GRANTS, grants); return super.beforeHandshake(request, response, wsHandler, attributes); }
OfframpHandshakeInterceptor extends HttpSessionHandshakeInterceptor { @Override public boolean beforeHandshake( ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { log.info("Request received: {} {} - with headers: {}", request.getMethod(), request.getURI(), request.getHeaders()); Map<String, String> segments = URI_TEMPLATE.match(request.getURI().getPath()); attributes.put(VERSION, segments.get(VERSION)); attributes.put(ROAD_NAME, segments.get(ROAD_NAME)); attributes.put(STREAM_NAME, segments.get(STREAM_NAME)); MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUri(request.getURI()).build().getQueryParams(); DefaultOffset defaultOffset = Mono .justOrEmpty(parameters.getFirst(DEFAULT_OFFSET)) .map(DefaultOffset::valueOf) .defaultIfEmpty(LATEST) .block(); attributes.put(DEFAULT_OFFSET, defaultOffset); Set<Sensitivity> grants = Mono .justOrEmpty(parameters.get(GRANTS)) .flatMapMany(Flux::fromIterable) .filter(s -> !s.isEmpty()) .map(Sensitivity::valueOf) .collect(toSet()) .block(); attributes.put(GRANTS, grants); return super.beforeHandshake(request, response, wsHandler, attributes); } }
OfframpHandshakeInterceptor extends HttpSessionHandshakeInterceptor { @Override public boolean beforeHandshake( ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { log.info("Request received: {} {} - with headers: {}", request.getMethod(), request.getURI(), request.getHeaders()); Map<String, String> segments = URI_TEMPLATE.match(request.getURI().getPath()); attributes.put(VERSION, segments.get(VERSION)); attributes.put(ROAD_NAME, segments.get(ROAD_NAME)); attributes.put(STREAM_NAME, segments.get(STREAM_NAME)); MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUri(request.getURI()).build().getQueryParams(); DefaultOffset defaultOffset = Mono .justOrEmpty(parameters.getFirst(DEFAULT_OFFSET)) .map(DefaultOffset::valueOf) .defaultIfEmpty(LATEST) .block(); attributes.put(DEFAULT_OFFSET, defaultOffset); Set<Sensitivity> grants = Mono .justOrEmpty(parameters.get(GRANTS)) .flatMapMany(Flux::fromIterable) .filter(s -> !s.isEmpty()) .map(Sensitivity::valueOf) .collect(toSet()) .block(); attributes.put(GRANTS, grants); return super.beforeHandshake(request, response, wsHandler, attributes); }  }
OfframpHandshakeInterceptor extends HttpSessionHandshakeInterceptor { @Override public boolean beforeHandshake( ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { log.info("Request received: {} {} - with headers: {}", request.getMethod(), request.getURI(), request.getHeaders()); Map<String, String> segments = URI_TEMPLATE.match(request.getURI().getPath()); attributes.put(VERSION, segments.get(VERSION)); attributes.put(ROAD_NAME, segments.get(ROAD_NAME)); attributes.put(STREAM_NAME, segments.get(STREAM_NAME)); MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUri(request.getURI()).build().getQueryParams(); DefaultOffset defaultOffset = Mono .justOrEmpty(parameters.getFirst(DEFAULT_OFFSET)) .map(DefaultOffset::valueOf) .defaultIfEmpty(LATEST) .block(); attributes.put(DEFAULT_OFFSET, defaultOffset); Set<Sensitivity> grants = Mono .justOrEmpty(parameters.get(GRANTS)) .flatMapMany(Flux::fromIterable) .filter(s -> !s.isEmpty()) .map(Sensitivity::valueOf) .collect(toSet()) .block(); attributes.put(GRANTS, grants); return super.beforeHandshake(request, response, wsHandler, attributes); }  @Override boolean beforeHandshake(
      ServerHttpRequest request,
      ServerHttpResponse response,
      WebSocketHandler wsHandler,
      Map<String, Object> attributes); }
OfframpHandshakeInterceptor extends HttpSessionHandshakeInterceptor { @Override public boolean beforeHandshake( ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { log.info("Request received: {} {} - with headers: {}", request.getMethod(), request.getURI(), request.getHeaders()); Map<String, String> segments = URI_TEMPLATE.match(request.getURI().getPath()); attributes.put(VERSION, segments.get(VERSION)); attributes.put(ROAD_NAME, segments.get(ROAD_NAME)); attributes.put(STREAM_NAME, segments.get(STREAM_NAME)); MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUri(request.getURI()).build().getQueryParams(); DefaultOffset defaultOffset = Mono .justOrEmpty(parameters.getFirst(DEFAULT_OFFSET)) .map(DefaultOffset::valueOf) .defaultIfEmpty(LATEST) .block(); attributes.put(DEFAULT_OFFSET, defaultOffset); Set<Sensitivity> grants = Mono .justOrEmpty(parameters.get(GRANTS)) .flatMapMany(Flux::fromIterable) .filter(s -> !s.isEmpty()) .map(Sensitivity::valueOf) .collect(toSet()) .block(); attributes.put(GRANTS, grants); return super.beforeHandshake(request, response, wsHandler, attributes); }  @Override boolean beforeHandshake(
      ServerHttpRequest request,
      ServerHttpResponse response,
      WebSocketHandler wsHandler,
      Map<String, Object> attributes);  }