Update channelOrigin as String
This commit is contained in:
parent
9d9f593c56
commit
ec8c9060f4
Binary file not shown.
@ -40,6 +40,14 @@ public class MessageHelper {
|
||||
this.errorMappings = initializeErrorMappings();
|
||||
}
|
||||
|
||||
public Response handleSuccess(Object data, String statusCode) {
|
||||
log.info(
|
||||
"Respuesta exitosa controlada: {}",
|
||||
statusCode
|
||||
);
|
||||
return buildResponse(data, statusCode);
|
||||
}
|
||||
|
||||
public Response handleException(HttpStatusCodeException exception) {
|
||||
log.error(
|
||||
"Error interno controlado: {} -> {}",
|
||||
@ -110,6 +118,25 @@ public class MessageHelper {
|
||||
.build();
|
||||
}
|
||||
|
||||
private Response buildResponse(Object data, String statusCode) {
|
||||
ErrorMapping mapping = errorMappings.getOrDefault(
|
||||
statusCode, errorMappings.getOrDefault(
|
||||
statusCode, createDefaultMapping()
|
||||
)
|
||||
);
|
||||
StatusResponse status = createError(mapping, null);
|
||||
|
||||
log.error(
|
||||
"[Success] Message {} -> {}",
|
||||
statusCode,
|
||||
status.getMessage()
|
||||
);
|
||||
|
||||
return Response.status(mapping.getHttpCode())
|
||||
.entity(new ApiResponse<>(data, status))
|
||||
.build();
|
||||
}
|
||||
|
||||
private Map<String, ErrorMapping> initializeErrorMappings() {
|
||||
try {
|
||||
String json;
|
||||
|
||||
@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -34,56 +36,61 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
|
||||
@Override
|
||||
public <T> T execute(HttpRequest request) {
|
||||
return executeInternal(request);
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, R> Either<T, R> executeEither(HttpRequest request) {
|
||||
return executeEitherInternal(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, R> Either<List<T>, R> executeEitherList(HttpRequest request) {
|
||||
return executeEitherInternal(request, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiResponse<T> executeApiResponse(HttpRequest request) {
|
||||
return executeInternal(request);
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiResponse<List<T>> executeApiResponseList(
|
||||
HttpRequest request
|
||||
) {
|
||||
return executeInternal(request);
|
||||
public <T> ApiResponse<List<T>> executeApiResponseList(HttpRequest request) {
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiPrivateResponse<Either<T, ApiPrivateError>> executeApiPrivateResponse(
|
||||
HttpRequest request
|
||||
) {
|
||||
return executeInternal(request);
|
||||
public <T> ApiPrivateResponse<Either<T, ApiPrivateError>> executeApiPrivateResponse(HttpRequest request) {
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ApiPrivateResponse<Either<List<T>, ApiPrivateError>> executeApiPrivateResponseList(
|
||||
HttpRequest request
|
||||
) {
|
||||
return executeInternal(request);
|
||||
public <T> ApiPrivateResponse<Either<List<T>, ApiPrivateError>> executeApiPrivateResponseList(HttpRequest request) {
|
||||
return executeRequest(request);
|
||||
}
|
||||
|
||||
private <T> T executeInternal(HttpRequest request) {
|
||||
String finalUrl = buildFinalUrl(request);
|
||||
|
||||
if (request.isLogRequestBody()) {
|
||||
log.info("URL final: {}", finalUrl);
|
||||
|
||||
if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
|
||||
log.info("Headers: {}", request.getHeaders());
|
||||
}
|
||||
|
||||
if (request.getQueryParams() != null && !request.getQueryParams().isEmpty()) {
|
||||
log.info("Query params: {}", request.getQueryParams());
|
||||
}
|
||||
|
||||
if (request.getBody() != null) {
|
||||
log.info("Body: {}", request.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
private <T, R> Either<T, R> executeEitherInternal(HttpRequest request, boolean isList) {
|
||||
try (Client client = createClient(request.getConnectTimeout(), request.getReadTimeout())) {
|
||||
WebTarget target = client.target(finalUrl);
|
||||
WebTarget target = client.target(buildFinalUrl(request));
|
||||
Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
|
||||
|
||||
if (request.getHeaders() != null) {
|
||||
request.getHeaders().forEach(builder::header);
|
||||
}
|
||||
|
||||
Response response = buildRequest(builder, request);
|
||||
return handleEitherResponse(request, response, isList);
|
||||
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw handleConnectionError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T executeRequest(HttpRequest request) {
|
||||
try (Client client = createClient(request.getConnectTimeout(), request.getReadTimeout())) {
|
||||
WebTarget target = client.target(buildFinalUrl(request));
|
||||
Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
|
||||
|
||||
if (request.getHeaders() != null) {
|
||||
@ -95,14 +102,122 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("Error de conexion {}: {}", request.getMethod(), e.getMessage());
|
||||
throw HttpStatusCodeException.serviceUnavailable(
|
||||
"503",
|
||||
"Error de conexion con el servicio externo: " + e.getMessage()
|
||||
);
|
||||
throw handleConnectionError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T, R> Either<T, R> handleEitherResponse(HttpRequest request, Response response, boolean isList) {
|
||||
int statusCode = response.getStatus();
|
||||
|
||||
try (response) {
|
||||
String responseBody = response.readEntity(String.class);
|
||||
logResponse(request, statusCode, responseBody);
|
||||
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
Object successData = isList
|
||||
? parseSuccessListResponse(request, responseBody)
|
||||
: parseSuccessResponse(request, responseBody);
|
||||
return Either.left((T) successData);
|
||||
} else {
|
||||
logErrorResponse(request, statusCode, responseBody);
|
||||
R errorData = tryParseErrorResponse(request, responseBody);
|
||||
|
||||
if (errorData != null) {
|
||||
return Either.right(errorData);
|
||||
}
|
||||
|
||||
throw mapHttpStatusToException(statusCode, responseBody);
|
||||
}
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw handleProcessingError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T parseSuccessResponse(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
Type successType = extractSuccessType(request);
|
||||
|
||||
if (successType != null) {
|
||||
if (successType instanceof Class) {
|
||||
return objectMapper.readValue(responseBody, (Class<T>) successType);
|
||||
} else if (successType instanceof ParameterizedType) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructType(successType);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.getResponseType() != null && request.getResponseType() != Object.class) {
|
||||
return objectMapper.readValue(responseBody, objectMapper.getTypeFactory().constructType(request.getResponseType()));
|
||||
}
|
||||
|
||||
return (T) objectMapper.readValue(responseBody, Object.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> List<T> parseSuccessListResponse(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
Type successType = extractSuccessType(request);
|
||||
|
||||
if (
|
||||
successType instanceof ParameterizedType paramType &&
|
||||
paramType.getRawType() == List.class &&
|
||||
paramType.getActualTypeArguments().length > 0
|
||||
) {
|
||||
Type elementType = paramType.getActualTypeArguments()[0];
|
||||
if (elementType instanceof Class) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructCollectionType(
|
||||
List.class, (Class<T>) elementType
|
||||
);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
}
|
||||
}
|
||||
|
||||
return objectMapper.readValue(responseBody, List.class);
|
||||
}
|
||||
|
||||
private Type extractSuccessType(HttpRequest request) {
|
||||
if (
|
||||
request.getComplexType() != null &&
|
||||
request.getComplexType() instanceof ParameterizedType paramType &&
|
||||
paramType.getRawType() == Either.class &&
|
||||
paramType.getActualTypeArguments().length > 0
|
||||
) {
|
||||
return paramType.getActualTypeArguments()[0];
|
||||
}
|
||||
|
||||
if (request.getGenericType() != null) {
|
||||
return request.getGenericType();
|
||||
}
|
||||
|
||||
return request.getResponseType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <R> R tryParseErrorResponse(HttpRequest request, String responseBody) {
|
||||
if (responseBody == null || responseBody.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (request.getErrorType() != null) {
|
||||
return (R) objectMapper.readValue(responseBody, request.getErrorType());
|
||||
}
|
||||
|
||||
if (request.getComplexType() != null && request.getComplexType() instanceof ParameterizedType paramType) {
|
||||
Type[] typeArgs = paramType.getActualTypeArguments();
|
||||
if (typeArgs.length >= 2 && typeArgs[1] instanceof Class) {
|
||||
return objectMapper.readValue(responseBody, (Class<R>) typeArgs[1]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("No se pudo parsear la respuesta como error type: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String buildFinalUrl(HttpRequest request) {
|
||||
String finalUrl = request.getUrl();
|
||||
|
||||
@ -113,7 +228,11 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
return appendQueryParams(finalUrl, request.getQueryParams());
|
||||
String url = appendQueryParams(finalUrl, request.getQueryParams());
|
||||
|
||||
log.info("Url Final: {}", url);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private String appendQueryParams(String url, Map<String, String> queryParams) {
|
||||
@ -132,20 +251,24 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
urlBuilder.append("&");
|
||||
}
|
||||
|
||||
urlBuilder.append(entry.getKey())
|
||||
.append("=")
|
||||
.append(entry.getValue() != null ? entry.getValue() : "");
|
||||
String encodedKey = URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8);
|
||||
String encodedValue = entry.getValue() != null
|
||||
? URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)
|
||||
: "";
|
||||
|
||||
urlBuilder.append(encodedKey).append("=").append(encodedValue);
|
||||
}
|
||||
|
||||
return urlBuilder.toString();
|
||||
}
|
||||
|
||||
private Response buildRequest(
|
||||
Invocation.Builder builder,
|
||||
HttpRequest request
|
||||
) {
|
||||
private Response buildRequest(Invocation.Builder builder, HttpRequest request) {
|
||||
log.info("Metodo HTTP: {}", request.getMethod().name());
|
||||
|
||||
if(request.getBody() != null) {
|
||||
log.info("Peticion Cuerpo: {}", request.getBody());
|
||||
}
|
||||
|
||||
return switch (request.getMethod()) {
|
||||
case GET -> builder.get();
|
||||
case POST -> builder.post(Entity.entity(request.getBody(), MediaType.APPLICATION_JSON));
|
||||
@ -160,43 +283,26 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
|
||||
private Client createClient(int connectTimeout, int readTimeout) {
|
||||
return ClientBuilder.newBuilder()
|
||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
private <T> T handleResponse(
|
||||
HttpRequest request,
|
||||
Response response
|
||||
) {
|
||||
private <T> T handleResponse(HttpRequest request, Response response) {
|
||||
int statusCode = response.getStatus();
|
||||
log.info("Respuesta {} - Status: {}", request.getMethod(), statusCode);
|
||||
|
||||
try (response) {
|
||||
String responseBody = response.readEntity(String.class);
|
||||
|
||||
if (request.isLogResponseBody()) {
|
||||
log.info("Respuesta Cuerpo: {}", responseBody);
|
||||
}
|
||||
logResponse(request, statusCode, responseBody);
|
||||
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
if (request.getResponseType() == Void.class || request.getResponseType() == void.class) {
|
||||
return null;
|
||||
}
|
||||
|
||||
T result = responseResult(request, responseBody);
|
||||
|
||||
log.debug("Respuesta exitosa {} {}: {}", request.getMethod(), request.getUrl(), result);
|
||||
|
||||
return result;
|
||||
return responseResult(request, responseBody);
|
||||
} else {
|
||||
log.error(
|
||||
"Error HTTP {} {} - Status: {} - Body: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
statusCode,
|
||||
responseBody
|
||||
);
|
||||
logErrorResponse(request, statusCode, responseBody);
|
||||
|
||||
if (isApiResponseFormat(responseBody)) {
|
||||
ApiResponse<?> apiResponse = deserializeApiResponse(responseBody, request);
|
||||
@ -208,53 +314,72 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
} catch (HttpStatusCodeException | HttpApiResponseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error(
|
||||
"Error procesando respuesta {} {}: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
e.getMessage()
|
||||
);
|
||||
throw HttpStatusCodeException.internalServer(
|
||||
"500", "Error procesando respuesta del servicio externo: " + e.getMessage()
|
||||
);
|
||||
throw handleProcessingError(request, e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T responseResult(
|
||||
HttpRequest request,
|
||||
String responseBody
|
||||
) throws JsonProcessingException {
|
||||
private void logResponse(HttpRequest request, int statusCode, String responseBody) {
|
||||
if (request.isLogResponseBody()) {
|
||||
log.info("Respuesta {} - Status: {}", request.getMethod(), statusCode);
|
||||
log.info("Respuesta Cuerpo: {}", responseBody);
|
||||
}
|
||||
}
|
||||
|
||||
private void logErrorResponse(HttpRequest request, int statusCode, String responseBody) {
|
||||
log.error(
|
||||
"Error HTTP {} {} - Status: {} - Body: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
statusCode,
|
||||
responseBody
|
||||
);
|
||||
}
|
||||
|
||||
private HttpStatusCodeException handleConnectionError(HttpRequest request, Exception e) {
|
||||
log.error("Error de conexion {}: {}", request.getMethod(), e.getMessage());
|
||||
|
||||
return HttpStatusCodeException.serviceUnavailable(
|
||||
"503", "Error de conexion con el servicio externo: " + e.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
private HttpStatusCodeException handleProcessingError(HttpRequest request, Exception e) {
|
||||
log.error(
|
||||
"Error procesando respuesta {} {}: {}",
|
||||
request.getMethod(),
|
||||
request.getUrl(),
|
||||
e.getMessage()
|
||||
);
|
||||
return HttpStatusCodeException.internalServer(
|
||||
"500", "Error procesando respuesta del servicio externo: " + e.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
private <T> T responseResult(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
if (request.isApiPrivateResponse() && request.isEitherResponse()) {
|
||||
return handleApiPrivateResponseWithEither(request, responseBody);
|
||||
}
|
||||
|
||||
T result;
|
||||
|
||||
if (request.getResponseType() == ApiResponse.class) {
|
||||
result = deserializeApiResponse(responseBody, request);
|
||||
return deserializeApiResponse(responseBody, request);
|
||||
} else if (request.getComplexType() != null) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(
|
||||
request.getResponseType(), objectMapper.getTypeFactory().constructType(request.getComplexType())
|
||||
);
|
||||
result = objectMapper.readValue(responseBody, javaType);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
} else if (request.getGenericType() != null) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(
|
||||
request.getResponseType(), objectMapper.getTypeFactory().constructType(request.getGenericType())
|
||||
);
|
||||
result = objectMapper.readValue(responseBody, javaType);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
} else {
|
||||
result = objectMapper.readValue(
|
||||
return objectMapper.readValue(
|
||||
responseBody, objectMapper.getTypeFactory().constructType(request.getResponseType())
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> T handleApiPrivateResponseWithEither(
|
||||
HttpRequest request,
|
||||
String responseBody
|
||||
) throws JsonProcessingException {
|
||||
private <T> T handleApiPrivateResponseWithEither(HttpRequest request, String responseBody) throws JsonProcessingException {
|
||||
JsonNode rootNode = objectMapper.readTree(responseBody);
|
||||
String status = rootNode.has("estatus") ? rootNode.get("estatus").asText() : null;
|
||||
String message = rootNode.has("mensaje") ? rootNode.get("mensaje").asText() : null;
|
||||
@ -268,12 +393,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T handleSuccessResponse(
|
||||
HttpRequest request,
|
||||
String status,
|
||||
String message,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private <T> T handleSuccessResponse(HttpRequest request, String status, String message, JsonNode detailNode) {
|
||||
Object successData;
|
||||
|
||||
if (request.isListResponse()) {
|
||||
@ -295,10 +415,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private Object handleListSuccess(
|
||||
HttpRequest request,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private Object handleListSuccess(HttpRequest request, JsonNode detailNode) {
|
||||
Class<?> elementType = getElementTypeFromRequest(request);
|
||||
JavaType listType = objectMapper.getTypeFactory().constructCollectionType(List.class, elementType);
|
||||
|
||||
@ -309,10 +426,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private Object handleObjectSuccess(
|
||||
HttpRequest request,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private Object handleObjectSuccess(HttpRequest request, JsonNode detailNode) {
|
||||
Class<?> elementType = getElementTypeFromRequest(request);
|
||||
|
||||
if (detailNode != null && !detailNode.isNull()) {
|
||||
@ -323,11 +437,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T handleErrorResponse(
|
||||
String status,
|
||||
String message,
|
||||
JsonNode detailNode
|
||||
) {
|
||||
private <T> T handleErrorResponse(String status, String message, JsonNode detailNode) {
|
||||
ApiPrivateError error = buildApiPrivateError(detailNode, message);
|
||||
ApiPrivateResponse<Either<Object, ApiPrivateError>> response = new ApiPrivateResponse<>();
|
||||
|
||||
@ -338,10 +448,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
return (T) response;
|
||||
}
|
||||
|
||||
private ApiPrivateError buildApiPrivateError(
|
||||
JsonNode detailNode,
|
||||
String message
|
||||
) {
|
||||
private ApiPrivateError buildApiPrivateError(JsonNode detailNode, String message) {
|
||||
if (detailNode != null && !detailNode.isNull()) {
|
||||
try {
|
||||
return objectMapper.convertValue(detailNode, ApiPrivateError.class);
|
||||
@ -385,15 +492,11 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T deserializeApiResponse(
|
||||
String responseBody,
|
||||
HttpRequest request
|
||||
) {
|
||||
private <T> T deserializeApiResponse(String responseBody, HttpRequest request) {
|
||||
try {
|
||||
if (request.getGenericType() != null) {
|
||||
JavaType javaType = objectMapper.getTypeFactory().constructParametricType(
|
||||
ApiResponse.class,
|
||||
objectMapper.getTypeFactory().constructType(request.getGenericType())
|
||||
ApiResponse.class, objectMapper.getTypeFactory().constructType(request.getGenericType())
|
||||
);
|
||||
return objectMapper.readValue(responseBody, javaType);
|
||||
} else {
|
||||
@ -427,10 +530,7 @@ public class HttpClientService implements HttpClientUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private HttpStatusCodeException mapHttpStatusToException(
|
||||
int statusCode,
|
||||
String errorBody
|
||||
) {
|
||||
private HttpStatusCodeException mapHttpStatusToException(int statusCode, String errorBody) {
|
||||
String errorCode = "HTTP_" + statusCode;
|
||||
String defaultMessage = "Error en servicio externo: HTTP " + statusCode;
|
||||
String message = errorBody != null && !errorBody.isEmpty()
|
||||
|
||||
@ -8,6 +8,10 @@ public interface HttpClientUseCase {
|
||||
|
||||
<T> T execute(HttpRequest request);
|
||||
|
||||
<T, R> Either<T, R> executeEither(HttpRequest request);
|
||||
|
||||
<T, R> Either<List<T>, R> executeEitherList(HttpRequest request);
|
||||
|
||||
<T> ApiResponse<T> executeApiResponse(HttpRequest request);
|
||||
|
||||
<T> ApiResponse<List<T>> executeApiResponseList(HttpRequest request);
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
package com.banesco.common.domain.exception;
|
||||
|
||||
public class BusinessException extends BaseApiException {
|
||||
public BusinessException(String errorCode, String message, String fieldPath) {
|
||||
super(errorCode, message, fieldPath, "business");
|
||||
}
|
||||
|
||||
public BusinessException(String errorCode, String fieldPath) {
|
||||
super(errorCode, fieldPath, "business");
|
||||
}
|
||||
}
|
||||
17
src/main/java/com/banesco/common/domain/model/Device.java
Normal file
17
src/main/java/com/banesco/common/domain/model/Device.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.banesco.common.domain.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class Device {
|
||||
private String deviceType;
|
||||
private String deviceDescription;
|
||||
private String deviceIp;
|
||||
private String deviceSessionReference;
|
||||
}
|
||||
@ -69,4 +69,13 @@ public class RestClientConfig {
|
||||
throw new IllegalStateException("Error cargando configuracion del servicio " + configName + ": " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public String toJsonString(Object object) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(object);
|
||||
} catch (Exception e) {
|
||||
log.error("Error al convertir a json string: {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,9 @@ public class RequestContext {
|
||||
|
||||
private RequestContext() {}
|
||||
|
||||
private static final String REQUEST_ID = "requestId";
|
||||
public static final String REQUEST_ID = "requestId";
|
||||
public static final String DEVICE = "device";
|
||||
public static final String DEVICE_SESSION_REFERENCE = "deviceSessionReference";
|
||||
|
||||
public static String getRequestId() {
|
||||
return MDC.get(REQUEST_ID);
|
||||
|
||||
@ -6,15 +6,88 @@ import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
import jakarta.ws.rs.container.ContainerResponseContext;
|
||||
import jakarta.ws.rs.container.ContainerResponseFilter;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Provider
|
||||
public class RequestIdFilter implements ContainerRequestFilter, ContainerResponseFilter {
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext) {
|
||||
RequestContext.setRequestId(UUID.randomUUID().toString().substring(0, 13));
|
||||
String requestId = requestContext.getHeaderString(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
|
||||
if (isEmpty(requestId)) {
|
||||
requestId = requestContext.getUriInfo()
|
||||
.getQueryParameters()
|
||||
.getFirst(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
}
|
||||
|
||||
if (isEmpty(requestId) && hasJsonBody(requestContext)) {
|
||||
requestId = extractRequestIdFromBody(requestContext);
|
||||
}
|
||||
|
||||
if (isEmpty(requestId)) {
|
||||
requestId = UUID.randomUUID().toString().substring(0, 13);
|
||||
}
|
||||
|
||||
RequestContext.setRequestId(requestId);
|
||||
}
|
||||
|
||||
private boolean isEmpty(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
private boolean hasJsonBody(ContainerRequestContext context) {
|
||||
try {
|
||||
String method = context.getMethod();
|
||||
String contentType = context.getHeaderString("Content-Type");
|
||||
|
||||
return ("POST".equals(method) || "PUT".equals(method))
|
||||
&& contentType != null
|
||||
&& contentType.contains("application/json");
|
||||
} catch (Exception e) {
|
||||
log.warn("La peticion no es un POST o PUT: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String extractRequestIdFromBody(ContainerRequestContext context) {
|
||||
try {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
context.getEntityStream().transferTo(buffer);
|
||||
byte[] bodyBytes = buffer.toByteArray();
|
||||
|
||||
context.setEntityStream(new ByteArrayInputStream(bodyBytes));
|
||||
|
||||
String bodyString = new String(bodyBytes, StandardCharsets.UTF_8);
|
||||
io.vertx.core.json.JsonObject jsonObject = new io.vertx.core.json.JsonObject(bodyString);
|
||||
|
||||
if (jsonObject.containsKey(RequestContext.DEVICE)) {
|
||||
io.vertx.core.json.JsonObject device = jsonObject.getJsonObject(RequestContext.DEVICE);
|
||||
|
||||
if (device.containsKey(RequestContext.DEVICE_SESSION_REFERENCE)) {
|
||||
return device.getString(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonObject.containsKey(RequestContext.REQUEST_ID)) {
|
||||
return jsonObject.getString(RequestContext.REQUEST_ID);
|
||||
}
|
||||
|
||||
if (jsonObject.containsKey(RequestContext.DEVICE_SESSION_REFERENCE)) {
|
||||
return jsonObject.getString(RequestContext.DEVICE_SESSION_REFERENCE);
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("Error extrayendo el requestId del cuerpo de la peticion: {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -22,6 +95,10 @@ public class RequestIdFilter implements ContainerRequestFilter, ContainerRespons
|
||||
ContainerRequestContext requestContext,
|
||||
ContainerResponseContext responseContext
|
||||
) {
|
||||
RequestContext.clear();
|
||||
try {
|
||||
RequestContext.clear();
|
||||
} catch (Exception e) {
|
||||
log.error("Error limpiando el filtro: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,4 +7,5 @@ public enum BankingProductType {
|
||||
BROKERED_PRODUCT,
|
||||
TERM_DEPOSIT_PRODUCT,
|
||||
MOBILE_PAYMENT,
|
||||
NETUNO
|
||||
}
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
package com.banesco.module.instruction.domain.model;
|
||||
|
||||
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
||||
import com.banesco.common.domain.model.Identifier;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Builder
|
||||
@ -19,21 +15,12 @@ import java.util.Objects;
|
||||
public class Instruction {
|
||||
private InstructionIdentification instructionIdentifier; // Request JSON: "id"
|
||||
private String instructionDescription; // Request JSON: "signature"
|
||||
private InstructionPurposeType instructionPurposeType; // Request JSON: "channelOrigin" (BOLE)
|
||||
private String instructionPurposeType; // Request JSON: "channelOrigin" (BOLE)
|
||||
|
||||
public static Instruction fromResource(
|
||||
String paymentStatusId,
|
||||
String channelCode,
|
||||
String signatureIdentifier
|
||||
String channelCode
|
||||
) {
|
||||
boolean isChannelCodeValid = (Arrays.stream(
|
||||
InstructionPurposeType.values()
|
||||
).anyMatch(type -> Objects.equals(type.name(), channelCode)));
|
||||
|
||||
if(!isChannelCodeValid) {
|
||||
throw HttpStatusCodeException.badRequest("VDE02", "channelCode");
|
||||
}
|
||||
|
||||
return Instruction.builder()
|
||||
.instructionIdentifier(
|
||||
InstructionIdentification.builder()
|
||||
@ -45,8 +32,7 @@ public class Instruction {
|
||||
.identificationType(InstructionIdentificationType.INSTRUCTION_NUMBER)
|
||||
.build()
|
||||
)
|
||||
.instructionPurposeType(InstructionPurposeType.valueOf(channelCode))
|
||||
.instructionDescription(signatureIdentifier)
|
||||
.instructionPurposeType(channelCode)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
package com.banesco.module.instruction.domain.model;
|
||||
|
||||
public enum InstructionPurposeType {
|
||||
BOLE,
|
||||
BOL,
|
||||
}
|
||||
@ -1,5 +1,14 @@
|
||||
package com.banesco.module.security_trace.application.usecase;
|
||||
|
||||
import com.banesco.module.service_issue_payment_status.domain.dto.request.ServiceIssuePaymentStatusRequest;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
public interface SecurityTraceUseCase {
|
||||
<T> T execute(Class<T> responseType);
|
||||
<T> T execute(
|
||||
ServiceIssuePaymentStatusRequest apiRequest,
|
||||
Response apiResponse,
|
||||
long startTime,
|
||||
long endTime,
|
||||
Class<T> responseType
|
||||
);
|
||||
}
|
||||
|
||||
@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Builder
|
||||
@ -12,8 +15,120 @@ import lombok.*;
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SecurityTraceRequest {
|
||||
private String codBan;
|
||||
private String codMon;
|
||||
private String codEve;
|
||||
private String codEve2;
|
||||
private String login;
|
||||
private Date fecHor;
|
||||
private String nacCli;
|
||||
private Integer cedRifCli;
|
||||
private String tipoProductoCli;
|
||||
private String tipoProductoBen;
|
||||
private String productoCli;
|
||||
private String codEmpresa;
|
||||
private String nacBen;
|
||||
private Integer cedBen;
|
||||
private String nombreBen;
|
||||
private String productoBen;
|
||||
private BigDecimal monto;
|
||||
private String referencia;
|
||||
private String nroDePago;
|
||||
private String desPago;
|
||||
private String objeto;
|
||||
private Integer tipoRespuesta;
|
||||
private String msgRespuesta;
|
||||
private Long tiempoRespuesta;
|
||||
private String codFintech;
|
||||
private String cedRifFintech;
|
||||
private String nombreFintech;
|
||||
private String tipoDispositivo;
|
||||
private String desDispositivo;
|
||||
private String ipCli;
|
||||
private String refInternacional;
|
||||
private BigDecimal montoReceptor;
|
||||
private String refBanco;
|
||||
private String stsTransaccion;
|
||||
private String tipoMonedaEmi;
|
||||
private String tipoMonedaRec;
|
||||
private String paisEmisor;
|
||||
private String paisReceptor;
|
||||
private BigDecimal montoEmisor;
|
||||
private String numeroCuentaEmi;
|
||||
private String numeroCuentaRec;
|
||||
private String numeroTelefonoRec;
|
||||
private String propositoTransaccion;
|
||||
private BigDecimal montoComision;
|
||||
private String tipoIdEmisor;
|
||||
private String idEmisor;
|
||||
private BigDecimal numeroTarjeta;
|
||||
private Integer codigoAutoriza;
|
||||
private String refUniversal;
|
||||
private String fechaAprobacion;
|
||||
private String refBanesco;
|
||||
private String fecHorCarga;
|
||||
private String tipoProductoEmisor;
|
||||
private String ctaEmisor;
|
||||
private String tipoProductoReceptor;
|
||||
private String ctaReceptor;
|
||||
private String idReceptor;
|
||||
private String nombreReceptor;
|
||||
private String refExterna;
|
||||
private String origenFondos;
|
||||
private String destinoFondos;
|
||||
private String fecHorTransaccion;
|
||||
private String metodoPagoEmisor;
|
||||
private String valorMetodoPagoEmisor;
|
||||
private String entFinancieraEmisor;
|
||||
private String nombreEmisor;
|
||||
private String monedaEmisor;
|
||||
private String metodoPagoReceptor;
|
||||
private String valorMetodoPagoReceptor;
|
||||
private String entFinancieraReceptor;
|
||||
private String monedaReceptor;
|
||||
private String descPago;
|
||||
private String descTransaccion;
|
||||
private BigDecimal tasaComision;
|
||||
private BigDecimal numTarjeta;
|
||||
private String codAutorizacion;
|
||||
private String fecHorAprobacion;
|
||||
private BigDecimal montoIgtf;
|
||||
private BigDecimal montoLbtr;
|
||||
private BigDecimal tasaCambio;
|
||||
private BigDecimal montoTotalBs;
|
||||
private String sp;
|
||||
private String eventCod;
|
||||
private String bankCod;
|
||||
private String curCod;
|
||||
private String cn;
|
||||
private String OU;
|
||||
private String distinguishedName;
|
||||
private String userPassword;
|
||||
private Integer Enabled;
|
||||
private String givenName;
|
||||
private String sn;
|
||||
private String mail;
|
||||
private String employeeNumber;
|
||||
private String employeeID;
|
||||
private String mobile;
|
||||
private String homePhone;
|
||||
private String company;
|
||||
private String personalTitle;
|
||||
private String title;
|
||||
private String description;
|
||||
private String departament;
|
||||
private String otherMobile;
|
||||
private String otherHomePhone;
|
||||
private String telephoneNumber;
|
||||
private String facsimileTelephoneNumber;
|
||||
private String postalAddress;
|
||||
private String postalCode;
|
||||
private String st;
|
||||
private String owner;
|
||||
private String serialNumber;
|
||||
private String usuarioMaster;
|
||||
private Integer lockoutTime;
|
||||
private Integer lockoutDuration;
|
||||
private Integer lockoutThreshold;
|
||||
private Integer badPwdCount;
|
||||
private String badPasswordTime;
|
||||
private String oU;
|
||||
private Integer enabled;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.banesco.module.security_trace.domain.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
@JsonPropertyOrder({"RQ", "RS"})
|
||||
@JsonNaming(PropertyNamingStrategies.UpperSnakeCaseStrategy.class)
|
||||
public class SecurityTraceObject {
|
||||
private Object RQ;
|
||||
private Object RS;
|
||||
}
|
||||
@ -2,19 +2,27 @@ package com.banesco.module.security_trace.infrastructure.client;
|
||||
|
||||
import com.banesco.common.application.usecase.HttpClientUseCase;
|
||||
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
||||
import com.banesco.common.domain.model.ApiResponse;
|
||||
import com.banesco.common.domain.model.HttpRequest;
|
||||
import com.banesco.common.infrastructure.config.RestClientConfig;
|
||||
import com.banesco.module.security_trace.application.usecase.SecurityTraceUseCase;
|
||||
import com.banesco.module.security_trace.domain.dto.request.SecurityTraceRequest;
|
||||
import com.banesco.module.security_trace.domain.model.SecurityTraceConfig;
|
||||
import com.banesco.module.security_trace.domain.model.SecurityTraceObject;
|
||||
import com.banesco.module.service_issue_payment_status.domain.dto.request.ServiceIssuePaymentStatusRequest;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
public class SecurityTraceClient implements SecurityTraceUseCase {
|
||||
private final HttpClientUseCase httpClientUseCase;
|
||||
private final RestClientConfig restClientConfig;
|
||||
private final SecurityTraceConfig securityTraceConfig;
|
||||
|
||||
@Inject
|
||||
@ -23,13 +31,23 @@ public class SecurityTraceClient implements SecurityTraceUseCase {
|
||||
RestClientConfig restClientConfig
|
||||
) {
|
||||
this.httpClientUseCase = httpClientUseCase;
|
||||
this.restClientConfig = restClientConfig;
|
||||
this.securityTraceConfig = restClientConfig.getSecurityTraceConfig();
|
||||
log.info("Configuracion cargada para security-trace: {}", securityTraceConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T execute(Class<T> responseType) {
|
||||
SecurityTraceRequest body = securityTraceConfig.getRequest();
|
||||
public <T> T execute(
|
||||
ServiceIssuePaymentStatusRequest apiRequest,
|
||||
Response apiResponse,
|
||||
long startTime,
|
||||
long endTime,
|
||||
Class<T> responseType
|
||||
) {
|
||||
SecurityTraceRequest body = getRequest(
|
||||
apiRequest, apiResponse,
|
||||
startTime, endTime
|
||||
);
|
||||
HttpRequest request = HttpRequest.forDirectResponse(
|
||||
securityTraceConfig.getUrl(),
|
||||
HttpRequest.HttpMethod.POST,
|
||||
@ -41,8 +59,6 @@ public class SecurityTraceClient implements SecurityTraceUseCase {
|
||||
securityTraceConfig.getTimeout().getResponse()
|
||||
);
|
||||
|
||||
log.debug("Request configurado: {}", request);
|
||||
|
||||
try {
|
||||
T response = httpClientUseCase.execute(request);
|
||||
|
||||
@ -65,4 +81,59 @@ public class SecurityTraceClient implements SecurityTraceUseCase {
|
||||
throw HttpStatusCodeException.serviceUnavailable("503");
|
||||
}
|
||||
}
|
||||
|
||||
private SecurityTraceRequest getRequest(
|
||||
ServiceIssuePaymentStatusRequest apiRequest,
|
||||
Response apiResponse,
|
||||
long startTime,
|
||||
long endTime
|
||||
) {
|
||||
long executedTime = (endTime - startTime);
|
||||
int statusHttp = apiResponse.getStatus();
|
||||
ApiResponse<?> apiResponseData = (ApiResponse<?>) apiResponse.getEntity();
|
||||
|
||||
return SecurityTraceRequest.builder()
|
||||
.sp(securityTraceConfig.getRequest().getSp())
|
||||
.codBan(securityTraceConfig.getRequest().getCodBan())
|
||||
.codMon(securityTraceConfig.getRequest().getCodMon())
|
||||
.codEve(securityTraceConfig.getRequest().getCodEve())
|
||||
.codEve2(securityTraceConfig.getRequest().getCodEve2())
|
||||
.login(apiRequest.getChannelCode())
|
||||
.fecHor(new Date())
|
||||
.nacCli("")
|
||||
.cedRifCli(0)
|
||||
.objeto(
|
||||
restClientConfig.toJsonString(SecurityTraceObject.builder()
|
||||
.RQ(apiRequest)
|
||||
.RS(apiResponseData)
|
||||
.build())
|
||||
)
|
||||
.tipoRespuesta(statusHttp)
|
||||
.msgRespuesta(getStatusMessage(apiResponseData, statusHttp))
|
||||
.tiempoRespuesta(executedTime)
|
||||
.codFintech(apiRequest.getCustomerReferenceFintechId())
|
||||
.nombreFintech(apiRequest.getChannelCode())
|
||||
.tipoDispositivo(apiRequest.getDevice().getDeviceType())
|
||||
.desDispositivo(apiRequest.getDevice().getDeviceDescription())
|
||||
.ipCli(apiRequest.getDevice().getDeviceIp())
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getStatusMessage(
|
||||
ApiResponse<?> apiResponseData,
|
||||
int statusHttp
|
||||
) {
|
||||
if (apiResponseData != null && apiResponseData.getStatusResponse() != null) {
|
||||
String statusCode = apiResponseData.getStatusResponse().getStatusCode();
|
||||
String message = apiResponseData.getStatusResponse().getMessage();
|
||||
|
||||
if(StringUtil.isNullOrEmpty(statusCode)) {
|
||||
statusCode = String.valueOf(statusHttp);
|
||||
}
|
||||
|
||||
return statusCode + "-" + message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,7 @@ import com.banesco.module.service_status.domain.dto.request.ServiceStatusRequest
|
||||
import com.banesco.module.service_status.domain.dto.response.ServiceStatusResponse;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -42,38 +43,38 @@ public class ServiceIssuePaymentStatusService implements ServiceIssuePaymentStat
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<ServiceIssuePaymentStatusResponse> execute(
|
||||
public Response execute(
|
||||
ServiceIssuePaymentStatusRequest request
|
||||
) {
|
||||
log.info("Iniciando ejecucion para la transaccion: {}", request.getId());
|
||||
|
||||
if(!isServiceStatusActive(request)) {
|
||||
log.info("Estatus del servicio no disponible: {}", request.getId());
|
||||
throw HttpStatusCodeException.serviceUnavailable("VRN04");
|
||||
}
|
||||
Response response = null;
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
ApiResponse<ServiceIssuePaymentStatusResponse> response = domain(request);
|
||||
|
||||
if (
|
||||
!Objects.isNull(response.getData()) &&
|
||||
messageHelper.isSuccessStatusCode(response.getStatusResponse())
|
||||
) {
|
||||
return new ApiResponse<>(response.getData(), messageHelper.createStatusResponse(
|
||||
response.getStatusResponse().getStatusCode()
|
||||
));
|
||||
if(!isServiceStatusActive(request)) {
|
||||
log.info("Estatus del servicio no disponible: {}", request.getId());
|
||||
throw HttpStatusCodeException.serviceUnavailable("VRN04");
|
||||
}
|
||||
|
||||
throw HttpStatusCodeException.serviceUnavailable("503");
|
||||
ApiResponse<ServiceIssuePaymentStatusResponse> apiResponse = domain(request);
|
||||
|
||||
response = messageHelper.handleSuccess(
|
||||
apiResponse.getData(),
|
||||
apiResponse.getStatusResponse().getStatusCode()
|
||||
);
|
||||
} catch (HttpStatusCodeException e) {
|
||||
log.error("Excepcion HTTP del api de dominio: {} - {}", e.getStatusCode(), e.getErrorCode());
|
||||
throw e;
|
||||
response = messageHelper.handleException(e);
|
||||
} catch (Exception e) {
|
||||
log.error("Excepcion generica del api de dominio: {}", e.getMessage());
|
||||
throw e;
|
||||
response = messageHelper.handleGenericException(e);
|
||||
} finally {
|
||||
securityTrace();
|
||||
long endTime = System.currentTimeMillis();
|
||||
securityTrace(request, response, startTime, endTime);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private ApiResponse<ServiceIssuePaymentStatusResponse> domain(
|
||||
@ -116,8 +117,28 @@ public class ServiceIssuePaymentStatusService implements ServiceIssuePaymentStat
|
||||
return isServiceActive;
|
||||
}
|
||||
|
||||
private void securityTrace() {
|
||||
private void securityTrace(
|
||||
ServiceIssuePaymentStatusRequest request,
|
||||
Response response,
|
||||
long startTime,
|
||||
long endTime
|
||||
) {
|
||||
log.info("Ejecutando llamada al api de la traza de seguridad");
|
||||
securityTraceUseCase.execute(SecurityTraceResponse.class);
|
||||
|
||||
try {
|
||||
securityTraceUseCase.execute(
|
||||
request, response,
|
||||
startTime, endTime,
|
||||
SecurityTraceResponse.class
|
||||
);
|
||||
} catch (HttpStatusCodeException e) {
|
||||
log.info(
|
||||
"Error HTTP al ejecutar la traza de seguridad: {} -> {}",
|
||||
e.getStatusCode(),
|
||||
e.getMessage()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.info("Error al ejecutar la traza de seguridad: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,10 @@
|
||||
package com.banesco.module.service_issue_payment_status.application.usecase;
|
||||
|
||||
import com.banesco.common.domain.model.ApiResponse;
|
||||
import com.banesco.module.service_issue_payment_status.domain.dto.request.ServiceIssuePaymentStatusRequest;
|
||||
import com.banesco.module.service_issue_payment_status.domain.dto.response.ServiceIssuePaymentStatusResponse;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
public interface ServiceIssuePaymentStatusUseCase {
|
||||
ApiResponse<ServiceIssuePaymentStatusResponse> execute(
|
||||
Response execute(
|
||||
ServiceIssuePaymentStatusRequest request
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
package com.banesco.module.service_issue_payment_status.domain.dto.request;
|
||||
|
||||
import com.banesco.common.domain.model.Device;
|
||||
import com.banesco.common.infrastructure.context.RequestContext;
|
||||
import com.banesco.module.instruction.domain.model.Instruction;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
|
||||
@ -22,23 +26,43 @@ public class ServiceIssuePaymentStatusRequest {
|
||||
private String appId;
|
||||
@NonNull
|
||||
private Instruction procedureRequest;
|
||||
@NonNull
|
||||
private Device device;
|
||||
|
||||
@JsonIgnore
|
||||
public String getId() {
|
||||
return getProcedureRequest().getInstructionIdentifier().getIdentification().getIdentifierValue();
|
||||
return procedureRequest
|
||||
.getInstructionIdentifier()
|
||||
.getIdentification()
|
||||
.getIdentifierValue();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getChannelCode() {
|
||||
return getProcedureRequest().getInstructionPurposeType().name();
|
||||
return procedureRequest
|
||||
.getInstructionPurposeType();
|
||||
}
|
||||
|
||||
public String getSignatureIdentifier() {
|
||||
return getProcedureRequest().getInstructionDescription();
|
||||
@JsonIgnore
|
||||
public Map<String, String> toParams() {
|
||||
return Map.ofEntries(
|
||||
entry("paymentStatusId", Objects.toString(getId(), "")),
|
||||
entry("channelCode", Objects.toString(getChannelCode(), ""))
|
||||
);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Map<String, String> toQueryString() {
|
||||
return Map.ofEntries(
|
||||
entry("appId", Objects.toString(getAppId(), "")),
|
||||
entry("customerReferenceFintechId", Objects.toString(getCustomerReferenceFintechId(), ""))
|
||||
entry("customerReferenceFintechId", Objects.toString(getCustomerReferenceFintechId(), "")),
|
||||
entry("deviceType", Objects.toString(getDevice().getDeviceType(), "")),
|
||||
entry("deviceDescription", Objects.toString(getDevice().getDeviceDescription(), "")),
|
||||
entry("deviceIp", Objects.toString(getDevice().getDeviceIp(), "")),
|
||||
entry("deviceSessionReference", (!StringUtil.isNullOrEmpty(getDevice().getDeviceSessionReference()))
|
||||
? getDevice().getDeviceSessionReference()
|
||||
: RequestContext.getRequestId()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -13,8 +13,6 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
public class DomServiceIssuePaymentStatusClient implements DomainUseCase {
|
||||
@ -37,27 +35,20 @@ public class DomServiceIssuePaymentStatusClient implements DomainUseCase {
|
||||
Class<T> responseType
|
||||
) {
|
||||
String paymentStatusId = params.getId();
|
||||
String channelCode = params.getChannelCode();
|
||||
String signatureIdentifier = params.getSignatureIdentifier();
|
||||
HttpRequest request = HttpRequest.builder()
|
||||
.url(domainConfig.getUrl())
|
||||
.method(HttpRequest.HttpMethod.GET)
|
||||
.pathParams(Map.of(
|
||||
"paymentStatusId", paymentStatusId,
|
||||
"channelCode", channelCode,
|
||||
"signatureIdentifier", signatureIdentifier
|
||||
))
|
||||
.queryParams(params.toQueryString())
|
||||
.responseType(ApiResponse.class)
|
||||
.genericType(responseType)
|
||||
.connectTimeout(domainConfig.getTimeout().getConnect())
|
||||
.readTimeout(domainConfig.getTimeout().getResponse())
|
||||
.build();
|
||||
|
||||
log.debug("Request configurado: {}", request);
|
||||
HttpRequest request = HttpRequest.forApiResponse(
|
||||
domainConfig.getUrl(),
|
||||
HttpRequest.HttpMethod.GET,
|
||||
responseType
|
||||
)
|
||||
.withPathParams(params.toParams())
|
||||
.withQueryParams(params.toQueryString())
|
||||
.withTimeout(
|
||||
domainConfig.getTimeout().getConnect(),
|
||||
domainConfig.getTimeout().getResponse()
|
||||
);
|
||||
|
||||
try {
|
||||
ApiResponse<T> response = httpClientUseCase.execute(request);
|
||||
ApiResponse<T> response = httpClientUseCase.executeApiResponse(request);
|
||||
|
||||
log.info(
|
||||
"Solicitud del api de dominio exitoso: {}",
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package com.banesco.module.service_issue_payment_status.infrastructure.resource;
|
||||
|
||||
import com.banesco.common.application.helper.MessageHelper;
|
||||
import com.banesco.common.domain.exception.HttpStatusCodeException;
|
||||
import com.banesco.common.domain.model.ApiResponse;
|
||||
import com.banesco.common.domain.model.Device;
|
||||
import com.banesco.common.domain.model.StatusResponse;
|
||||
import com.banesco.module.instruction.domain.model.Instruction;
|
||||
import com.banesco.module.service_issue_payment_status.application.usecase.ServiceIssuePaymentStatusUseCase;
|
||||
@ -31,19 +31,17 @@ import java.util.Objects;
|
||||
public class ServiceIssuePaymentStatusResource {
|
||||
|
||||
private final ServiceIssuePaymentStatusUseCase useCase;
|
||||
private final MessageHelper messageHelper;
|
||||
|
||||
@Inject
|
||||
public ServiceIssuePaymentStatusResource(
|
||||
MessageHelper messageHelper,
|
||||
ServiceIssuePaymentStatusUseCase useCase
|
||||
) {
|
||||
this.messageHelper = messageHelper;
|
||||
this.useCase = useCase;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/retrieve/{paymentStatusId}/{channelCode}/{signatureIdentifier}")
|
||||
@Path("/retrieve/{paymentStatusId}/{channelCode}")
|
||||
@Operation(
|
||||
summary = "Recuperar informacion de la transaccion",
|
||||
description = "Consulta de una trasanccion de pago por id de archivo"
|
||||
@ -312,34 +310,48 @@ public class ServiceIssuePaymentStatusResource {
|
||||
@Parameter(description = "Codigo del canal (BOL, BOLE)", required = true, example = "BOLE")
|
||||
String channelCode,
|
||||
|
||||
@PathParam("signatureIdentifier")
|
||||
@Parameter(description = "Firma del archivo", required = true, example = "add7c6375b8659a798a998258fb049b98119ea97d8116b95e1ee00cc9ffafa84")
|
||||
String signatureIdentifier,
|
||||
|
||||
@QueryParam("customerReferenceFintechId")
|
||||
@Parameter(description = "ID de la fintech", example = "pranical-test")
|
||||
String customerReferenceFintechId,
|
||||
|
||||
@QueryParam("appId")
|
||||
@Parameter(description = "ID de la aplicacion", example = "DANIAPP")
|
||||
String appId
|
||||
String appId,
|
||||
|
||||
@QueryParam("deviceType")
|
||||
@Parameter(description = "Tipo de dispositivo", example = "Mobile")
|
||||
String deviceType,
|
||||
|
||||
@QueryParam("deviceDescription")
|
||||
@Parameter(description = "Descripcion del dispositivo", example = "Xiaomi Note 11 PRO")
|
||||
String deviceDescription,
|
||||
|
||||
@QueryParam("deviceIp")
|
||||
@Parameter(description = "Direccion IP del dispositivo", example = "127.0.0.1")
|
||||
String deviceIp,
|
||||
|
||||
@QueryParam("deviceSessionReference")
|
||||
@Parameter(description = "Referencia de la peticion del dispositivo", example = "12345678901304")
|
||||
String deviceSessionReference
|
||||
) {
|
||||
log.info("Iniciando consulta para instruccion de archivo id: {}", paymentStatusId);
|
||||
|
||||
try {
|
||||
return Response.ok(useCase.execute(
|
||||
ServiceIssuePaymentStatusRequest.builder()
|
||||
.customerReferenceFintechId(Objects.toString(customerReferenceFintechId, ""))
|
||||
.appId(Objects.toString(appId, ""))
|
||||
.procedureRequest(Instruction.fromResource(
|
||||
paymentStatusId, channelCode, signatureIdentifier
|
||||
))
|
||||
.build()
|
||||
)).build();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
return messageHelper.handleException(e);
|
||||
} catch (Exception e) {
|
||||
return messageHelper.handleGenericException(e);
|
||||
}
|
||||
return useCase.execute(
|
||||
ServiceIssuePaymentStatusRequest.builder()
|
||||
.customerReferenceFintechId(Objects.toString(customerReferenceFintechId, ""))
|
||||
.appId(Objects.toString(appId, ""))
|
||||
.procedureRequest(Instruction.fromResource(
|
||||
paymentStatusId, channelCode
|
||||
))
|
||||
.device(
|
||||
Device.builder()
|
||||
.deviceType(deviceType)
|
||||
.deviceDescription(deviceDescription)
|
||||
.deviceIp(deviceIp)
|
||||
.deviceSessionReference(deviceSessionReference)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -48,8 +48,6 @@ public class ServiceStatusClient implements ServiceStatusUseCase {
|
||||
serviceStatusConfig.getTimeout().getResponse()
|
||||
);
|
||||
|
||||
log.debug("Request configurado: {}", request);
|
||||
|
||||
try {
|
||||
T response = httpClientUseCase.execute(request);
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ public enum TransactionStatusType {
|
||||
EXECUTED,
|
||||
CANCELLED,
|
||||
CONFIRMED,
|
||||
APPROVED,
|
||||
SUSPENDED,
|
||||
PENDING,
|
||||
COMPLETED,
|
||||
@ -15,4 +16,9 @@ public enum TransactionStatusType {
|
||||
REJECTED,
|
||||
EXPIRED,
|
||||
SENT,
|
||||
RECEIVED,
|
||||
ACTIVE,
|
||||
READ,
|
||||
PROGRAMED,
|
||||
ATYPICAL_TRANSACTION,
|
||||
}
|
||||
|
||||
@ -8,15 +8,13 @@ quarkus:
|
||||
|
||||
api:
|
||||
source-id: BSIPS
|
||||
allowed:
|
||||
app-id: '[{"appId":"DANIAPP","request":{"serviceType":"P2P","limitType":"REC","casheaIndicator":"NO"}}]'
|
||||
read-messages:
|
||||
from-props: true
|
||||
bus-service-issue-payment-status:
|
||||
messages:
|
||||
key: 'bus-service-issue-payment-status'
|
||||
content: '[{"backendCode":"200","httpCode":200,"statusCode":"200","description":"Operacion exitosa"},{"backendCode":"R404","httpCode":404,"statusCode":"404","description":"Datos de validacion no encontrado."},{"backendCode":"503","httpCode":503,"statusCode":"503","description":"Uso interno"},{"backendCode":"422","httpCode":422,"statusCode":"422","description":"Uso interno"},{"backendCode":"500","httpCode":500,"statusCode":"500","description":"Uso interno"},{"backendCode":"100","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-382505","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-380002","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"ERROR","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"400","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"401","httpCode":401,"statusCode":"401","description":"Uso interno"},{"backendCode":"403","httpCode":403,"statusCode":"403","description":"Uso interno"},{"backendCode":"404","httpCode":404,"statusCode":"404","description":"Uso interno"},{"backendCode":"default","httpCode":409,"statusCode":"409","description":"Conflicto"},{"backendCode":"424","httpCode":424,"statusCode":"424","description":"Error de dependencia"},{"backendCode":"VDE01","httpCode":400,"statusCode":"VDE01","description":"VDE01 - Error en dato de entrada obligatorio: %s"},{"backendCode":"VDE02","httpCode":400,"statusCode":"VDE02","description":"VDE02 - Error en valor permitido para campo: %s"},{"backendCode":"VRN04","httpCode":"503","statusCode":"VRN04","description":"Servicio en horario de mantenimiento","status":"error"},{"backendCode":"204","httpCode":"200","statusCode":"200","description":"Cliente sin productos","status":"ok"}]'
|
||||
content: '[{"backendCode":"200","httpCode":200,"statusCode":"200","description":"Operacion exitosa"},{"backendCode":"R404","httpCode":404,"statusCode":"404","description":"Datos de validacion no encontrado."},{"backendCode":"503","httpCode":503,"statusCode":"503","description":"Uso interno"},{"backendCode":"422","httpCode":422,"statusCode":"422","description":"Uso interno"},{"backendCode":"500","httpCode":500,"statusCode":"500","description":"Uso interno"},{"backendCode":"100","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-382505","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"OSB-380002","httpCode":503,"statusCode":"503","description":"VDR13 - OSB Disponible"},{"backendCode":"ERROR","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"400","httpCode":400,"statusCode":"400","description":"Uso interno"},{"backendCode":"401","httpCode":401,"statusCode":"401","description":"Uso interno"},{"backendCode":"403","httpCode":403,"statusCode":"403","description":"Uso interno"},{"backendCode":"404","httpCode":404,"statusCode":"404","description":"Uso interno"},{"backendCode":"default","httpCode":409,"statusCode":"409","description":"Conflicto"},{"backendCode":"424","httpCode":424,"statusCode":"424","description":"Error de dependencia"},{"backendCode":"VDE01","httpCode":400,"statusCode":"VDE01","description":"VDE01 - Error en dato de entrada obligatorio: %s"},{"backendCode":"VDE02","httpCode":400,"statusCode":"VDE02","description":"VDE02 - Error en valor permitido para campo: %s"},{"backendCode":"VRN04","httpCode":"503","statusCode":"VRN04","description":"Servicio en horario de mantenimiento","status":"error"},{"backendCode":"VRN02","httpCode":"204","statusCode":"VRN02","description":"Cliente sin productos"}]'
|
||||
rest-client:
|
||||
dom-service-issue-payment-status: '{"url":"http://localhost:8083/service-issue-payment-status/retrieve/{paymentStatusId}/{channelCode}/{signatureIdentifier}","timeout":{"connect":10000,"response":10000}}'
|
||||
security-trace: '{"url":"http://api-register-security-route-apis-banesco-dev.apps.desplakur3.desintra.banesco.com/register-security/save","timeout":{"connect":10000,"response":10000},"request":{"sp":"spAPI_Traza","eventCod":"CANCTARJ","bankCod":"01","curCod":"BS"}}'
|
||||
dom-service-issue-payment-status: '{"url":"http://localhost:8083/service-issue-payment-status/retrieve/{paymentStatusId}/{channelCode}","timeout":{"connect":10000,"response":10000}}'
|
||||
security-trace: '{"url":"http://api-register-security-route-apis-banesco-dev.apps.desplakur3.desintra.banesco.com/register-security/save","timeout":{"connect":10000,"response":10000},"request":{"sp":"spAPI_Traza","codEve":"CONSSOLID","codEve2":"CONSSOLID","codBan":"01","codMon":"BS"}}'
|
||||
service-status: '{"url":"http://api-get-service-status-route-apis-banesco-dev.apps.desplakur3.desintra.banesco.com/service/status","timeout":{"connect":10000,"response":10000},"request":{"applicationId": "","transactionId": "","bankService": {"bankCode": "01","serviceCode": "APIFI","eventCode": "P2PVUEL"}}}'
|
||||
Loading…
x
Reference in New Issue
Block a user