コード例 #1
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    HttpSession session = req.getSession(true);
    String sessionId = session.getId();

    ChannelService channelService = ChannelServiceFactory.getChannelService();
    String token = channelService.createChannel(sessionId);

    StringBuilder sessionMap = new StringBuilder();
    Enumeration<String> attributeNames = session.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
      String name = attributeNames.nextElement();
      sessionMap
          .append(name)
          .append(" => ")
          .append(session.getAttribute(name).toString())
          .append("<br/>");
    }

    resp.setContentType("text/html");
    new SkimpyTemplate(getServletContext().getResourceAsStream("/injectable.html"))
        .add("sessionId", sessionId)
        .add("token", token)
        .add("session-vars", sessionMap.toString())
        .write(resp.getWriter());
  }
コード例 #2
0
ファイル: ChatServlet.java プロジェクト: omplanet/Hamaspyur
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    String message_type = req.getParameter("type");
    String user_name = user.getNickname();

    String userId = user.getUserId();

    if (message_type.compareTo("message") == 0) {
      String message = req.getParameter("text");
      String chat_message = chatMessage(user_name, message);
      sendChannelMessageToAll(user_name, chat_message);
      addMessageToCache(chat_message);
    } else if (message_type.compareTo("get_token") == 0) {
      // generate and give token to user
      ChannelService channelService = ChannelServiceFactory.getChannelService();
      String token = channelService.createChannel(userId);
      addToCacheList(_tokenKey, userId);

      resp.setCharacterEncoding("UTF-8");
      resp.setContentType("text/html");
      PrintWriter out = resp.getWriter();
      out.print(tokenMessage(user_name, token));
    } else if (message_type.compareTo("leave") == 0) {
      removeFromCacheList(_tokenKey, userId);
    }
  }
コード例 #3
0
  public LoginInfo login(String requestUri) {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    LoginInfo loginInfo = new LoginInfo();
    ChannelService channelService = ChannelServiceFactory.getChannelService();

    if (user != null) {
      loginInfo.setLoggedIn(true);
      loginInfo.setEmailAddress(user.getEmail());
      loginInfo.setNickname(user.getNickname());
      loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri));
      String token = channelService.createChannel(loginInfo.getEmailAddress());
      loginInfo.setToken(token);
    } else {
      loginInfo.setLoggedIn(false);
      loginInfo.setLoginUrl(userService.createLoginURL(requestUri));
    }

    return loginInfo;
  }
コード例 #4
0
 public static String getChannelToken(String clientId) {
   // Key includes appid; KeyFactory.keyToString(myKey) will not work for backend.
   return channelService.createChannel(clientId);
 }