improved http check status mechanism
This commit is contained in:
parent
49c8ea0db9
commit
0a459e4b48
1 changed files with 42 additions and 41 deletions
|
|
@ -504,7 +504,7 @@ public class KSeFAuthManager {
|
||||||
|
|
||||||
// Now we need to wait until auth/{AuthRef} will return 200
|
// Now we need to wait until auth/{AuthRef} will return 200
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
long timeout = 120_000; // 120 Sekunden
|
long timeout = 180_000; // 180 Sekunden
|
||||||
|
|
||||||
while (System.currentTimeMillis() - start < timeout) {
|
while (System.currentTimeMillis() - start < timeout) {
|
||||||
int status = this.checkSessionStatus(workitem);
|
int status = this.checkSessionStatus(workitem);
|
||||||
|
|
@ -529,7 +529,7 @@ public class KSeFAuthManager {
|
||||||
// Optional: prüfen, ob Timeout erreicht wurde
|
// Optional: prüfen, ob Timeout erreicht wurde
|
||||||
if (System.currentTimeMillis() - start >= timeout) {
|
if (System.currentTimeMillis() - start >= timeout) {
|
||||||
throw new PluginException(KSeFAuthManager.class.getSimpleName(), ERROR_API,
|
throw new PluginException(KSeFAuthManager.class.getSimpleName(), ERROR_API,
|
||||||
"API Error - failed to init new interactive session - ⚠️ Timeout reached after 120 seconds!");
|
"API Error - failed to init new interactive session - ⚠️ Timeout reached after 180 seconds!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -889,53 +889,54 @@ public class KSeFAuthManager {
|
||||||
|
|
||||||
httpResponse = response.statusCode();
|
httpResponse = response.statusCode();
|
||||||
logger.info("│ ├── HTTP Response: " + httpResponse);
|
logger.info("│ ├── HTTP Response: " + httpResponse);
|
||||||
|
|
||||||
logger.info("│ ├── " + response.body());
|
logger.info("│ ├── " + response.body());
|
||||||
|
|
||||||
try (Jsonb jsonb = JsonbBuilder.create()) {
|
if (httpResponse >= 200 && httpResponse <= 299) {
|
||||||
JsonObject jsonObject = jsonb.fromJson(response.body(), JsonObject.class);
|
|
||||||
|
|
||||||
// Status Code aus dem status-Objekt extrahieren
|
try (Jsonb jsonb = JsonbBuilder.create()) {
|
||||||
if (jsonObject.containsKey("status")) {
|
JsonObject jsonObject = jsonb.fromJson(response.body(), JsonObject.class);
|
||||||
JsonObject statusObject = jsonObject.getJsonObject("status");
|
|
||||||
if (statusObject.containsKey("code")) {
|
|
||||||
statusCode = statusObject.getInt("code");
|
|
||||||
logger.info("│ ├── Status Code: " + statusCode);
|
|
||||||
logger.info("│ ├── Status Description: " + statusObject.getString("description"));
|
|
||||||
workitem.setItemValue("ksef.status.code", statusCode);
|
|
||||||
workitem.setItemValue("ksef.status.description", statusObject.getString("description"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract UPO data from the first page
|
// Status Code aus dem status-Objekt extrahieren
|
||||||
if (jsonObject.containsKey("upo")) {
|
if (jsonObject.containsKey("status")) {
|
||||||
JsonObject upoObject = jsonObject.getJsonObject("upo");
|
JsonObject statusObject = jsonObject.getJsonObject("status");
|
||||||
if (upoObject.containsKey("pages")) {
|
if (statusObject.containsKey("code")) {
|
||||||
JsonArray pagesArray = upoObject.getJsonArray("pages");
|
statusCode = statusObject.getInt("code");
|
||||||
if (pagesArray != null && !pagesArray.isEmpty()) {
|
logger.info("│ ├── Status Code: " + statusCode);
|
||||||
JsonObject firstPage = pagesArray.getJsonObject(0);
|
logger.info("│ ├── Status Description: " + statusObject.getString("description"));
|
||||||
|
workitem.setItemValue("ksef.status.code", statusCode);
|
||||||
String referenceNumber = firstPage.getString("referenceNumber", "");
|
workitem.setItemValue("ksef.status.description", statusObject.getString("description"));
|
||||||
String downloadUrl = firstPage.getString("downloadUrl", "");
|
|
||||||
String expirationDate = firstPage.getString("downloadUrlExpirationDate", "");
|
|
||||||
|
|
||||||
logger.info("│ ├── UPO Reference Number: " + referenceNumber);
|
|
||||||
logger.info("│ ├── UPO Download URL: " + downloadUrl);
|
|
||||||
logger.info("│ ├── UPO URL Expiration: " + expirationDate);
|
|
||||||
|
|
||||||
workitem.setItemValue("ksef.upo.referenceNumber", referenceNumber);
|
|
||||||
workitem.setItemValue("ksef.upo.downloadUrl", downloadUrl);
|
|
||||||
workitem.setItemValue("ksef.upo.downloadUrlExpirationDate", expirationDate);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract UPO data from the first page
|
||||||
|
if (jsonObject.containsKey("upo")) {
|
||||||
|
JsonObject upoObject = jsonObject.getJsonObject("upo");
|
||||||
|
if (upoObject.containsKey("pages")) {
|
||||||
|
JsonArray pagesArray = upoObject.getJsonArray("pages");
|
||||||
|
if (pagesArray != null && !pagesArray.isEmpty()) {
|
||||||
|
JsonObject firstPage = pagesArray.getJsonObject(0);
|
||||||
|
|
||||||
|
String referenceNumber = firstPage.getString("referenceNumber", "");
|
||||||
|
String downloadUrl = firstPage.getString("downloadUrl", "");
|
||||||
|
String expirationDate = firstPage.getString("downloadUrlExpirationDate", "");
|
||||||
|
|
||||||
|
logger.info("│ ├── UPO Reference Number: " + referenceNumber);
|
||||||
|
logger.info("│ ├── UPO Download URL: " + downloadUrl);
|
||||||
|
logger.info("│ ├── UPO URL Expiration: " + expirationDate);
|
||||||
|
|
||||||
|
workitem.setItemValue("ksef.upo.referenceNumber", referenceNumber);
|
||||||
|
workitem.setItemValue("ksef.upo.downloadUrl", downloadUrl);
|
||||||
|
workitem.setItemValue("ksef.upo.downloadUrlExpirationDate", expirationDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.severe("├── ⚠️ Error parsing JSON response: " + e.getMessage());
|
||||||
|
throw new PluginException(KSeFAuthManager.class.getSimpleName(), ERROR_API,
|
||||||
|
"Error parsing JSON response: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.severe("├── ⚠️ Error parsing JSON response: " + e.getMessage());
|
|
||||||
throw new PluginException(KSeFAuthManager.class.getSimpleName(), ERROR_API,
|
|
||||||
"Error parsing JSON response: " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return statusCode;
|
return statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue