コード例 #1
0
  @OnOpen
  public void onOpen(Session session) {

    peers.add(session);
    try {
      ResponseDTO r = new ResponseDTO();
      r.setSessionID(session.getId());
      session.getBasicRemote().sendText(gson.toJson(r));

      log.log(Level.WARNING, "onOpen...sent session id: {0}", session.getId());
    } catch (IOException ex) {
      log.log(Level.SEVERE, "Failed to open web socket session", ex);
      platformUtil.addErrorStore(ResponseDTO.ERROR_WEBSOCKET, ex.getMessage(), SOURCE);
    } catch (Exception ex) {
      log.log(Level.SEVERE, null, ex);
      platformUtil.addErrorStore(ResponseDTO.ERROR_WEBSOCKET, ex.getMessage(), SOURCE);
    }
  }
コード例 #2
0
  @OnMessage
  public ByteBuffer onMessage(String message) throws Exception {
    log.log(Level.WARNING, "onMessage, incoming: {0}", message);
    ResponseDTO resp = new ResponseDTO();
    try {
      RequestDTO dto = gson.fromJson(message, RequestDTO.class);
      switch (dto.getRequestType()) {
        case RequestDTO.GET_COUNTRY_LIST:
          resp = dataUtil.getProvinceListByCountryCode(dto.getCountryCode());
          break;
        case RequestDTO.GCM_SEND_TRAINEE_TO_INSTRUCTOR_MSG:
          resp =
              cloudMsgUtil.sendTraineeToInstructorMessage(
                  dto.getHelpRequest(),
                  null,
                  dto.getTrainingClassID(),
                  platformUtil,
                  instructorUtil,
                  dataUtil);
          break;
        case RequestDTO.SEND_TRAINEE_SHOUT:
          resp =
              cloudMsgUtil.sendTraineeToInstructorMessage(
                  null,
                  dto.getTraineeShout(),
                  dto.getTrainingClassID(),
                  platformUtil,
                  instructorUtil,
                  dataUtil);
          break;

        case RequestDTO.EVALUATE_TRAINEE_ACTIVITY:
          resp =
              traineeUtil.traineeActivityEvaluation(
                  dto.getCourseTraineeActivity(), dto.getTraineeID(), dataUtil);
          break;
        case RequestDTO.LOGIN_TRAINEE:
          resp = traineeUtil.loginTrainee(dto.getEmail(), dto.getPassword(), dataUtil);
          resp.setProvinceList(
              dataUtil.getProvinceListByCountryCode(dto.getCountryCode()).getProvinceList());
          if (resp.getStatusCode() == 0) {
            StringBuilder sb = new StringBuilder();
            sb.append("Trainee logging in with new device").append("\n");
            sb.append(resp.getCompany().getCompanyName()).append("\n\n");
            sb.append(resp.getTrainee().getFirstName())
                .append(" ")
                .append(resp.getTrainee().getLastName())
                .append("\n");
            platformUtil.addErrorStore(0, sb.toString(), "Trainee Services");
          }
          break;

        case RequestDTO.ADD_HELP_REQUEST:
          resp = traineeUtil.addHelpRequest(dto.getHelpRequest(), dataUtil);
          break;
        case RequestDTO.UPDATE_TRAINEE:
          resp = traineeUtil.updateTraineeProfile(dto.getTrainee(), dataUtil);
          break;
        case RequestDTO.GET_TRAINEE_DATA:
          resp =
              traineeUtil.getTraineeData(
                  dto.getTrainingClassID(),
                  dto.getTraineeID(),
                  dto.getCompanyID(),
                  dto.getCountryCode(),
                  dataUtil);
          resp.setTeamList(
              teamUtil.getTeamsByClass(dto.getTrainingClassID(), dataUtil).getTeamList());
          break;
        case RequestDTO.GET_RATING_LIST:
          resp = dataUtil.getRatingAndHelpList(dto.getCompanyID());
          break;
        case RequestDTO.GET_INSTRUCTOR_LIST_BY_CLASS:
          resp = traineeUtil.getInstructorsByClass(dto.getTrainingClassID(), dataUtil);
          break;
        case RequestDTO.GET_TEAMS_BY_CLASS:
          resp = teamUtil.getTeamsByClass(dto.getTrainingClassID(), dataUtil);
          break;
        case RequestDTO.GET_TEAMS_BY_COMPANY:
          resp = teamUtil.getTeamsByCompany(dto.getCompanyID(), dataUtil);
          break;

        default:
          resp.setStatusCode(ResponseDTO.ERROR_UNKNOWN_REQUEST);
          resp.setMessage("Unknown request. Verboten!!");
          platformUtil.addErrorStore(
              resp.getStatusCode(), "Unknown request detected. Whazzup??", "Trainee Services");
          break;
      }
    } catch (DataException ex) {
      resp.setStatusCode(ResponseDTO.ERROR_DATABASE);
      resp.setMessage("Data service failed to process your request");
      log.log(Level.SEVERE, null, ex);
      platformUtil.addErrorStore(ResponseDTO.ERROR_DATABASE, ex.getDescription(), SOURCE);
    } catch (Exception ex) {
      resp.setStatusCode(ResponseDTO.ERROR_SERVER);
      resp.setMessage("Service failed to process your request");
      log.log(Level.SEVERE, null, ex);
      platformUtil.addErrorStore(ResponseDTO.ERROR_SERVER, ex.getMessage(), SOURCE);
    }
    ByteBuffer bb = null;
    try {
      bb = getZippedResponse(resp);
    } catch (Exception ex) {
      log.log(Level.SEVERE, null, ex);
    }
    return bb;
  }
コード例 #3
0
 @OnError
 public void onError(Throwable t) {
   log.log(Level.SEVERE, "######### WebSocket Fail", t);
   platformUtil.addErrorStore(ResponseDTO.ERROR_WEBSOCKET, t.getMessage(), SOURCE);
 }