@Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); this.uri = session.getRequestURI(); this.acceptedProtocol = session.getNegotiatedSubprotocol(); List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions(); if (!CollectionUtils.isEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); } this.extensions = Collections.unmodifiableList(this.extensions); } else { this.extensions = Collections.emptyList(); } if (this.user == null) { this.user = session.getUserPrincipal(); } }
@Test @SuppressWarnings("resource") public void getAcceptedProtocol() { String protocol = "foo"; Session nativeSession = Mockito.mock(Session.class); given(nativeSession.getNegotiatedSubprotocol()).willReturn(protocol); StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null); session.initializeNativeSession(nativeSession); reset(nativeSession); assertEquals(protocol, session.getAcceptedProtocol()); verifyNoMoreInteractions(nativeSession); }
public static WebSocketTransportRequest create(WebSocketServerMessageHandler webSocketMessageHandler, Session session, String contextPath, String endpointPath, Reader reader) { String requestUri = session.getRequestURI().getPath(); if (log.isDebugEnabled()) log.debug("Request URI: " + requestUri); String requestPath = requestUri.substring(contextPath.length() + endpointPath.length()); if (! requestPath.startsWith("/")) requestPath = "/" + requestPath; try { requestPath = URLDecoder.decode(requestPath, "UTF-8"); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex.getMessage(), ex); } String negotiatedSubprotocol = session.getNegotiatedSubprotocol(); return new WebSocketTransportRequest(webSocketMessageHandler, requestPath, negotiatedSubprotocol, reader); }
/** * {@inheritDoc} */ @Override public String getNegotiatedProtocol() { checkNativeSessionInitialized(); return getNativeSession().getNegotiatedSubprotocol(); }
@Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); this.uri = session.getRequestURI(); this.acceptedProtocol = session.getNegotiatedSubprotocol(); List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions(); if (!CollectionUtils.isEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); } this.extensions = Collections.unmodifiableList(this.extensions); } else { this.extensions = Collections.emptyList(); } if (this.user == null) { this.user = session.getUserPrincipal(); } }
String contentType = session.getNegotiatedSubprotocol(); MimeType recvMimeType = contentType != null ? new MimeType(contentType) : null; xdiReader = recvMimeType != null ? XDIReaderRegistry.forMimeType(recvMimeType) : null;
@Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); this.uri = session.getRequestURI(); this.acceptedProtocol = session.getNegotiatedSubprotocol(); List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions(); if (!CollectionUtils.isEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); } this.extensions = Collections.unmodifiableList(this.extensions); } else { this.extensions = Collections.emptyList(); } if (this.user == null) { this.user = session.getUserPrincipal(); } }
@Override @SuppressWarnings("unchecked") public void run() { String subprotocol = session.getNegotiatedSubprotocol(); for (MessageAndMetadata<byte[], byte[]> messageAndMetadata : (Iterable<MessageAndMetadata<byte[], byte[]>>) stream) { String topic = messageAndMetadata.topic(); byte[] message = messageAndMetadata.message(); switch(subprotocol) { case "kafka-binary": sendBinary(topic, message); break; default: sendText(topic, message); break; } if (Thread.currentThread().isInterrupted()) { try { session.close(); } catch (IOException e) { LOG.error("Error terminating session: {}", e.getMessage()); } return; } } }