Skip to content

Commit

Permalink
Ristrutturazione classe con springboot in attesa di test con la suite…
Browse files Browse the repository at this point in the history
… di mittente inoltre refactoring del codice ottimizzato secondo i standard, tolta logica di singleton e inserito il concetto del bean di Spring eliminazione singleton
  • Loading branch information
StefanoCritelli-it committed Nov 5, 2024
1 parent 43507b1 commit 54bc3d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
13 changes: 3 additions & 10 deletions src/main/java/it/pn/frontend/e2e/config/CustomHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
Expand All @@ -28,6 +29,7 @@
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class CustomHttpClient<RequestType, ResponseType> {
private static CustomHttpClient<?, ?> instance;
Expand Down Expand Up @@ -65,16 +67,7 @@ public CustomHttpClient(String apiKeyTest) {
}


public static <R, S> CustomHttpClient<R, S> getInstance() {
if (instance == null) {
synchronized (CustomHttpClient.class) {
if (instance == null) {
instance = new CustomHttpClient<>();
}
}
}
return (CustomHttpClient<R, S>) instance;
}


public static <R, S> CustomHttpClient<R, S> getInstanceWithApiKey(String apiKey) {
if (instance == null) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/it/pn/frontend/e2e/rest/RestContact.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class RestContact {

@Autowired
private WebDriverConfig webDriverConfig;

@Autowired
private CustomHttpClient customHttpClient;
private final Map<String, String> headers = new HashMap<>();

// Carica il token all'avvio della classe
Expand Down Expand Up @@ -105,7 +106,7 @@ public void removeSpecialContact(DigitalAddress digitalAddress) throws RestDeleg
* Ottiene l'indirizzo digitale di default.
*/
public DigitalAddressResponse getDigitalAddress() throws RestContactException {
CustomHttpClient<?, DigitalAddressResponse> httpClientDigitalAddress = CustomHttpClient.getInstance();
CustomHttpClient<?, DigitalAddressResponse> httpClientDigitalAddress = customHttpClient;
httpClientDigitalAddress.setBaseUrlApi("https://webapi." + webDriverConfig.getEnvironment() + ".notifichedigitali.it");
String url = "/bff/v1/addresses/LEGAL/default/PEC";

Expand All @@ -125,7 +126,7 @@ public DigitalAddressResponse getDigitalAddress() throws RestContactException {
* Ottiene tutti gli indirizzi digitali.
*/
public List<DigitalAddress> getAllDigitalAddress() throws RestContactException {
CustomHttpClient<?, DigitalAddress> httpClientDigitalAddress = CustomHttpClient.getInstance();
CustomHttpClient<?, DigitalAddress> httpClientDigitalAddress = customHttpClient;
httpClientDigitalAddress.setBaseUrlApi("https://webapi." + webDriverConfig.getEnvironment() + ".notifichedigitali.it");
String url = "/bff/v1/addresses";

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/it/pn/frontend/e2e/rest/RestNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import it.pn.frontend.e2e.model.documents.PreLoadResponse;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.io.IOException;
Expand All @@ -19,6 +20,9 @@ public class RestNotification {
public RestNotification() {
}

@Autowired
private CustomHttpClient customHttpClient;

/**
* Create a new notification with one recipient and one document
*
Expand Down Expand Up @@ -53,7 +57,7 @@ public List<PreLoadResponse> preLoadDocument(List<PreLoadRequest> preLoadList) t
}

public void uploadDocument(String url, String secret, String sha256) throws RestNotificationException {
final CustomHttpClient<?, ?> httpClient2 = CustomHttpClient.getInstance();
final CustomHttpClient<?, ?> httpClient2 = customHttpClient;
try {
httpClient2.sendHttpUpLoadPutRequest(url, secret, sha256, null);
} catch (IOException e) {
Expand All @@ -63,7 +67,7 @@ public void uploadDocument(String url, String secret, String sha256) throws Rest
}

public void uploadDocumentF24(String url, String secret, String sha256, File metaDatiDocument) throws RestNotificationException {
final CustomHttpClient<?, ?> httpClient2 = CustomHttpClient.getInstance();
final CustomHttpClient<?, ?> httpClient2 = customHttpClient;
try {
httpClient2.sendHttpUpLoadf24PutRequest(url, secret, sha256, null, metaDatiDocument);
} catch (IOException e) {
Expand All @@ -73,7 +77,7 @@ public void uploadDocumentF24(String url, String secret, String sha256, File met
}

public LinkedTreeMap<String, Object> getNotificationStatus(String notificationRequestId) {
final CustomHttpClient<Object, Object> httpClient2 = CustomHttpClient.getInstance(); // Modifica qui
final CustomHttpClient<Object, Object> httpClient2 = customHttpClient; // Modifica qui
httpClient2.setBaseUrlApi("https://api.test.notifichedigitali.it");
try {
Object response = httpClient2.sendHttpGetRequest("/delivery/v2.3/requests?notificationRequestId=" + notificationRequestId, null, Object.class);
Expand Down

0 comments on commit 54bc3d1

Please sign in to comment.