@Monitor(
      server = POIDETAIL_SERVER,
      parserClass = ServiceUrlParserFactory.CLASS_PROPERTIES,
      filePath = "config/web_services.properties",
      serviceUrlKeys = "URL_POI_DETAIL")
  private DetectResult monitorPoiDetailServer() {
    DetectResult result = new DetectResult();

    ContentInfoServiceStub stub = null;
    try {
      TnContext tc = BackendServerMonitorUtil.createTnContext();

      GetPoiDetailsRequest getPoiDetailRequest = new GetPoiDetailsRequest();
      getPoiDetailRequest.setClientName(HtmlConstants.clientName);
      getPoiDetailRequest.setClientVersion(HtmlConstants.clientVersion);
      getPoiDetailRequest.setContextString(tc.toContextString());
      getPoiDetailRequest.setTransactionId(System.currentTimeMillis() + "");
      getPoiDetailRequest.setPoiId(getSamplePoiId());

      stub = new ContentInfoServiceStub(WebServiceConfigurator.getUrlOfPoiDetail());
      GetPoiDetailsResponse getPoiDetailResponse = stub.getPoiDetails(getPoiDetailRequest);
      com.telenav.datatypes.services.v20.ResponseStatus status =
          getPoiDetailResponse.getResponseStatus();

      // poi detail can't be found is ok. only 20%-30% has detail information from zhangpan.
      if ("OK".equals(status.getStatusCode())
          || "DB_DATA_NOT_FOUND".equals(status.getStatusCode())) {
        result.isSuccess = true;
      } else {
        result.isSuccess = false;
        result.msg =
            "responseCode = "
                + status.getStatusCode()
                + ", responseMessage = "
                + status.getStatusMessage();
        logger.debug(result.msg);
      }

    } catch (Exception ex) {
      logger.fatal("#monitorLogoImageServer", ex);
      result.isSuccess = false;
      result.msg =
          "Exception occurs when get logo image"
              + ". Exception msg->"
              + ExceptionUtil.collectExceptionMsg(ex);
    } finally {
      if (stub != null) {
        try {
          WebServiceUtils.cleanupStub(stub);
        } catch (Exception ex) {
        }
      }
    }
    return result;
  }
  /**
   * TODO add a new record about nickname
   *
   * @param nickNameRequest
   * @param nickNameResponse
   * @param tnContext
   * @return
   */
  public HtmlNickNameResponse addNickName(
      HtmlNickNameRequest nickNameRequest,
      HtmlNickNameResponse nickNameResponse,
      TnContext tnContext) {

    CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE);
    cli.setFunctionName("addNickName");
    nickNameResponse.setStatus(ExecutorResponse.STATUS_OK);
    long userId = nickNameRequest.getUserId();
    String userName = nickNameRequest.getNickName();
    nickNameResponse.setNickName(userName);
    UserManagementServiceStub stub = null;
    try {

      logger.debug("addNickName userId:" + userId + ",userName" + userName);
      // set conditions
      GetUserRequestDTO getUserRequest = new GetUserRequestDTO();
      getUserRequest.setParam(Long.toString(userId));
      getUserRequest.setParamType(UserQueryBy.USER_ID);
      getUserRequest.setClientName(HtmlConstants.clientName);
      getUserRequest.setClientVersion(HtmlConstants.clientVersion);
      getUserRequest.setContextString(tnContext.toContextString());
      getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId());

      // get user
      stub = getServer();
      GetUserResponseDTO responseDto = stub.getUser(getUserRequest);
      User user = responseDto.getUser();
      user.setUserName(userName);

      // update user
      UpdateUserRequestDTO updateRequest = new UpdateUserRequestDTO();
      updateRequest.setUser(user);
      updateRequest.setClientName(HtmlConstants.clientName);
      updateRequest.setClientVersion(HtmlConstants.clientVersion);
      updateRequest.setContextString(tnContext.toContextString());
      updateRequest.setTransactionId(HtmlPoiUtil.getTrxId());

      UserManagementResponseDTO updateResponse = stub.updateUser(updateRequest);

    } catch (Exception e) {
      logger.error(e);
      e.printStackTrace();
      cli.setStatus(e);
      cli.setState(CliConstants.STATUS_FAIL);
    } finally {
      cli.complete();
      WebServiceUtils.cleanupStub(stub);
    }

    return nickNameResponse;
  }
  @Monitor(
      server = ORGANICADVERTISE_SERVER,
      parserClass = ServiceUrlParserFactory.CLASS_PROPERTIES,
      filePath = "config/web_services.properties",
      serviceUrlKeys = "URL_ORGANIC_ADS_SEARCH")
  private DetectResult monitorOrganicAdvertiseServer() {
    DetectResult result = new DetectResult();

    com.telenav.services.content.ads.v10.AdServiceStub stub = null;
    try {
      TnContext tc = BackendServerMonitorUtil.createTnContext();

      AdServiceOrganicAdsRequestDTO requestDTO = new AdServiceOrganicAdsRequestDTO();
      requestDTO.setClientName(HtmlConstants.clientName);
      requestDTO.setClientVersion(HtmlConstants.clientVersion);
      requestDTO.setContextString(tc.toContextString());
      requestDTO.setTransactionId(HtmlPoiUtil.getTrxId());
      long[] poiIds = new long[1];
      poiIds[0] = getSamplePoiId();
      requestDTO.setPoiIds(poiIds);

      stub =
          new com.telenav.services.content.ads.v10.AdServiceStub(
              WebServiceConfigurator.getUrlOfOrganicAdsSearch());
      AdServiceResponseDTO response = stub.getOrganicAds(requestDTO);

      if (response != null) {
        result.isSuccess = true;

      } else {
        result.isSuccess = false;
        result.msg = "response is null";
      }
    } catch (Exception ex) {
      logger.fatal("#monitorOrganicAdvertiseServer", ex);
      result.isSuccess = false;
      result.msg =
          "Exception occurs when get logo get organic advertise"
              + ". Exception msg->"
              + ExceptionUtil.collectExceptionMsg(ex);
    } finally {
      if (stub != null) {
        try {
          WebServiceUtils.cleanupStub(stub);
        } catch (Exception ex) {
        }
      }
    }
    return result;
  }
  @Monitor(
      server = USER_MANAGEMENT_SERVER,
      parserClass = ServiceUrlParserFactory.CLASS_PROPERTIES,
      filePath = "config/web_services.properties",
      serviceUrlKeys = "URL_POI_REVIEW_WRITE")
  private DetectResult monitorUserManagementServer() {

    DetectResult result = new DetectResult();

    UserManagementServiceStub stub = null;
    try {
      UserProfile userProfile = BackendServerMonitorUtil.createUserProfile();
      TnContext tc = BackendServerMonitorUtil.createTnContext();

      GetUserRequestDTO getUserRequest = new GetUserRequestDTO();
      getUserRequest.setParam(userProfile.getUserId() + "");
      getUserRequest.setParamType(UserQueryBy.USER_ID);

      getUserRequest.setClientName(HtmlConstants.clientName);
      getUserRequest.setClientVersion(HtmlConstants.clientVersion);
      getUserRequest.setContextString(tc.toContextString());
      getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId());
      // get userInfo
      stub = new UserManagementServiceStub(WebServiceConfigurator.getUrlOfPoiReviewWrite());
      GetUserResponseDTO response = stub.getUser(getUserRequest);
      if (response != null) {
        if (response.getUser() != null) {
          result.isSuccess = true;
        } else {
          result.isSuccess = false;
          result.msg = "GetUserResponseDTO.getUser() is null";
        }
      } else {
        result.isSuccess = false;
        result.msg = "GetUserResponseDTO is Null";
      }
    } catch (Exception ex) {
      logger.fatal("#monitorUserManagementServer", ex);
      result.isSuccess = false;
      result.msg =
          "Exception occurs when getUserName"
              + ". Exception msg->"
              + ExceptionUtil.collectExceptionMsg(ex);
    } finally {
      if (stub != null) {
        WebServiceUtils.cleanupStub(stub);
      }
    }
    return result;
  }
  @Monitor(
      server = WHETHER_SERVER,
      parserClass = ServiceUrlParserFactory.CLASS_PROPERTIES,
      filePath = "config/web_services.properties",
      serviceUrlKeys = "URL_WEATHER")
  private DetectResult monitorWhetherServer() {
    DetectResult result = new DetectResult();

    WeatherServiceStub stub = null;
    try {
      I18NWeatherServiceRequestDTO request = new I18NWeatherServiceRequestDTO();
      request.setClientName("6x-cserver");
      request.setClientVersion("1.0");
      request.setTransactionId("unknown");

      Location location = new Location();
      com.telenav.ws.datatypes.address.GeoCode latLon =
          new com.telenav.ws.datatypes.address.GeoCode();
      latLon.setLatitude(37.37515);
      latLon.setLongitude(-121.99769);
      location.setGeoCode(latLon);
      request.setLocation(location);

      request.setNumberOfDays(2);

      stub = new WeatherServiceStub(WebServiceConfigurator.getUrlOfWeather());
      I18NWeatherServiceResponseDTO response = stub.getI18NCurrentNForecast(request);
      String statusCode = response.getResponseStatus().getStatusCode();
      String statusMessage = response.getResponseStatus().getStatusMessage();
      if ("OK".equals(statusCode)) {
        result.isSuccess = true;
      } else {
        result.isSuccess = false;
        result.msg = "StatusCode = " + statusCode + ", StatusMessage = " + statusMessage;
      }

    } catch (Exception e) {
      logger.fatal("#monitorWhetherServer", e);
      result.isSuccess = false;
      result.msg =
          "Exception occurs when getI18NCurrentNForecast"
              + ". Exception msg->"
              + ExceptionUtil.collectExceptionMsg(e);
    } finally {
      if (stub != null) {
        WebServiceUtils.cleanupStub(stub);
      }
    }
    return result;
  }
  /**
   * @TODO query nickname
   *
   * @param nickNameRequest
   * @param nickNameResponse
   * @param tnContext
   * @return
   */
  public HtmlNickNameResponse queryNickName(
      HtmlNickNameRequest nickNameRequest,
      HtmlNickNameResponse nickNameResponse,
      TnContext tnContext) {

    CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE);
    cli.setFunctionName("queryNickName");
    long userId = nickNameRequest.getUserId();
    nickNameResponse.setStatus(ExecutorResponse.STATUS_OK);
    nickNameResponse.setUserId(userId);
    nickNameResponse.setNickName("");
    UserManagementServiceStub stub = null;
    try {
      // set query conditions
      GetUserRequestDTO getUserRequest = new GetUserRequestDTO();
      getUserRequest.setParam(Long.toString(userId));
      getUserRequest.setParamType(UserQueryBy.USER_ID);

      getUserRequest.setClientName(HtmlConstants.clientName);
      getUserRequest.setClientVersion(HtmlConstants.clientVersion);
      getUserRequest.setContextString(tnContext.toContextString());
      getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId());
      // get userInfo
      stub = getServer();
      GetUserResponseDTO responseDto = stub.getUser(getUserRequest);
      if (responseDto != null) {
        User user = responseDto.getUser();
        if (user != null) // set response param
        {
          logger.debug("queryNickName userId:" + userId + ",user name:" + user.getUserName());
          // set query result
          nickNameResponse.setNickName(user.getUserName());
        }
        cli.addData("Response", "Status Code:" + responseDto.getResponseStatus());
      }
      // nickNameResponse.setMessage("Status Code =" + statusCode + " Message=" + statusMsg);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      logger.error(e);
      e.printStackTrace();
      cli.setStatus(e);
      cli.setState(CliConstants.STATUS_FAIL);
    } finally {
      cli.complete();
      WebServiceUtils.cleanupStub(stub);
    }

    return nickNameResponse;
  }
  /**
   * @TODO check nickname if exist
   *
   * @param nickNameRequest
   * @param nickNameResponse
   * @param tnContext
   * @return
   */
  public HtmlNickNameResponse checkNickName(
      HtmlNickNameRequest nickNameRequest,
      HtmlNickNameResponse nickNameResponse,
      TnContext tnContext) {

    CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE);
    cli.setFunctionName("checkNickName");
    String nickNameStr = nickNameRequest.getNickName();
    nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME);
    nickNameResponse.setStatus(ExecutorResponse.STATUS_OK);
    UserManagementServiceStub stub = null;
    try {

      // set conditions
      IsUniqueUsernameRequestDTO isUniqueRequest = new IsUniqueUsernameRequestDTO();
      isUniqueRequest.setUserName(nickNameStr);
      isUniqueRequest.setClientName(HtmlConstants.clientName);
      isUniqueRequest.setClientVersion(HtmlConstants.clientVersion);
      isUniqueRequest.setContextString(tnContext.toContextString());
      isUniqueRequest.setTransactionId(HtmlPoiUtil.getTrxId());

      // check NickName
      stub = getServer();
      IsUniqueUsernameResponseDTO isUniqueResponse = stub.isUniqueUsername(isUniqueRequest);
      nickNameResponse.setNickName(nickNameStr);
      if (isUniqueResponse != null) {
        boolean isUnique = isUniqueResponse.getUnique();
        logger.debug("checkNickName userName:"******",isUnique" + isUnique);
        cli.addData("data", "checkNickName userName:"******",isUnique" + isUnique);
        if (isUnique) { // the nick name is unique
          nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME);
        } else { // the nick name has exist
          nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_NOT_UNIQUE_NICKNAME);
        }
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      logger.error(e);
      e.printStackTrace();
      cli.setStatus(e);
      cli.setState(CliConstants.STATUS_FAIL);
    } finally {
      cli.complete();
      WebServiceUtils.cleanupStub(stub);
    }

    return nickNameResponse;
  }
  @Monitor(
      server = FEEDBACK_SERVER,
      parserClass = ServiceUrlParserFactory.CLASS_PROPERTIES,
      filePath = "config/web_services.properties",
      serviceUrlKeys = "URL_FEEDBACK_SERVER")
  private DetectResult monitorFeedbackServer() {
    DetectResult result = new DetectResult();

    FeedbackServiceStub stub = null;
    try {
      stub = new FeedbackServiceStub(WebServiceConfigurator.getUrlOfFeedbackServer());
      GetFeedbackQuestionsRequestDTO requestDTO = new GetFeedbackQuestionsRequestDTO();

      // requestDTO.setTopic(topic);
      requestDTO.setLocale("en_US");
      requestDTO.setTopicString("fakeTopic");
      requestDTO.setCarrier(null); // (userProfile.getCarrier());
      requestDTO.setPlatform(null); // userProfile.getPlatform());
      requestDTO.setClientName("default"); // ("c-server");
      requestDTO.setClientVersion("default"); // (userProfile.getVersion());
      // requestDTO.setDevice(null);//(userProfile.getDevice());
      requestDTO.setTransactionId("default"); // ("unknown");

      GetFeedbackQuestionsResponseDTO response = stub.getAllFeedbackQuestions(requestDTO);

      if ("OK".equals(response.getResponseStatus().getStatusCode())) {
        result.isSuccess = true;
      } else {
        result.isSuccess = false;
        result.msg =
            "responseCode = "
                + response.getResponseStatus().getStatusCode()
                + ", responseMessage = "
                + response.getResponseStatus().getStatusMessage();
      }
    } catch (Exception e) {
      result.isSuccess = false;
      result.msg = "Error when getAllFeedbackQuestions. Exception occurs->" + e.getMessage();
    } finally {
      if (stub != null) {
        WebServiceUtils.cleanupStub(stub);
      }
    }

    return result;
  }
  @Monitor(
      server = ONEBOXSEARCH_SERVER,
      parserClass = ServiceUrlParserFactory.CLASS_PROPERTIES,
      filePath = "config/web_services.properties",
      serviceUrlKeys = "URL_ONE_BOX_SEARCH")
  private DetectResult monitorOneBoxSearchServer() {
    DetectResult result = new DetectResult();

    OneboxSearchServiceStub stub = null;
    try {
      UserProfile userProfile = BackendServerMonitorUtil.createUserProfile();
      TnContext tc = BackendServerMonitorUtil.createTnContext();

      OneboxSearchRequest obReq = new OneboxSearchRequest();

      // set user
      UserInformation user = new UserInformation();
      UserProfile usrProfile = userProfile;
      user.setUserId(usrProfile.getUserId());
      user.setPtn(usrProfile.getMin());
      obReq.setUserInfo(user);

      // set client info
      Date today = new Date();
      // using date only
      String trxnId = String.valueOf(today.getTime());
      obReq.setClientName(ClientNameEnum._MOBILE);
      obReq.setClientVersion("1");
      obReq.setTransactionId(trxnId);

      // set POI data set() and MAP data set
      obReq.setContextString(tc.toContextString());

      // set anchor
      com.telenav.ws.datatypes.address.GeoCode latLon =
          new com.telenav.ws.datatypes.address.GeoCode();
      latLon.setLatitude(37.37453);
      latLon.setLongitude(-121.99983);
      obReq.setAnchor(latLon);

      // set query
      obReq.setQuery("coffee");
      obReq.setStartIndex(0);
      obReq.setResultCount(10);
      // TODO: check sponsor number
      obReq.setSponsorStartIndex(0);
      obReq.setSponsorResultCount(1);
      obReq.setLocale(CommonUtil.getTnLocal(userProfile.getLocale()));
      obReq.setSponsorResultCount(100);
      obReq.setTransactionId(System.currentTimeMillis() + "");

      stub = new OneboxSearchServiceStub(WebServiceConfigurator.getUrlOfOneBox());
      OneboxSearchResponse response = stub.oneboxSearch(obReq);

      if (response != null && "RESULT_FOUND".equals(response.getResponseStatus().getStatusCode())) {
        result.isSuccess = true;
      } else {
        result.isSuccess = false;
        result.msg =
            response == null
                ? "Response is null."
                : "StatusCode = "
                    + response.getResponseStatus().getStatusCode()
                    + ", StatusMessage = "
                    + response.getResponseStatus().getStatusMessage();
      }

    } catch (Exception e) {
      logger.fatal("#monitorOneBoxSearchServer", e);
      result.isSuccess = false;
      result.msg =
          "Exception occurs when one box search"
              + ". Exception msg->"
              + ExceptionUtil.collectExceptionMsg(e);
    } finally {
      if (stub != null) {
        WebServiceUtils.cleanupStub(stub);
      }
    }
    return result;
  }
  /**
   * TODO add a new record about nickname
   *
   * @param nickNameRequest
   * @param nickNameResponse
   * @param tnContext
   * @return
   */
  public HtmlNickNameResponse checkAndaddNickName(
      HtmlNickNameRequest nickNameRequest,
      HtmlNickNameResponse nickNameResponse,
      TnContext tnContext) {

    CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE);
    cli.setFunctionName("checkAndaddNickName");
    nickNameResponse.setStatus(ExecutorResponse.STATUS_OK);
    UserManagementServiceStub stub = null;
    try {

      String userName = nickNameRequest.getNickName();
      // set conditions
      IsUniqueUsernameRequestDTO isUniqueRequest = new IsUniqueUsernameRequestDTO();
      isUniqueRequest.setUserName(userName);
      isUniqueRequest.setClientName(HtmlConstants.clientName);
      isUniqueRequest.setClientVersion(HtmlConstants.clientVersion);
      isUniqueRequest.setContextString(tnContext.toContextString());
      isUniqueRequest.setTransactionId(HtmlPoiUtil.getTrxId());

      // check NickName
      stub = getServer();
      IsUniqueUsernameResponseDTO isUniqueResponse = stub.isUniqueUsername(isUniqueRequest);
      nickNameResponse.setNickName(userName);

      if (isUniqueResponse != null) {
        boolean isUnique = isUniqueResponse.getUnique();

        logger.debug("checkNickName userName:"******",isUnique" + isUnique);
        cli.addData("data", "checkNickName userName:"******",isUnique" + isUnique);
        if (isUnique) { // the nick name is unique
          nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME);

          long userId = nickNameRequest.getUserId();

          logger.debug("addNickName userId:" + userId + ",userName" + userName);
          // set conditions
          GetUserRequestDTO getUserRequest = new GetUserRequestDTO();
          getUserRequest.setParam(Long.toString(userId));
          getUserRequest.setParamType(UserQueryBy.USER_ID);
          getUserRequest.setClientName(HtmlConstants.clientName);
          getUserRequest.setClientVersion(HtmlConstants.clientVersion);
          getUserRequest.setContextString(tnContext.toContextString());
          getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId());

          // get user
          GetUserResponseDTO responseDto = stub.getUser(getUserRequest);
          User user = responseDto.getUser();
          if (user != null) {
            user.setUserName(userName);
            // update user
            UpdateUserRequestDTO updateRequest = new UpdateUserRequestDTO();
            updateRequest.setUser(user);
            updateRequest.setClientName(HtmlConstants.clientName);
            updateRequest.setClientVersion(HtmlConstants.clientVersion);
            updateRequest.setContextString(tnContext.toContextString());
            updateRequest.setTransactionId(HtmlPoiUtil.getTrxId());

            UserManagementResponseDTO updateResponse = stub.updateUser(updateRequest);
          }
        } else { // the nick name has exist
          nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_NOT_UNIQUE_NICKNAME);
        }
      } else {
        nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME);
      }
    } catch (Exception e) {
      logger.error(e);
      e.printStackTrace();
      cli.setStatus(e);
      cli.setState(CliConstants.STATUS_FAIL);
    } finally {
      cli.complete();
      WebServiceUtils.cleanupStub(stub);
    }

    return nickNameResponse;
  }