From 583630aa62be7f80d1e4904d5237e6836e8cdbe8 Mon Sep 17 00:00:00 2001 From: tkellner Date: Fri, 21 Sep 2012 15:50:48 +0000 Subject: Create (client) & Log (server) STAL error messages git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1136 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../impl/xsect/STALSignatureException.java | 14 ++++++++- .../slcommands/impl/xsect/STALSignatureMethod.java | 3 +- .../egiz/bku/slcommands/impl/xsect/Signature.java | 9 +++--- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 36 +++++++++++----------- .../gv/egiz/bku/smccstal/StatusRequestHandler.java | 4 ++- 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java index 91cfde5d..aa126744 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureException.java @@ -52,10 +52,22 @@ public class STALSignatureException extends SignatureException { * * @param errorCode the error code */ - public STALSignatureException(int errorCode) { + public STALSignatureException(int errorCode) { + super(); this.errorCode = errorCode; } + /** + * Creates a new instance of this STALSigantureException with + * the given errorCode. + * + * @param errorCode the error code + */ + public STALSignatureException(int errorCode, String msg) { + super(msg); + this.errorCode = errorCode; + } + /** * Creates a new instance of this STALSignatureException with * the given error msg. diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java index 44f49031..51c6c805 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/STALSignatureMethod.java @@ -113,7 +113,8 @@ public class STALSignatureMethod extends AbstractSignatureMethodImpl { if (response instanceof SignResponse) { return ((SignResponse) response).getSignatureValue(); } else if (response instanceof ErrorResponse) { - STALSignatureException se = new STALSignatureException(((ErrorResponse) response).getErrorCode()); + ErrorResponse err = (ErrorResponse) response; + STALSignatureException se = new STALSignatureException(err.getErrorCode(), err.getErrorMessage()); throw new XMLSignatureException(se); } else { throw new XMLSignatureException("Failed to access STAL."); diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java index e7f04457..8cc6caf2 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java @@ -434,12 +434,13 @@ public class Signature { Throwable cause = e.getCause(); while (cause != null) { if (cause instanceof STALSignatureException) { - if (((STALSignatureException) cause).getCause() instanceof SLViewerException) { - throw (SLViewerException) ((STALSignatureException) cause).getCause(); + STALSignatureException stalCause = (STALSignatureException) cause; + if (stalCause.getCause() instanceof SLViewerException) { + throw (SLViewerException) stalCause.getCause(); } - int errorCode = ((STALSignatureException) cause).getErrorCode(); + int errorCode = stalCause.getErrorCode(); SLCommandException commandException = new SLCommandException(errorCode); - log.info("Failed to sign signature.", e); + log.info("Failed to sign signature: {}", stalCause.getMessage(), e); throw commandException; } else { cause = cause.getCause(); diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index a6a58806..41ef90a5 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -55,7 +55,7 @@ import at.gv.egiz.stal.signedinfo.SignedInfoType; public class SignRequestHandler extends AbstractRequestHandler { - private final Logger log = LoggerFactory.getLogger(SignRequestHandler.class); + private final static Logger log = LoggerFactory.getLogger(SignRequestHandler.class); private static JAXBContext jaxbContext; static { @@ -73,6 +73,14 @@ public class SignRequestHandler extends AbstractRequestHandler { this.secureViewer = secureViewer; } + private ErrorResponse errorResponse(int errorCode, String errorMessage, Exception e) + { + log.error(errorMessage, e); + ErrorResponse err = new ErrorResponse(errorCode); + err.setErrorMessage(errorMessage + (e == null ? "" : " " + e)); + return err; + } + @SuppressWarnings("unchecked") @Override public STALResponse handleRequest(STALRequest request) throws InterruptedException { @@ -89,50 +97,42 @@ public class SignRequestHandler extends AbstractRequestHandler { byte[] resp = card.createSignature(new ByteArrayInputStream(signReq.getSignedInfo()), kb, new SignPINGUI(gui, secureViewer, si.getValue()), signatureMethod); if (resp == null) { - return new ErrorResponse(6001); + return errorResponse(6001, "Response is null", null); } SignResponse stalResp = new SignResponse(); stalResp.setSignatureValue(resp); return stalResp; } catch (NotActivatedException e) { - log.info("Citizen card not activated.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); waitForAction(); gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, BKUGUIFacade.MESSAGE_WAIT); - return new ErrorResponse(6001); + return errorResponse(6001, "Citizen card not activated.", e); } catch (LockedException e) { - log.info("Citizen card locked.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_LOCKED, null, this, null); waitForAction(); gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, BKUGUIFacade.MESSAGE_WAIT); - return new ErrorResponse(6001); + return errorResponse(6001, "Citizen card locked.", e); } catch (CancelledException cx) { - log.debug("User cancelled request."); - return new ErrorResponse(6001); + return errorResponse(6001, "User cancelled request.", null); } catch (TimeoutException ex) { - log.error("Timeout during pin entry"); gui.showMessageDialog(BKUGUIFacade.TITLE_ENTRY_TIMEOUT, BKUGUIFacade.ERR_PIN_TIMEOUT, null, BKUGUIFacade.BUTTON_CANCEL, this, null); waitForAction(); gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, BKUGUIFacade.MESSAGE_WAIT); - return new ErrorResponse(6001); + return errorResponse(6001, "Timeout during pin entry.", null); } catch (SignatureCardException e) { - log.error("Error while creating signature: " + e); - return new ErrorResponse(4000); + return errorResponse(4000,"Error while creating signature.", e); } catch (JAXBException e) { - log.error("Cannot unmarshall signed info.", e); - return new ErrorResponse(1000); + return errorResponse(1000, "Cannot unmarshall signed info.", e); } catch (IOException e) { - log.error("Error while creating signature: " + e); - return new ErrorResponse(4000); + return errorResponse(4000, "Error while creating signature.", e); } } else { - log.error("Got unexpected STAL request: {}.", request); - return new ErrorResponse(1000); + return errorResponse(1000, "Got unexpected STAL request: " + request + ".", null); } } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java index 706774e4..86711ca4 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/StatusRequestHandler.java @@ -69,7 +69,9 @@ public class StatusRequestHandler extends AbstractRequestHandler { return response; } else { log.error("Got unexpected STAL request: {}.", request); - return new ErrorResponse(1000); + ErrorResponse err = new ErrorResponse(1000); + err.setErrorMessage("Got unexpected STAL request: " + request); + return err; } } -- cgit v1.2.3