Esempio n. 1
0
  @Post
  public String handlePost(Representation entity) {

    CommonUtil.setSystemOut();
    HttpRequest request = (HttpRequest) getRequest();
    String clientIp = request.getClientInfo().getAddress();
    MDC.put("cip", clientIp);

    String responseStr = null;
    Series<Parameter> headers =
        (Series<Parameter>) request.getAttributes().get("org.restlet.http.headers");
    StringBuilder authKey = new StringBuilder();
    StringBuilder source = new StringBuilder();
    StringBuilder device = new StringBuilder();

    ParseUtil.getHeaderInfo(headers, authKey, source, device);

    logger.info("authKey:" + authKey);
    logger.info("source/device : (" + source + "/" + device + ")");

    TconCheckAuth tca = TconCheckAuth.getInstance();

    boolean isAccepted = false;
    for (String ip : GlobalVariables.accepted_ip) {
      if (clientIp.equals(ip)) {
        isAccepted = true;
        break;
      }
    }

    try {
      // 인증
      if (tca.isValidKey(authKey.toString(), source.toString()) || isAccepted) {
        String region_id = (String) request.getAttributes().get("region_id");

        logger.info("region_id:" + region_id);

        /*if (region_id.length()!=10){
        	return GenericResponse.getInvalidURIErrorStr();
        }*/

        ProcessData pd = new ProcessData();

        JSONObject jobjRoot = new JSONObject();
        jobjRoot.put("retcode", 0);

        // 현재 날씨
        responseStr = pd.getWeatherVaillageNow(region_id);
        JSONObject jobj = new JSONObject(responseStr);
        jobjRoot.put("now", jobj);

        // Short (3시간 예보)
        responseStr = pd.getWeatherVaillageShort(region_id);
        JSONObject jobj1 = new JSONObject(responseStr);
        jobjRoot.put("short", jobj1);

        // Life (생활 지수)
        responseStr = pd.getWeatherVaillageLife(region_id);
        JSONObject jobj2 = new JSONObject(responseStr);
        jobjRoot.put("life", jobj2);

        // 기상 특보
        responseStr = pd.getWeatherWarn();
        JSONObject jobj3 = new JSONObject(responseStr);
        jobjRoot.put("warn", jobj3);

        responseStr = jobjRoot.toString();

      } else {
        responseStr = GenericResponse.getAuthFailJsonStr();
      }
    } catch (JSONException e) {
      logger.error("[EXCEPTION]", e);
      responseStr = GenericResponse.getJSONObjectErrorStr();
    } catch (Exception e1) {
      logger.error("[EXCEPTION]", e1);
      responseStr = GenericResponse.getUnExpectedErrorStr();
    }
    logger.info("--> " + responseStr);
    return responseStr;
  }
Esempio n. 2
0
 @Delete
 public String handleDelete() {
   HttpRequest request = (HttpRequest) getRequest();
   MDC.put("cip", request.getClientInfo().getAddress());
   return GenericResponse.getInvalidMethodErrorStr();
 }