Beispiel #1
0
  /**
   * Asigna los parametros contantes del request http
   *
   * @param httpform
   */
  private void setCommonRequestParamsfromConfig(HttpForm httpform) {
    Map<String, String> headersParams = new LinkedHashMap<String, String>();
    JsonObject jsonHeaderCofig = getJsonConfig().get("request_headers").getAsJsonObject();

    for (Map.Entry<String, JsonElement> entry : jsonHeaderCofig.entrySet()) {
      headersParams.put(entry.getKey(), entry.getValue().getAsString());
      httpform.putAdditionalRequestProperty(entry.getKey(), entry.getValue().getAsString());
    }

    Map<String, String> requestParams = new LinkedHashMap<String, String>();
    JsonObject jsonRequestCofig = getJsonConfig().get("request_parameters").getAsJsonObject();

    for (Map.Entry<String, JsonElement> entry : jsonRequestCofig.entrySet()) {
      requestParams.put(entry.getKey(), entry.getValue().getAsString());
      httpform.putFieldValue(entry.getKey(), entry.getValue().getAsString());
    }
  }
Beispiel #2
0
  /**
   * Busca Rnc o Cedula en la pagina de la DGII y parsea el resultado.
   *
   * @param rncOrCedula
   * @throws URISyntaxException
   * @throws IOException
   */
  public Rnc parseRncConsult(String rncOrCedula) throws URISyntaxException, IOException {

    Rnc rnc = null;
    String url =
        getJsonConfig().get("url").getAsString()
            + getJsonConfig().get("web_resource").getAsString();
    URI uri = new URI(url);

    HttpForm form = new HttpForm(uri);
    setCommonRequestParamsfromConfig(form);

    // Set rnc or cedula paramater
    form.putFieldValue("txtRncCed", rncOrCedula);

    HttpResponse response = form.doPost();
    if (response.getCode() == HttpURLConnection.HTTP_OK) {
      // Http request was Ok, now parsing it
      rnc = ParserUtil.createRncFromHtml(response.getData(), getJsonConfig());
    }
    return rnc;
  }