@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(); } }
URI uri = session.getRequestURI(); String rawPath = uri.getPath(); String contextPath = framework.getAtmosphereConfig().getServletContext().getContextPath();
@Test public void onOpen() throws Throwable { URI uri = URI.create("http://example.org"); given(this.session.getRequestURI()).willReturn(uri); this.adapter.onOpen(this.session, null); verify(this.webSocketHandler).afterConnectionEstablished(this.webSocketSession); verify(this.session, atLeast(2)).addMessageHandler(any(MessageHandler.Whole.class)); given(this.session.getRequestURI()).willReturn(uri); assertEquals(uri, this.webSocketSession.getUri()); }
@OnOpen public void start(Session wsSession) { current.set(wsSession); try { URI uri = wsSession.getRequestURI(); String path = uri.getPath(); log.fine("Establishing session for " + path); String contextPath = path.substring(0, path.lastIndexOf('/')); PluginContext context = WebPluginLifeCycle.getPluginContext(contextPath); if (context != null) { Boolean enabled = context.getProperty(WebPlugin.ENABLED); if (enabled != null && enabled) { log.fine("Using shell " + context); ShellFactory factory = context.getPlugin(ShellFactory.class); Principal user = wsSession.getUserPrincipal(); Shell shell = factory.create(user); CRaSHSession session = new CRaSHSession(wsSession, shell); sessions.put(wsSession.getId(), session); log.fine("Established session " + wsSession.getId()); } else { log.fine("Web plugin disabled"); } } else { log.fine("No shell found"); } } finally { current.set(null); } }
@Override public String getUrl() { return session.getRequestURI().toString(); }
public String getUri() { return session.getRequestURI().toString(); } }
@Override public final InetSocketAddress getRemoteAddress() { return InetSocketAddress.createUnresolved(session.getRequestURI().getHost(), session.getRequestURI().getPort()); }
@Override public String getPath() { String path = session.getRequestURI().getPath(); if (path == null) { return null; } if (contextPath.length() > 1 && path.startsWith(contextPath)) { path = path.substring(contextPath.length()); } if (prefix.length() > 0 && path.startsWith(prefix)) { path = path.substring(prefix.length()); } return path; }
@Override public final String toString() { StringBuilder sb = new StringBuilder("WebSocket connection at ").append(session.getRequestURI()); final String streamId = getStreamId(); if (streamId != null) { sb.append(" (").append(streamId).append(')'); } return sb.toString(); } }
@ScriptFunction public String getUri() { return webSocketSession.getRequestURI().toString(); }
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); }
@OnOpen public synchronized void onOpen(Session session) { LOGGER.info("[PubSub] Connected: "+session.getRequestURI()); connectedSince = System.currentTimeMillis(); this.s = session; handler.handleConnect(); }
/** * {@inheritDoc} */ @Override public URI getUri() { checkNativeSessionInitialized(); return getNativeSession().getRequestURI(); }
public synchronized String getStatus() { if (!connecting) { return "Not connected"; } if (s != null && s.isOpen()) { return String.format("Connected to %s for %s (last message received %s ago)", s.getRequestURI(), DateTime.ago(connectedSince), DateTime.ago(lastMessageReceived)); } return "Connecting.."; }
public JavaxUpgradeHttpRequest(final Session session, EndpointConfig endpointConfig) { Map<String, Object> userProperties = session.getUserProperties(); if (userProperties == null || userProperties.isEmpty()) { // workaround for JBoss Wildfly 8.0.Final userProperties = endpointConfig.getUserProperties(); } this.httpSession = (HttpSession) userProperties.get("session"); this.headers = (Map<String, List<String>>) userProperties.get("headers"); this.queryString = session.getQueryString(); this.userPrincipal = session.getUserPrincipal(); Object requestURI = session.getRequestURI(); this.requestUri = requestURI != null ? requestURI.toString() : ""; this.parametersMap = new HashMap<>(); Map<String, List<String>> parameters = session.getRequestParameterMap(); if (parameters != null) { for (Map.Entry<String, List<String>> entry : parameters.entrySet()) { String name = entry.getKey(); List<String> value = entry.getValue(); parametersMap.put(name, value.toArray(new String[0])); } } }
public JavaxUpgradeHttpRequest(final Session session, EndpointConfig endpointConfig) { Map<String, Object> userProperties = session.getUserProperties(); if (userProperties == null || userProperties.isEmpty()) { // workaround for JBoss Wildfly 8.0.Final userProperties = endpointConfig.getUserProperties(); } this.httpSession = (HttpSession) userProperties.get("session"); this.headers = (Map<String, List<String>>) userProperties.get("headers"); this.queryString = session.getQueryString(); this.userPrincipal = session.getUserPrincipal(); Object requestURI = session.getRequestURI(); this.requestUri = requestURI != null ? requestURI.toString() : ""; this.parametersMap = new HashMap<>(); Map<String, List<String>> parameters = session.getRequestParameterMap(); if (parameters != null) { for (Map.Entry<String, List<String>> entry : parameters.entrySet()) { String name = entry.getKey(); List<String> value = entry.getValue(); parametersMap.put(name, value.toArray(new String[0])); } } }
@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 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(); } }
private WebSocketClientProtocolHandler makeWsProtocolHandler(Session session) { WebSocketVersion version = Utils.getWsVersion(session.getProtocolVersion()); WebSocketClientHandshaker wshs = WebSocketClientHandshakerFactory.newHandshaker(session.getRequestURI(), version, null, true, new DefaultHttpHeaders()); return new WebSocketClientProtocolHandler(wshs); }
/** * Get Websocket status in text form, with some basic formatting. * * @return */ public synchronized String getStatus() { if (!connecting) { return "Not connected"; } if (s != null && s.isOpen()) { return String.format("Connected for %s\n" + "\tServer: %s\n" + "\tCommands sent: %d (last %s ago)\n" + "\tMessages received: %d (last %s ago)\n" + "\tLatency: %dms (%s)", DateTime.ago(timeConnected), s.getRequestURI(), sentCount, DateTime.ago(timeLastMessageSent), receivedCount, DateTime.ago(timeLastMessageReceived), lastMeasuredLatency, timeLatencyMeasured == 0 ? "not yet measured" : "measured "+DateTime.ago(timeLatencyMeasured)+" ago"); } return "Connecting.."; }