Merge branch 'master' into develop
This commit is contained in:
@@ -1,44 +1,21 @@
|
|||||||
package it.integry.ems.schedule.new_cron_job.dto.operations.runners;
|
package it.integry.ems.schedule.new_cron_job.dto.operations.runners;
|
||||||
|
|
||||||
import it.integry.common.var.CommonConstants;
|
|
||||||
import it.integry.ems.json.ResponseJSONObjectMapper;
|
|
||||||
import it.integry.ems.response.EsitoType;
|
|
||||||
import it.integry.ems.response.ServiceRestResponse;
|
|
||||||
import it.integry.ems.schedule.new_cron_job.dto.operations.CheckB2BAutomatedOperationDTO;
|
import it.integry.ems.schedule.new_cron_job.dto.operations.CheckB2BAutomatedOperationDTO;
|
||||||
import it.integry.ems.service.HttpRestWrapper;
|
import it.integry.ems.service.HttpRestWrapper;
|
||||||
import it.integry.ems_model.config.EmsRestConstants;
|
import it.integry.ems_model.config.EmsRestConstants;
|
||||||
import it.integry.ems_model.utility.UtilityServer;
|
import org.springframework.web.context.ContextLoader;
|
||||||
import org.apache.http.entity.ContentType;
|
|
||||||
|
|
||||||
public class CheckB2BScheduledOperationRunner extends BaseScheduledOperationRunner<CheckB2BAutomatedOperationDTO> {
|
public class CheckB2BScheduledOperationRunner extends BaseScheduledOperationRunner<CheckB2BAutomatedOperationDTO> {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
String port = UtilityServer.getLocalServerPort();
|
final HttpRestWrapper httpRestWrapper = ContextLoader.getCurrentWebApplicationContext().getBean(HttpRestWrapper.class);
|
||||||
|
|
||||||
String baseUrl = "http://localhost:" + port + "/ems-api/"
|
final Object internalGetResponse = httpRestWrapper.callInternalGet(getDtoInstance().getProfileDb(),
|
||||||
+ EmsRestConstants.PATH_READ_FPX_INBOX + "?"
|
EmsRestConstants.PATH_READ_FPX_INBOX,
|
||||||
+ CommonConstants.PROFILE_DB + "=" + getDtoInstance().getProfileDb();
|
getDtoInstance().getUsername());
|
||||||
|
|
||||||
StringBuilder responseBody = new StringBuilder();
|
|
||||||
HttpRestWrapper.callGeneric(
|
|
||||||
baseUrl,
|
|
||||||
getDtoInstance().getUsername(),
|
|
||||||
getDtoInstance().getPassword(),
|
|
||||||
null,
|
|
||||||
ContentType.APPLICATION_JSON,
|
|
||||||
responseBody);
|
|
||||||
|
|
||||||
String responseJson = responseBody.toString();
|
|
||||||
|
|
||||||
ResponseJSONObjectMapper mapper = new ResponseJSONObjectMapper();
|
|
||||||
|
|
||||||
ServiceRestResponse serviceRestResponse = mapper.readValue(responseJson, ServiceRestResponse.class);
|
|
||||||
|
|
||||||
if (serviceRestResponse.getEsito().equals(EsitoType.KO)) {
|
|
||||||
logger.error(String.format("Eccezione %s generata dall'operazione %s", serviceRestResponse.getErrorMessage(), this.getDtoInstance().getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package it.integry.ems.service;
|
|||||||
import it.integry.common.var.CommonConstants;
|
import it.integry.common.var.CommonConstants;
|
||||||
import it.integry.ems.json.ResponseJSONObjectMapper;
|
import it.integry.ems.json.ResponseJSONObjectMapper;
|
||||||
import it.integry.ems.properties.EmsProperties;
|
import it.integry.ems.properties.EmsProperties;
|
||||||
|
import it.integry.ems.response.EsitoType;
|
||||||
import it.integry.ems.response.ServiceRestResponse;
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
import it.integry.ems_model.config.EmsRestConstants;
|
import it.integry.ems_model.config.EmsRestConstants;
|
||||||
|
import it.integry.ems_model.exception.InternalRestCallException;
|
||||||
|
import it.integry.ems_model.utility.UtilityServer;
|
||||||
import it.integry.ems_model.utility.UtilityString;
|
import it.integry.ems_model.utility.UtilityString;
|
||||||
import it.integry.security.utility.RestUtil;
|
import it.integry.security.utility.RestUtil;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
@@ -53,6 +56,38 @@ public class HttpRestWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Object callInternalGet(String profileDb, String service, String username) throws Exception {
|
||||||
|
final String endPoint = String.format("http://localhost:%s/ems-api/", UtilityServer.getLocalServerPort());
|
||||||
|
|
||||||
|
final Client client = ClientBuilder.newClient();
|
||||||
|
final WebTarget resource = client.target(endPoint)
|
||||||
|
.path(service);
|
||||||
|
|
||||||
|
Response response = resource
|
||||||
|
.queryParam(CommonConstants.PROFILE_DB, profileDb)
|
||||||
|
.request()
|
||||||
|
//.header("Authorization", "Basic " + auth)
|
||||||
|
.header("username", username)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
int status = response.getStatus();
|
||||||
|
|
||||||
|
if(status != 200)
|
||||||
|
throw new InternalRestCallException(status);
|
||||||
|
|
||||||
|
String stringResponse = response.readEntity(String.class);
|
||||||
|
|
||||||
|
final ServiceRestResponse serviceRestResponse = jsonObjectMapper.readValue(stringResponse, ServiceRestResponse.class);
|
||||||
|
|
||||||
|
if (serviceRestResponse.getEsito() == EsitoType.OK || serviceRestResponse.getEsito() == EsitoType.WARNING) {
|
||||||
|
return serviceRestResponse.getJsonObject();
|
||||||
|
} else {
|
||||||
|
throw new InternalRestCallException(status, serviceRestResponse.getErrorMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int callGenericGet(String url, String username, String password, StringBuilder bodyResponse, HashMap<String, String> queryParams) throws NoSuchAlgorithmException, KeyManagementException {
|
public static int callGenericGet(String url, String username, String password, StringBuilder bodyResponse, HashMap<String, String> queryParams) throws NoSuchAlgorithmException, KeyManagementException {
|
||||||
final Client client = makeDefaultConfig();
|
final Client client = makeDefaultConfig();
|
||||||
WebTarget webTarget = client.target(url);
|
WebTarget webTarget = client.target(url);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package it.integry.ems_model.exception;
|
||||||
|
|
||||||
|
public class InternalRestCallException extends Exception {
|
||||||
|
|
||||||
|
private final int statusCode;
|
||||||
|
|
||||||
|
public InternalRestCallException(int statusCode) {
|
||||||
|
super("Errore durante la chiamata (Status " + statusCode + ")");
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
public InternalRestCallException(int statusCode, String cause) {
|
||||||
|
super(cause + " (Status " + statusCode + ")");
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatusCode() {
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user