From 54f16e552a3d6c5579282de5c8d6a92395f6c049 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Sat, 13 May 2023 15:18:03 +0200 Subject: refact(core): remove double serialization in central error handling --- .../controller/ProtocolFinalizationController.java | 74 +++++++--------------- 1 file changed, 24 insertions(+), 50 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java index a0ac57d1..099aa180 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java @@ -29,7 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.util.SerializationUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -85,32 +84,23 @@ public class ProtocolFinalizationController extends AbstractController { log.debug("Searching exception with internal error-token: {}", errorId); // load stored exception from database - final byte[] containerSerialized = transactionStorage.get(errorId, byte[].class); - if (containerSerialized != null) { + final ExceptionContainer container = transactionStorage.get(errorId, ExceptionContainer.class); + if (container != null) { // remove exception if it was found transactionStorage.remove(errorId); log.trace("Find exception with internal error-token: {}", errorId); - //final Object containerObj = EaafSerializationUtils.deserialize(containerSerialized, - // Arrays.asList( - // ExceptionContainer.class.getName() - // )); - final Object containerObj = SerializationUtils.deserialize(containerSerialized); - - if (containerObj instanceof ExceptionContainer) { - final ExceptionContainer container = (ExceptionContainer) containerObj; - final Throwable throwable = container.getExceptionThrown(); - pendingReq = container.getPendingRequest(); - - if (pendingReq != null) { - IModulInfo handlingModule = ProtocolAuthenticationService - .extractShibbolethHandling(pendingReq, applicationContext); - if (!handlingModule.generateErrorMessage(throwable, req, resp, pendingReq)) { - protAuthService.handleErrorNoRedirect(new EaafException("process.90", null), req, resp, false); - - } + final Throwable throwable = container.getExceptionThrown(); + pendingReq = container.getPendingRequest(); + + if (pendingReq != null) { + IModulInfo handlingModule = ProtocolAuthenticationService + .extractShibbolethHandling(pendingReq, applicationContext); + if (!handlingModule.generateErrorMessage(throwable, req, resp, pendingReq)) { + protAuthService.handleErrorNoRedirect(new EaafException("process.90", null), req, resp, false); + } - } + } } else { log.info("Find no exception with internal error-token: {}", errorId); protAuthService @@ -162,45 +152,29 @@ public class ProtocolFinalizationController extends AbstractController { log.debug("Searching exception with internal error-token: {}", errorId); // load stored exception from database - final byte[] containerSerialized = transactionStorage.get(errorId, byte[].class); - if (containerSerialized != null) { + final ExceptionContainer container = transactionStorage.get(errorId, ExceptionContainer.class); + if (container != null) { // remove exception if it was found transactionStorage.remove(errorId); log.trace("Find exception with internal error-token: {}", errorId); - //final Object containerObj = EaafSerializationUtils.deserialize(containerSerialized, - // Arrays.asList( - // ExceptionContainer.class.getName() - // )); - final Object containerObj = SerializationUtils.deserialize(containerSerialized); - - if (containerObj instanceof ExceptionContainer) { - final ExceptionContainer container = (ExceptionContainer) containerObj; - final Throwable throwable = container.getExceptionThrown(); - pendingReq = container.getPendingRequest(); + final Throwable throwable = container.getExceptionThrown(); + pendingReq = container.getPendingRequest(); - if (pendingReq != null) { - //set MDC variables - TransactionIdUtils.setAllLoggingVariables(pendingReq); + if (pendingReq != null) { + // set MDC variables + TransactionIdUtils.setAllLoggingVariables(pendingReq); - // build protocol-specific error message if possible - protAuthService.buildProtocolSpecificErrorResponse(throwable, req, resp, pendingReq); + // build protocol-specific error message if possible + protAuthService.buildProtocolSpecificErrorResponse(throwable, req, resp, pendingReq); - // remove active user-session - transactionStorage.remove(pendingReq.getPendingRequestId()); - - } else { - protAuthService.handleErrorNoRedirect(throwable, req, resp, true); - - } + // remove active user-session + transactionStorage.remove(pendingReq.getPendingRequestId()); } else { - protAuthService - .handleErrorNoRedirect(new EaafException(IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC, null), req, - resp, false); + protAuthService.handleErrorNoRedirect(throwable, req, resp, true); } - } else { log.info("Find no exception with internal error-token: {}", errorId); protAuthService -- cgit v1.2.3