Package org.jwebsocket.server

Examples of org.jwebsocket.server.TokenServer


      log.debug("Instantiating default servers...");
    }
    List<WebSocketServer> servers = new FastList<WebSocketServer>();
    // instantiate the Token server by default
    ServerConfiguration config = getServerConfiguration();
    TokenServer tokenServer = new TokenServer(config);
    servers.add(tokenServer);
    if (log.isInfoEnabled()) {
      log.info("Default server " + tokenServer.getId() + " instantiated.");
    }

    List<WebSocketServer> customServers = initializeCustomServers();
    if (customServers != null) {
      if (log.isDebugEnabled()) {
View Full Code Here


    System.out.println("Log files per default in jWebSocket.log if not overwritten in jWebSocket.xml.");

    JWebSocketFactory.start();

    // get the token server
    TokenServer lTS0 = (TokenServer) JWebSocketFactory.getServer("ts0");
    if (lTS0 != null) {
      // and add the sample listener to the server's listener chain
      lTS0.addListener(new JWebSocketTokenListenerSample());
    }

    // get the custom server
    CustomServer lCS0 = (CustomServer) JWebSocketFactory.getServer("cs0");
    if (lCS0 != null) {
View Full Code Here

   * shutdown server
   * @param aConnector
   * @param aToken
   */
  public void shutdown(WebSocketConnector aConnector, Token aToken) {
    TokenServer lServer = getServer();

    if (log.isDebugEnabled()) {
      log.debug("Processing 'shutdown'...");
    }

    // TODO: check for allowShutdown setting, irrespective of user right!

    // check if user is allowed to run 'shutdown' command
    if (!SecurityFactory.checkRight(lServer.getUsername(aConnector), NS_ADMIN + ".shutdown")) {
      lServer.sendToken(aConnector, lServer.createAccessDenied(aToken));
      return;
    }

    // notify clients about shutdown
    Token lResponseToken = lServer.createResponse(aToken);
    lResponseToken.put("msg", "Shutdown in progress...");
    lServer.broadcastToken(lResponseToken);

    JWebSocketInstance.setStatus(JWebSocketInstance.SHUTTING_DOWN);

  }
View Full Code Here

   * return all session
   * @param aConnector
   * @param aToken
   */
  public void getConnections(WebSocketConnector aConnector, Token aToken) {
    TokenServer lServer = getServer();

    if (log.isDebugEnabled()) {
      log.debug("Processing 'getConnections'...");
    }

    // check if user is allowed to run 'getConnections' command
    if (!SecurityFactory.checkRight(lServer.getUsername(aConnector), NS_ADMIN + ".getConnections")) {
      lServer.sendToken(aConnector, lServer.createAccessDenied(aToken));
      return;
    }

    Token lResponse = lServer.createResponse(aToken);
    try {
      List<Map> lResultList = new FastList<Map>();
      Map lConnectorMap = lServer.getAllConnectors();
      Collection<WebSocketConnector> lConnectors = lConnectorMap.values();
      for (WebSocketConnector lConnector : lConnectors) {
        Map lResultItem = new FastMap<String,Object>();
        lResultItem.put("port", lConnector.getRemotePort());
        lResultItem.put("usid", lConnector.getSession().getSessionId());
        lResultItem.put("username", lConnector.getUsername());
        lResultItem.put("isToken", lConnector.getBoolean(TokenServer.VAR_IS_TOKENSERVER));
        lResultList.add(lResultItem);
      }
      lResponse.put("connections", lResultList);
    } catch (Exception ex) {
      log.error(ex.getClass().getSimpleName()
          + " on getConnections: " + ex.getMessage());
    }

    lServer.sendToken(aConnector, lResponse);
  }
View Full Code Here

   * shutdown server
   * @param aConnector
   * @param aToken
   */
  public void select(WebSocketConnector aConnector, Token aToken) {
    TokenServer lServer = getServer();

    if (mLog.isDebugEnabled()) {
      mLog.debug("Processing 'select'...");
    }

    // check if user is allowed to run 'select' command
    if (!SecurityFactory.checkRight(lServer.getUsername(aConnector), NS_JDBC + ".select")) {
      lServer.sendToken(aConnector, lServer.createAccessDenied(aToken));
      // return;
    }

    // obtain required parameters for query
    String lTable = aToken.getString("table");
    String lFields = aToken.getString("fields");
    String lOrder = aToken.getString("order");
    String lWhere = aToken.getString("where");
    String lGroup = aToken.getString("group");
    String lHaving = aToken.getString("having");

    // buld SQL string
    String lSQL =
        "select "
        + lFields
        + " from "
        + lTable;
    if (lWhere != null && lWhere.length() > 0) {
      lSQL += " where " + lWhere;
    }
    if (lOrder != null && lOrder.length() > 0) {
      lSQL += " order by " + lOrder;
    }

    // instantiate response token
    Token lResponse = lServer.createResponse(aToken);
    // TODO: should work with usual arrays as well!
    // Object[] lColumns = null;
    int lRowCount = 0;
    int lColCount = 0;
    List<Map> lColumns = new FastList<Map>();
    List lData = new FastList<Map>();
    try {
      DBQueryResult lRes = DBConnectSingleton.querySQL(DBConnectSingleton.USR_SYSTEM, lSQL);

      // TODO: metadata should be optional to save bandwidth!
      // generate the meta data for the response
      lColCount = lRes.metaData.getColumnCount();
      lResponse.put("colcount", lColCount);

      for (int i = 1; i <= lColCount; i++) {
        // get name of colmuns
        String lSimpleClass = JDBCTools.extractSimpleClass(
            lRes.metaData.getColumnClassName(i));
        // convert to json type
        String lRIAType = JDBCTools.getJSONType(lSimpleClass, lRes.metaData);

        Map lColHeader = new FastMap<String, Object>();
        lColHeader.put("name", lRes.metaData.getColumnName(i));
        lColHeader.put("jsontype", lRIAType);
        lColHeader.put("jdbctype", lRes.metaData.getColumnTypeName(i));

        lColumns.add(lColHeader);
      }

      // generate the result data
      while (lRes.resultSet.next()) {
        lData.add(getResultColumns(lRes.resultSet, lColCount));
        lRowCount++;
      }
    } catch (Exception ex) {
      mLog.error(ex.getClass().getSimpleName() + " on query: " + ex.getMessage());
    }

    // complete the response token
    lResponse.put("rowcount", lRowCount);
    lResponse.put("columns", lColumns);
    lResponse.put("data", lData);

    // send response to requester
    lServer.sendToken(aConnector, lResponse);
  }
View Full Code Here

   * <tt>createResponse</tt> to simplify token plug-in code.
   * @param aInToken
   * @return
   */
  public Token createResponse(Token aInToken) {
    TokenServer lServer = (TokenServer) getServer();
    if (lServer != null) {
      return lServer.createResponse(aInToken);
    } else {
      return null;
    }
  }
View Full Code Here

   * <tt>createAccessDenied</tt> to simplify token plug-in code.
   * @param aInToken
   * @return
   */
  public Token createAccessDenied(Token aInToken) {
    TokenServer lServer = (TokenServer) getServer();
    if (lServer != null) {
      return lServer.createAccessDenied(aInToken);
    } else {
      return null;
    }
  }
View Full Code Here

   * @param aSource
   * @param aTarget
   * @param aToken
   */
  public void sendToken(WebSocketConnector aSource, WebSocketConnector aTarget, Token aToken) {
    TokenServer lServer = (TokenServer) getServer();
    if (lServer != null) {
      lServer.sendToken(aSource, aTarget, aToken);
    }
  }
View Full Code Here

   * @param aSource
   * @param aTarget
   * @param aToken
   */
  public void broadcastToken(WebSocketConnector aSource, Token aToken) {
    TokenServer lServer = (TokenServer) getServer();
    if (lServer != null) {
      lServer.broadcastToken(aSource, aToken);
    }
  }
View Full Code Here

    }
  }

  public void broadcastToken(WebSocketConnector aSource, Token aToken,
      BroadcastOptions aBroadcastOptions) {
    TokenServer lServer = (TokenServer) getServer();
    if (lServer != null) {
      lServer.broadcastToken(aSource, aToken, aBroadcastOptions);
    }
  }
View Full Code Here

TOP

Related Classes of org.jwebsocket.server.TokenServer

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.