Package org.eclipse.jetty.websocket.api

Examples of org.eclipse.jetty.websocket.api.Session


            messageQueue.offer(message);
        }

        public EndPoint getEndPoint() throws Exception
        {
            Session session = getSession();
            Assert.assertThat("Session type",session,instanceOf(WebSocketSession.class));

            WebSocketSession wssession = (WebSocketSession)session;
            Field fld = wssession.getClass().getDeclaredField("connection");
            fld.setAccessible(true);
View Full Code Here


    given(request.getUserPrincipal()).willReturn(user);

    UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
    given(response.getAcceptedSubProtocol()).willReturn(null);

    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUpgradeRequest()).willReturn(request);
    given(nativeSession.getUpgradeResponse()).willReturn(response);

    JettyWebSocketSession session = new JettyWebSocketSession(attributes);
    session.initializeNativeSession(nativeSession);

    reset(nativeSession);
View Full Code Here

    given(request.getUserPrincipal()).willReturn(null);

    UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
    given(response.getAcceptedSubProtocol()).willReturn(null);

    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUpgradeRequest()).willReturn(request);
    given(nativeSession.getUpgradeResponse()).willReturn(response);

    JettyWebSocketSession session = new JettyWebSocketSession(attributes);
    session.initializeNativeSession(nativeSession);

    reset(nativeSession);
View Full Code Here

    given(request.getUserPrincipal()).willReturn(null);

    UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
    given(response.getAcceptedSubProtocol()).willReturn(protocol);

    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUpgradeRequest()).willReturn(request);
    given(nativeSession.getUpgradeResponse()).willReturn(response);

    JettyWebSocketSession session = new JettyWebSocketSession(attributes);
    session.initializeNativeSession(nativeSession);

    reset(nativeSession);
View Full Code Here

        }

        @Override
        public void send(String content)
        {
            Session session;
            synchronized (this)
            {
                session = _session;
            }
            try
            {
                if (session == null)
                    throw new IOException("Unconnected");

                // Blocking async sends for the client to allow concurrent sends.
               session.getRemote().sendStringByFuture(content).get();
            }
            catch (Throwable x)
            {
                fail(x, "Exception");
            }
View Full Code Here

        }

        @Override
        protected void shutdown(String reason)
        {
            Session session;
            synchronized (this)
            {
                session = _session;
                close();
            }
            if (session != null)
            {
                if (logger.isDebugEnabled())
                    logger.debug("Closing websocket session {}", session);
                session.close(1000, reason);
            }
        }
View Full Code Here

    public void jsFunction_send(String data) throws IOException
    {
        try
        {
            Session session = this.session;
            if (session != null)
            {
                if (logger.isDebugEnabled())
                    logger.debug("WebSocket sending data {}", data);
                session.getRemote().sendString(data);
            }
        }
        catch (final Throwable x)
        {
            // This method is invoked from JavaScript, so we must fail asynchronously
View Full Code Here

        }
    }

    public void jsFunction_close(int code, String reason) throws IOException
    {
        Session session = this.session;
        if (session != null)
        {
            session.close(code, reason);
            this.session = null;
        }
    }
View Full Code Here

      String clientPagePath = socket.getPagePath();
      if (clientPagePath != null && !clientPagePath.equals(URIUtil.encodePath(pagePath))) {
        continue;
      }

      Session session = socket.getSession();

      webSocketData.setCallback(socket.getCallback());

      if ((session != null)) { //&& socket.isAuthenticated()) {

        List<? extends GraphObject> result = webSocketData.getResult();

        if ((result != null) && (result.size() > 0)
          && (webSocketData.getCommand().equals("UPDATE") || webSocketData.getCommand().equals("ADD") || webSocketData.getCommand().equals("CREATE"))) {

          WebSocketMessage clientData = webSocketData.copy();
          SecurityContext securityContext = socket.getSecurityContext();

          // For non-authenticated clients, construct a security context without user
          if (securityContext == null) {

            try {

              securityContext = SecurityContext.getInstance(null, AccessMode.Frontend);

            } catch (FrameworkException ex) {

              continue;
            }
          }

          clientData.setResult(filter(securityContext, result));

          message = gson.toJson(clientData, WebSocketMessage.class);

        } else {

          message = gson.toJson(webSocketData, WebSocketMessage.class);
        }

        //logger.log(Level.INFO, "############################################################ SENDING \n{0}", message);
        try {

          session.getRemote().sendString(message);

        } catch (Throwable t) {

          if (t instanceof WebSocketException) {
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.websocket.api.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.