All files / output zcl_abapgit_http_client.clas.mjs

6% Statements 12/200
66.66% Branches 2/3
7.69% Functions 1/13
6% Lines 12/200

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 2001x 1x               1x 1x 1x 1x 1x 1x 1x 1x                                                                                                                                                                                                                                                                                                                                                                           1x 1x
const {cx_root} = await import("./cx_root.clas.mjs");
// zcl_abapgit_http_client.clas.abap
class zcl_abapgit_http_client {
  static INTERNAL_TYPE = 'CLAS';
  static INTERNAL_NAME = 'ZCL_ABAPGIT_HTTP_CLIENT';
  static IMPLEMENTED_INTERFACES = [];
  static ATTRIBUTES = {"MI_CLIENT": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"});}, "visibility": "I", "is_constant": " ", "is_class": " "},
  "MO_DIGEST": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_HTTP_DIGEST", RTTIName: "\\CLASS=ZCL_ABAPGIT_HTTP_DIGEST"});}, "visibility": "I", "is_constant": " ", "is_class": " "}};
  static METHODS = {"CONSTRUCTOR": {"visibility": "U", "parameters": {"II_CLIENT": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"});}, "is_optional": " "}}},
  "CLOSE": {"visibility": "U", "parameters": {}},
  "SET_DIGEST": {"visibility": "U", "parameters": {"IO_DIGEST": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_HTTP_DIGEST", RTTIName: "\\CLASS=ZCL_ABAPGIT_HTTP_DIGEST"});}, "is_optional": " "}}},
  "SEND_RECEIVE_CLOSE": {"visibility": "U", "parameters": {"RV_DATA": {"type": () => {return new abap.types.XString({qualifiedName: "XSTRING"});}, "is_optional": " "}, "IV_DATA": {"type": () => {return new abap.types.XString({qualifiedName: "XSTRING"});}, "is_optional": " "}}},
  "GET_CDATA": {"visibility": "U", "parameters": {"RV_VALUE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}},
  "CHECK_HTTP_200": {"visibility": "U", "parameters": {}},
  "CHECK_SMART_RESPONSE": {"visibility": "U", "parameters": {"IV_EXPECTED_CONTENT_TYPE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_CONTENT_REGEX": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}},
  "SEND_RECEIVE": {"visibility": "U", "parameters": {}},
  "SET_HEADERS": {"visibility": "U", "parameters": {"IV_URL": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_SERVICE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}},
  "SET_HEADER": {"visibility": "U", "parameters": {"IV_KEY": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_VALUE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}}};
  #mi_client;
  #mo_digest;
  constructor() {
    this.me = new abap.types.ABAPObject();
    this.me.set(this);
    this.INTERNAL_ID = abap.internalIdCounter++;
    this.FRIENDS_ACCESS_INSTANCE = {
      "close": this.close.bind(this),
      "set_digest": this.set_digest.bind(this),
      "send_receive_close": this.send_receive_close.bind(this),
      "get_cdata": this.get_cdata.bind(this),
      "check_http_200": this.check_http_200.bind(this),
      "check_smart_response": this.check_smart_response.bind(this),
      "send_receive": this.send_receive.bind(this),
      "set_headers": this.set_headers.bind(this),
      "set_header": this.set_header.bind(this),
    };
    this.#mi_client = new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"});
    this.FRIENDS_ACCESS_INSTANCE["mi_client"] = this.#mi_client;
    this.#mo_digest = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_HTTP_DIGEST", RTTIName: "\\CLASS=ZCL_ABAPGIT_HTTP_DIGEST"});
    this.FRIENDS_ACCESS_INSTANCE["mo_digest"] = this.#mo_digest;
  }
  async check_http_200() {
    let lv_code = new abap.types.Integer({qualifiedName: "I"});
    let lv_text = new abap.types.String({qualifiedName: "STRING"});
    await this.#mi_client.get().if_http_client$response.get().if_http_response$get_status({code: lv_code});
    let unique242 = lv_code;
    if (abap.compare.eq(unique242, abap.IntegerFactory.get(200))) {
      return;
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(302))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(64, 'Resource access temporarily redirected (HTTP 302). Check the URL')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(401))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(66, 'Unauthorized access to resource (HTTP 401). Check your credentials')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(403))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(39, 'Access to resource forbidden (HTTP 403)')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(404))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(44, 'Resource not found (HTTP 404). Check the URL')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(407))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(64, 'Proxy authentication required (HTTP 407). Check your credentials')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(408))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(26, 'Request timeout (HTTP 408)')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(415))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(33, 'Unsupported media type (HTTP 415)')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(422))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(69, 'Unprocessable entity (HTTP 422). Check, if URL has to end with ".git"')});
    } else if (abap.compare.eq(unique242, new abap.types.Integer().set(426))) {
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(27, 'Upgrade Required (HTTP 426)'), iv_longtext: abap.operators.concat(new abap.types.String().set(`The git server requires a different HTTP-protocol than which is sent. `),abap.operators.concat(new abap.types.String().set(`abapGit uses HTTP/1.1 as default. `),new abap.types.String().set(`See more details in the abapGit online documentation.`)))});
    } else {
      lv_text.set((await this.#mi_client.get().if_http_client$response.get().if_http_entity$get_cdata()));
      await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: new abap.types.String().set(`(HTTP ${abap.templateFormatting(lv_code)}) ${abap.templateFormatting(lv_text)}`)});
    }
  }
  async check_smart_response(INPUT) {
    let iv_expected_content_type = INPUT?.iv_expected_content_type;
    if (iv_expected_content_type?.getQualifiedName === undefined || iv_expected_content_type.getQualifiedName() !== "STRING") { iv_expected_content_type = undefined; }
    if (iv_expected_content_type === undefined) { iv_expected_content_type = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_expected_content_type); }
    let iv_content_regex = INPUT?.iv_content_regex;
    if (iv_content_regex?.getQualifiedName === undefined || iv_content_regex.getQualifiedName() !== "STRING") { iv_content_regex = undefined; }
    if (iv_content_regex === undefined) { iv_content_regex = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_content_regex); }
    let lv_content_type = new abap.types.String({qualifiedName: "STRING"});
    let lv_data = new abap.types.String({qualifiedName: "STRING"});
    if (abap.compare.initial(iv_expected_content_type) === false) {
      lv_content_type.set((await this.#mi_client.get().if_http_client$response.get().if_http_entity$get_content_type()));
      if (abap.compare.ne(lv_content_type, iv_expected_content_type)) {
        await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(69, 'Wrong Content-Type sent by server - no fallback to the dumb protocol!')});
      }
    }
    if (abap.compare.initial(iv_content_regex) === false) {
      lv_data.set((await this.#mi_client.get().if_http_client$response.get().if_http_entity$get_cdata()));
      abap.statements.find(lv_data, {regex: iv_content_regex});
      if (abap.compare.ne(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0))) {
        await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(28, 'Wrong Content sent by server')});
      }
    }
  }
  async close() {
    await this.#mi_client.get().if_http_client$close();
  }
  async constructor_(INPUT) {
    let ii_client = INPUT?.ii_client;
    if (ii_client?.getQualifiedName === undefined || ii_client.getQualifiedName() !== "IF_HTTP_CLIENT") { ii_client = undefined; }
    if (ii_client === undefined) { ii_client = new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"}).set(INPUT.ii_client); }
    this.#mi_client.set(ii_client);
    return this;
  }
  async get_cdata() {
    let rv_value = new abap.types.String({qualifiedName: "STRING"});
    rv_value.set((await this.#mi_client.get().if_http_client$response.get().if_http_entity$get_cdata()));
    return rv_value;
  }
  async send_receive() {
    let lv_text = new abap.types.String({qualifiedName: "STRING"});
    let lv_code = new abap.types.Integer({qualifiedName: "I"});
    let lv_message = new abap.types.String({qualifiedName: "STRING"});
    try {
      await this.#mi_client.get().if_http_client$send();
      abap.builtin.sy.get().subrc.set(0);
    } catch (e) {
      if (e.classic) {
          switch (e.classic.toUpperCase()) {
          case "HTTP_COMMUNICATION_FAILURE": abap.builtin.sy.get().subrc.set(1); break;
          case "HTTP_INVALID_STATE": abap.builtin.sy.get().subrc.set(2); break;
          case "HTTP_PROCESSING_FAILED": abap.builtin.sy.get().subrc.set(3); break;
          case "HTTP_INVALID_TIMEOUT": abap.builtin.sy.get().subrc.set(4); break;
          default: abap.builtin.sy.get().subrc.set(5); break;
            }
        } else {
            throw e;
        }
      }
      if (abap.compare.eq(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0))) {
        try {
          await this.#mi_client.get().if_http_client$receive();
          abap.builtin.sy.get().subrc.set(0);
        } catch (e) {
          if (e.classic) {
              switch (e.classic.toUpperCase()) {
              case "HTTP_COMMUNICATION_FAILURE": abap.builtin.sy.get().subrc.set(1); break;
              case "HTTP_INVALID_STATE": abap.builtin.sy.get().subrc.set(2); break;
              case "HTTP_PROCESSING_FAILED": abap.builtin.sy.get().subrc.set(3); break;
              default: abap.builtin.sy.get().subrc.set(4); break;
                }
            } else {
                throw e;
            }
          }
        }
        if (abap.compare.ne(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0))) {
          await this.#mi_client.get().if_http_client$get_last_error({code: lv_code, message: lv_message});
          lv_text.set(new abap.types.String().set(`HTTP error ${abap.templateFormatting(lv_code)} occurred: ${abap.templateFormatting(lv_message)}`));
          await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: lv_text});
        }
      }
      async send_receive_close(INPUT) {
        let rv_data = new abap.types.XString({qualifiedName: "XSTRING"});
        let iv_data = INPUT?.iv_data;
        if (iv_data?.getQualifiedName === undefined || iv_data.getQualifiedName() !== "XSTRING") { iv_data = undefined; }
        if (iv_data === undefined) { iv_data = new abap.types.XString({qualifiedName: "XSTRING"}).set(INPUT.iv_data); }
        await this.#mi_client.get().if_http_client$request.get().if_http_entity$set_data({data: iv_data});
        await this.send_receive();
        await this.check_http_200();
        rv_data.set((await this.#mi_client.get().if_http_client$response.get().if_http_entity$get_data()));
        await this.#mi_client.get().if_http_client$close();
        return rv_data;
      }
      async set_digest(INPUT) {
        let io_digest = INPUT?.io_digest;
        if (io_digest?.getQualifiedName === undefined || io_digest.getQualifiedName() !== "ZCL_ABAPGIT_HTTP_DIGEST") { io_digest = undefined; }
        if (io_digest === undefined) { io_digest = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_HTTP_DIGEST", RTTIName: "\\CLASS=ZCL_ABAPGIT_HTTP_DIGEST"}).set(INPUT.io_digest); }
        this.#mo_digest.set(io_digest);
      }
      async set_header(INPUT) {
        let iv_key = INPUT?.iv_key;
        if (iv_key?.getQualifiedName === undefined || iv_key.getQualifiedName() !== "STRING") { iv_key = undefined; }
        if (iv_key === undefined) { iv_key = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_key); }
        let iv_value = INPUT?.iv_value;
        if (iv_value?.getQualifiedName === undefined || iv_value.getQualifiedName() !== "STRING") { iv_value = undefined; }
        if (iv_value === undefined) { iv_value = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_value); }
        await this.#mi_client.get().if_http_client$request.get().if_http_entity$set_header_field({name: iv_key, value: iv_value});
      }
      async set_headers(INPUT) {
        let iv_url = INPUT?.iv_url;
        if (iv_url?.getQualifiedName === undefined || iv_url.getQualifiedName() !== "STRING") { iv_url = undefined; }
        if (iv_url === undefined) { iv_url = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_url); }
        let iv_service = INPUT?.iv_service;
        if (iv_service?.getQualifiedName === undefined || iv_service.getQualifiedName() !== "STRING") { iv_service = undefined; }
        if (iv_service === undefined) { iv_service = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_service); }
        let lv_value = new abap.types.String({qualifiedName: "STRING"});
        await this.#mi_client.get().if_http_client$request.get().if_http_entity$set_header_field({name: abap.CharacterFactory.get(15, '~request_method'), value: abap.CharacterFactory.get(4, 'POST')});
        lv_value.set(abap.operators.concat((await abap.Classes['ZCL_ABAPGIT_URL'].path_name({iv_url: iv_url})),abap.operators.concat(abap.CharacterFactory.get(5, '/git-'),abap.operators.concat(iv_service,abap.CharacterFactory.get(5, '-pack')))));
        await this.#mi_client.get().if_http_client$request.get().if_http_entity$set_header_field({name: abap.CharacterFactory.get(12, '~request_uri'), value: lv_value});
        lv_value.set(abap.operators.concat(abap.CharacterFactory.get(18, 'application/x-git-'),abap.operators.concat(iv_service,abap.CharacterFactory.get(13, '-pack-request'))));
        await this.#mi_client.get().if_http_client$request.get().if_http_entity$set_header_field({name: abap.CharacterFactory.get(12, 'Content-Type'), value: lv_value});
        lv_value.set(abap.operators.concat(abap.CharacterFactory.get(18, 'application/x-git-'),abap.operators.concat(iv_service,abap.CharacterFactory.get(12, '-pack-result'))));
        await this.#mi_client.get().if_http_client$request.get().if_http_entity$set_header_field({name: abap.CharacterFactory.get(6, 'Accept'), value: lv_value});
        if (abap.compare.initial(this.#mo_digest) === false) {
          await this.#mo_digest.get().run({ii_client: this.#mi_client});
        }
      }
    }
    abap.Classes['ZCL_ABAPGIT_HTTP_CLIENT'] = zcl_abapgit_http_client;
export {zcl_abapgit_http_client};