Skip to content

Commit

Permalink
DSS-2549 : log exception stacktrace
Browse files Browse the repository at this point in the history
(cherry picked from commit 3cc40ed)
  • Loading branch information
bsanchezb committed Aug 16, 2021
1 parent 8bfd5b0 commit 3e052d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import eu.europa.esig.dss.validation.SignedDocumentValidator;
import eu.europa.esig.dss.web.WebAppUtils;
import eu.europa.esig.dss.web.editor.EnumPropertyEditor;
import eu.europa.esig.dss.web.exception.ApplicationJsonRequestException;
import eu.europa.esig.dss.web.exception.SignatureOperationException;
import eu.europa.esig.dss.web.model.CounterSignatureForm;
import eu.europa.esig.dss.web.model.CounterSignatureHelperResponse;
import eu.europa.esig.dss.web.model.DataToSignParams;
Expand Down Expand Up @@ -204,7 +204,7 @@ public CounterSignatureHelperResponse getSignatureIds(@RequestParam("documentToC
throw new DSSException("The uploaded file does not contain signatures.");

} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.europa.esig.dss.web.controller;

import eu.europa.esig.dss.model.DSSException;
import eu.europa.esig.dss.web.exception.ApplicationJsonRequestException;
import eu.europa.esig.dss.web.exception.SignatureOperationException;
import eu.europa.esig.dss.web.exception.InternalServerException;
import eu.europa.esig.dss.web.exception.SourceNotFoundException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -83,13 +83,11 @@ private ModelAndView getMAV(HttpServletRequest req, Exception e, HttpStatus stat
mav.setViewName(viewName);
return mav;
}

@ExceptionHandler(ApplicationJsonRequestException.class)
public ResponseEntity<String> ApplicationJsonRequestExceptionHandler(HttpServletRequest req, Exception e) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("An error occurred during a JSON request : uri = '{}', message = '{}'", req.getRequestURI(), e.getMessage());
}
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(SignatureOperationException.class)
public ResponseEntity<String> signatureOperationExceptionHandler(HttpServletRequest req, Exception e) throws Exception {
LOG.error("An error occurred on URI call [{}] : {}", req.getRequestURI(), e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public class ApplicationJsonRequestException extends RuntimeException {
public class SignatureOperationException extends RuntimeException {

private static final long serialVersionUID = -1881926104709953107L;

public ApplicationJsonRequestException(String message) {
super(message);
public SignatureOperationException(String message, Exception e) {
super(message, e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import eu.europa.esig.dss.utils.Utils;
import eu.europa.esig.dss.validation.timestamp.TimestampToken;
import eu.europa.esig.dss.web.WebAppUtils;
import eu.europa.esig.dss.web.exception.ApplicationJsonRequestException;
import eu.europa.esig.dss.web.exception.SignatureOperationException;
import eu.europa.esig.dss.web.model.AbstractSignatureForm;
import eu.europa.esig.dss.web.model.CounterSignatureForm;
import eu.europa.esig.dss.web.model.ExtensionForm;
Expand Down Expand Up @@ -127,7 +127,7 @@ public ToBeSigned getDataToSign(SignatureDocumentForm form) {
LOG.info("End getDataToSign with one document");
return toBeSigned;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -144,7 +144,7 @@ public ToBeSigned getDataToSign(SignatureDigestForm form) {
LOG.info("End getDataToSign with one digest");
return toBeSigned;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -161,7 +161,7 @@ public ToBeSigned getDataToSign(SignatureMultipleDocumentsForm form) {
LOG.info("End getDataToSign with multiple documents");
return toBeSigned;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -179,7 +179,7 @@ public ToBeSigned getDataToSign(SignatureJAdESForm form) {
LOG.info("End getDataToSign with one JAdES");
return toBeSigned;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -199,7 +199,7 @@ public ToBeSigned getDataToCounterSign(CounterSignatureForm form) {
LOG.info("End getDataToSign with one document");
return toBeSigned;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand Down Expand Up @@ -371,7 +371,7 @@ public DSSDocument signDocument(SignatureDocumentForm form) {
LOG.info("End signDocument with one document");
return signedDocument;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -390,7 +390,7 @@ public DSSDocument signDigest(SignatureDigestForm form) {
LOG.info("End signDigest with one digest");
return signedDocument;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -409,7 +409,7 @@ public DSSDocument signDocument(SignatureMultipleDocumentsForm form) {
LOG.info("End signDocument with multiple documents");
return signedDocument;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -429,7 +429,7 @@ public DSSDocument signDocument(SignatureJAdESForm form) {
LOG.info("End signDocument with JAdES");
return signedDocument;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand All @@ -451,7 +451,7 @@ public DSSDocument counterSignSignature(CounterSignatureForm form) {
LOG.info("End signDocument with one document");
return signedDocument;
} catch (Exception e) {
throw new ApplicationJsonRequestException(e.getMessage());
throw new SignatureOperationException(e.getMessage(), e);
}
}

Expand Down

0 comments on commit 3e052d1

Please sign in to comment.