org.springframework.web.HttpRequestHandler Java Examples
The following examples show how to use
org.springframework.web.HttpRequestHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void handshakeHandlerAndInterceptorWithAllowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); String origin = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo"), entry.getValue()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertSame(handshakeHandler, requestHandler.getHandshakeHandler()); assertEquals(2, requestHandler.getHandshakeInterceptors().size()); assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass()); }
Example #2
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void handshakeHandlerAndInterceptor() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo"), entry.getValue()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertSame(handshakeHandler, requestHandler.getHandshakeHandler()); assertEquals(2, requestHandler.getHandshakeInterceptors().size()); assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass()); }
Example #3
Source File: ServletWebSocketHandlerRegistry.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Return a {@link HandlerMapping} with mapped {@link HttpRequestHandler}s. */ public AbstractHandlerMapping getHandlerMapping() { Map<String, Object> urlMap = new LinkedHashMap<String, Object>(); for (ServletWebSocketHandlerRegistration registration : this.registrations) { MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); for (HttpRequestHandler httpHandler : mappings.keySet()) { for (String pattern : mappings.get(httpHandler)) { urlMap.put(pattern, httpHandler); } } } WebSocketHandlerMapping hm = new WebSocketHandlerMapping(); hm.setUrlMap(urlMap); hm.setOrder(this.order); if (this.urlPathHelper != null) { hm.setUrlPathHelper(this.urlPathHelper); } return hm; }
Example #4
Source File: WebMvcStompEndpointRegistry.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Return a handler mapping with the mapped ViewControllers; or {@code null} * in case of no registrations. */ public AbstractHandlerMapping getHandlerMapping() { Map<String, Object> urlMap = new LinkedHashMap<String, Object>(); for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) { MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); for (HttpRequestHandler httpHandler : mappings.keySet()) { for (String pattern : mappings.get(httpHandler)) { urlMap.put(pattern, httpHandler); } } } WebSocketHandlerMapping hm = new WebSocketHandlerMapping(); hm.setUrlMap(urlMap); hm.setOrder(this.order); if (this.urlPathHelper != null) { hm.setUrlPathHelper(this.urlPathHelper); } return hm; }
Example #5
Source File: ServletWebSocketHandlerRegistry.java From spring-analysis-note with MIT License | 6 votes |
public AbstractHandlerMapping getHandlerMapping() { Map<String, Object> urlMap = new LinkedHashMap<>(); for (ServletWebSocketHandlerRegistration registration : this.registrations) { MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); mappings.forEach((httpHandler, patterns) -> { for (String pattern : patterns) { urlMap.put(pattern, httpHandler); } }); } WebSocketHandlerMapping hm = new WebSocketHandlerMapping(); hm.setUrlMap(urlMap); hm.setOrder(this.order); if (this.urlPathHelper != null) { hm.setUrlPathHelper(this.urlPathHelper); } return hm; }
Example #6
Source File: WebMvcStompEndpointRegistry.java From spring-analysis-note with MIT License | 6 votes |
/** * Return a handler mapping with the mapped ViewControllers. */ public AbstractHandlerMapping getHandlerMapping() { Map<String, Object> urlMap = new LinkedHashMap<>(); for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) { MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); mappings.forEach((httpHandler, patterns) -> { for (String pattern : patterns) { urlMap.put(pattern, httpHandler); } }); } WebSocketHandlerMapping hm = new WebSocketHandlerMapping(); hm.setUrlMap(urlMap); hm.setOrder(this.order); if (this.urlPathHelper != null) { hm.setUrlPathHelper(this.urlPathHelper); } return hm; }
Example #7
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void handshakeHandlerAndInterceptorWithAllowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); String origin = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo"), entry.getValue()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertSame(handshakeHandler, requestHandler.getHandshakeHandler()); assertEquals(2, requestHandler.getHandshakeInterceptors().size()); assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass()); }
Example #8
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void handshakeHandlerAndInterceptor() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo"), entry.getValue()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertSame(handshakeHandler, requestHandler.getHandshakeHandler()); assertEquals(2, requestHandler.getHandshakeInterceptors().size()); assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass()); }
Example #9
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void handshakeHandlerAndInterceptor() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo"), entry.getValue()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertSame(handshakeHandler, requestHandler.getHandshakeHandler()); assertEquals(2, requestHandler.getHandshakeInterceptors().size()); assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass()); }
Example #10
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void handshakeHandlerAndInterceptorWithAllowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); String origin = "https://mydomain.com"; registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo"), entry.getValue()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertSame(handshakeHandler, requestHandler.getHandshakeHandler()); assertEquals(2, requestHandler.getHandshakeInterceptors().size()); assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass()); }
Example #11
Source File: WebMvcStompEndpointRegistry.java From java-technology-stack with MIT License | 6 votes |
/** * Return a handler mapping with the mapped ViewControllers. */ public AbstractHandlerMapping getHandlerMapping() { Map<String, Object> urlMap = new LinkedHashMap<>(); for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) { MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); mappings.forEach((httpHandler, patterns) -> { for (String pattern : patterns) { urlMap.put(pattern, httpHandler); } }); } WebSocketHandlerMapping hm = new WebSocketHandlerMapping(); hm.setUrlMap(urlMap); hm.setOrder(this.order); if (this.urlPathHelper != null) { hm.setUrlPathHelper(this.urlPathHelper); } return hm; }
Example #12
Source File: ServletWebSocketHandlerRegistry.java From java-technology-stack with MIT License | 6 votes |
public AbstractHandlerMapping getHandlerMapping() { Map<String, Object> urlMap = new LinkedHashMap<>(); for (ServletWebSocketHandlerRegistration registration : this.registrations) { MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); mappings.forEach((httpHandler, patterns) -> { for (String pattern : patterns) { urlMap.put(pattern, httpHandler); } }); } WebSocketHandlerMapping hm = new WebSocketHandlerMapping(); hm.setUrlMap(urlMap); hm.setOrder(this.order); if (this.urlPathHelper != null) { hm.setUrlPathHelper(this.urlPathHelper); } return hm; }
Example #13
Source File: ServletWebSocketHandlerRegistration.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void addSockJsServiceMapping(MultiValueMap<HttpRequestHandler, String> mappings, SockJsService sockJsService, WebSocketHandler handler, String pathPattern) { SockJsHttpRequestHandler httpHandler = new SockJsHttpRequestHandler(sockJsService, handler); mappings.add(httpHandler, pathPattern); }
Example #14
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void allowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); registration.setAllowedOrigins(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler)mappings.entrySet().iterator().next().getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertEquals(1, requestHandler.getHandshakeInterceptors().size()); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(0).getClass()); }
Example #15
Source File: ResourceHandlerRegistry.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Return a handler mapping with the mapped resource handlers; or {@code null} in case of no registrations. */ protected AbstractHandlerMapping getHandlerMapping() { if (registrations.isEmpty()) { return null; } Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>(); for (ResourceHandlerRegistration registration : this.registrations) { for (String pathPattern : registration.getPathPatterns()) { ResourceHttpRequestHandler handler = registration.getRequestHandler(); handler.setServletContext(this.servletContext); handler.setApplicationContext(this.appContext); try { handler.afterPropertiesSet(); } catch (Exception e) { throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", e); } urlMap.put(pathPattern, handler); } } SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setOrder(order); handlerMapping.setUrlMap(urlMap); return handlerMapping; }
Example #16
Source File: DefaultServletHandlerConfigurer.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; or {@code null} if * default servlet handling was not been enabled. */ protected AbstractHandlerMapping getHandlerMapping() { if (handler == null) { return null; } Map<String, HttpRequestHandler> urlMap = new HashMap<String, HttpRequestHandler>(); urlMap.put("/**", handler); SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setOrder(Integer.MAX_VALUE); handlerMapping.setUrlMap(urlMap); return handlerMapping; }
Example #17
Source File: HttpRequestHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { ((HttpRequestHandler) handler).handleRequest(request, response); return null; }
Example #18
Source File: ResourceHandlerRegistry.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return a handler mapping with the mapped resource handlers; or {@code null} in case * of no registrations. */ protected AbstractHandlerMapping getHandlerMapping() { if (this.registrations.isEmpty()) { return null; } Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>(); for (ResourceHandlerRegistration registration : this.registrations) { for (String pathPattern : registration.getPathPatterns()) { ResourceHttpRequestHandler handler = registration.getRequestHandler(); handler.setServletContext(this.servletContext); handler.setApplicationContext(this.applicationContext); handler.setContentNegotiationManager(this.contentNegotiationManager); try { handler.afterPropertiesSet(); } catch (Throwable ex) { throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex); } urlMap.put(pathPattern, handler); } } SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setOrder(order); handlerMapping.setUrlMap(urlMap); return handlerMapping; }
Example #19
Source File: HttpRequestHandlerAdapter.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { ((HttpRequestHandler) handler).handleRequest(request, response); return null; }
Example #20
Source File: ServletWebSocketHandlerRegistration.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void addWebSocketHandlerMapping(MultiValueMap<HttpRequestHandler, String> mappings, WebSocketHandler wsHandler, HandshakeHandler handshakeHandler, HandshakeInterceptor[] interceptors, String path) { WebSocketHttpRequestHandler httpHandler = new WebSocketHttpRequestHandler(wsHandler, handshakeHandler); if (!ObjectUtils.isEmpty(interceptors)) { httpHandler.setHandshakeInterceptors(Arrays.asList(interceptors)); } mappings.add(httpHandler, path); }
Example #21
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void minimalRegistration() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertNotNull(((WebSocketHttpRequestHandler) entry.getKey()).getWebSocketHandler()); assertEquals(1, ((WebSocketHttpRequestHandler) entry.getKey()).getHandshakeInterceptors().size()); assertEquals(Arrays.asList("/foo"), entry.getValue()); }
Example #22
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); String origin = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler) .addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); }
Example #23
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void sameOrigin() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); registration.setAllowedOrigins(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler)mappings.entrySet().iterator().next().getKey(); assertNotNull(requestHandler.getWebSocketHandler()); assertEquals(1, requestHandler.getHandshakeInterceptors().size()); assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(0).getClass()); }
Example #24
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test // SPR-12283 public void disableCorsWithSockJsService() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); registration.withSockJS().setSupressCors(true); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler)mappings.entrySet().iterator().next().getKey(); assertNotNull(requestHandler.getSockJsService()); DefaultSockJsService sockJsService = (DefaultSockJsService)requestHandler.getSockJsService(); assertTrue(sockJsService.shouldSuppressCors()); }
Example #25
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void handshakeHandlerInterceptorWithSockJsService() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); }
Example #26
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); String origin = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); }
Example #27
Source File: WallRideWebMvcConfiguration.java From wallride with Apache License 2.0 | 5 votes |
@Bean public SimpleUrlHandlerMapping mediaUrlHandlerMapping( ApplicationContext applicationContext, ServletContext servletContext, ContentNegotiationManager contentNegotiationManager) { MediaHttpRequestHandler handler = new MediaHttpRequestHandler(); handler.setServletContext(servletContext); handler.setApplicationContext(applicationContext); handler.setContentNegotiationManager(contentNegotiationManager); handler.setWallRideProperties(wallRideProperties); handler.setMediaService(mediaService); handler.setResourceLoader(resourceLoader); handler.setCacheSeconds(86400); try { handler.afterPropertiesSet(); } catch (Exception e) { throw new BeanInitializationException("Failed to init MediaHttpRequestHandler", e); } Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<>(); urlMap.put("/media/{key}", handler); SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); handlerMapping.setOrder(0); handlerMapping.setUrlMap(urlMap); return handlerMapping; }
Example #28
Source File: KSBDispatcherServlet.java From rice with Educational Community License v2.0 | 5 votes |
@Override protected HandlerAdapter getHandlerAdapter(Object handler) throws ServletException { if (handler instanceof HttpRequestHandler) { return new HttpRequestHandlerAdapter(); } else if (handler instanceof Controller) { Object unwrappedHandler = ClassLoaderUtils.unwrapFromProxy(handler); if (unwrappedHandler instanceof CXFServletControllerAdapter) { // TODO this just seems weird as this controller is initially null when it's created, does there need to be some synchronization here? ((CXFServletControllerAdapter)unwrappedHandler).setController(cxfServletController); } return new SimpleControllerHandlerAdapter(); } throw new RiceRuntimeException("handler of type " + handler.getClass().getName() + " is not known and can't be used by " + KSBDispatcherServlet.class.getName()); }
Example #29
Source File: AbstractShowTestGroupsController.java From proctor with Apache License 2.0 | 5 votes |
private void handle(final HttpServletRequest request, final HttpServletResponse response, final HttpRequestHandler handler) throws IOException, ServletException { if (isAccessAllowed(request)) { handler.handleRequest(request, response); } else { response.sendError(getAccessDeniedStatusCode()); } }
Example #30
Source File: HttpRequestHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { ((HttpRequestHandler) handler).handleRequest(request, response); return null; }