本文整理汇总了Java中ee.sk.digidoc.DigiDocException类的典型用法代码示例。如果您正苦于以下问题:Java DigiDocException类的具体用法?Java DigiDocException怎么用?Java DigiDocException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DigiDocException类属于ee.sk.digidoc包,在下文中一共展示了DigiDocException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeDataFile
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
private void removeDataFile(File file) {
logger.info("Removing data file: " + file.getName());
int index = -1;
ArrayList ddocDataFiles = ddoc.getDataFiles();
for (int i = 0; i < ddocDataFiles.size(); i++) {
ee.sk.digidoc.DataFile dataFile = (ee.sk.digidoc.DataFile) ddocDataFiles.get(i);
if (dataFile.getFileName().equalsIgnoreCase(file.getName())) index = i;
}
if (index == -1) {
DigiDoc4JException exception = new DigiDoc4JException("File not found");
logger.error(exception.toString());
throw exception;
}
try {
ddoc.removeDataFile(index);
} catch (DigiDocException e) {
logger.error(e.getMessage());
throw new DigiDoc4JException(e.getNestedException());
}
}
示例2: signRaw
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
public Signature signRaw(byte[] rawSignature) {
logger.info("Finalizing DDoc signature");
try {
ddocSignature.setSignatureValue(rawSignature);
DDocSignature signature = new DDocSignature(ddocSignature);
if (signatureProfile == SignatureProfile.LT_TM) {
ddocSignature.getConfirmation();
}
signature.setIndexInArray(getSignatureIndexInArray());
logger.info("Signing DDoc successfully completed");
return signature;
} catch (DigiDocException e) {
logger.error(e.getMessage());
throw new DigiDoc4JException(e.getNestedException());
}
}
示例3: generateReport
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
private void generateReport(DigiDocException exception, boolean isError) {
Element childElement;
String warningOrError;
String message = exception.getMessage();
int code = exception.getCode();
if(!isError){
warningOrError = "warning";
}else{
DigiDoc4JException digiDoc4JException = new DigiDoc4JException(code, message);
errors.add(digiDoc4JException);
warningOrError = "error";
}
logger.debug("Validation " + warningOrError + "."+ " Code: " + code + ", message: " + message);
childElement = report.createElement(warningOrError);
childElement.setAttribute("Code", Integer.toString(code));
childElement.setAttribute("Message", message);
rootElement.appendChild(childElement);
}
示例4: testReport
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
@Test
public void testReport() throws IOException, SAXException {
ArrayList<DigiDocException> exceptions = new ArrayList<DigiDocException>();
exceptions.add(new DigiDocException(DigiDocException.ERR_UNSUPPORTED, "test", new Throwable("exception1")));
exceptions.add(new DigiDocException(DigiDocException.ERR_CALCULATE_DIGEST, "test2", new Throwable("exception2")));
exceptions.add(new DigiDocException(DigiDocException.ERR_OLD_VER, "test", new Throwable("exception1")));
exceptions.add(new DigiDocException(DigiDocException.WARN_WEAK_DIGEST, "test2", new Throwable("exception2")));
ValidationResultForDDoc result = new ValidationResultForDDoc(exceptions);
assertXMLEqual("<?xml version=\"1.0\" encoding=\"UTF-16\"?>" +
"<!--DDoc verification result-->" +
"<root>" +
"<error Code=\"15\" Message=\"15test; nested exception is: 	java.lang.Throwable: exception1\"/>" +
"<error Code=\"54\" Message=\"54test2; nested exception is: 	java.lang.Throwable: " +
"exception2\"/><error " +
"Code=\"177\" Message=\"177test; nested exception is: 	java.lang.Throwable: " +
"exception1\"/><error " +
"Code=\"129\" Message=\"129test2; nested exception is: 	java.lang.Throwable: exception2\"/></root>",
result.getReport());
System.out.println();
}
示例5: removeDataFileThrowsException
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
@Test(expected = DigiDoc4JException.class)
public void removeDataFileThrowsException() throws Exception {
SignedDoc ddoc = mock(SignedDoc.class);
ArrayList<ee.sk.digidoc.DataFile> mockedDataFiles = new ArrayList<>();
DataFile dataFile = mock(DataFile.class);
when(dataFile.getFileName()).thenReturn("test.txt");
mockedDataFiles.add(dataFile);
doReturn(mockedDataFiles).when(ddoc).getDataFiles();
doThrow(new DigiDocException(100, "testException", new Throwable("test Exception"))).
when(ddoc).removeDataFile(anyInt());
DDocFacade container = new DDocFacade(ddoc);
container.addDataFile("testFiles/helper-files/test.txt", "text/plain");
container.removeDataFile("test.txt");
}
示例6: findAlias
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
private String findAlias(KeyStore store) throws DigiDocException {
try {
java.util.Enumeration en = store.aliases();
// find the key alias
while(en.hasMoreElements()) {
String n = (String)en.nextElement();
if (store.isKeyEntry(n)) {
return n;
}
}
return null;
} catch(Exception ex) {
DigiDocException.handleException(ex, DigiDocException.ERR_NOT_FAC_INIT);
return null;
}
}
示例7: finalizeSignature
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
public void finalizeSignature(IdSignSession signSession, String signatureValue, String userId, String fileId, Credential credential) throws IOException {
// SignatureContainerDescription description = signatureContainerDescriptionRepository.get(userId);
SignatureContainerDescription description = signatureContainerDescriptionRepository.get("master");
DigidocOCSPSignatureContainer digidocOCSPSignatureContainer = new DigidocOCSPSignatureContainer(
signatureContainerDescriptionRepository.getContent(description),
description);
digiDocService.finalizeSignature(
signSession.getSignedDoc(),
signSession.getId(),
signatureValue,
digidocOCSPSignatureContainer);
try {
File file = gDriveService.getFile(fileId, credential);
ByteArrayOutputStream out = new ByteArrayOutputStream();
signSession.getSignedDoc().writeToStream(out);
gDriveService.updateContent(file, out.toByteArray(), credential);
} catch (DigiDocException e) {
throw new RuntimeException(e);
}
}
示例8: parseSignedDoc
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
/**
* @throws IllegalArgumentException if content is not DDoc
* @param content
* @return
* @throws IOException
*/
public ValidatedSignedDoc parseSignedDoc(String fileName, String id, InputStream content) throws IOException {
ArrayList<DigiDocException> warnings = new ArrayList<DigiDocException>();
try {
DigiDocFactory factory = ConfigManager.instance().getDigiDocFactory();
SignedDoc doc = factory.readSignedDocFromStreamOfType(content, factory.isBdocExtension(fileName), warnings);
if (doc == null) {
throw new IllegalArgumentException("content is not a ddoc/bdoc: " + warnings);
}
return new ValidatedSignedDoc(doc, warnings);
} catch (DigiDocException e) {
throw new RuntimeException(e);
}
}
示例9: requestMobileIdSignature
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
public SignSession requestMobileIdSignature(
SignedDoc doc, String personalId, String phoneNumber) {
try {
StringBuffer challenge = new StringBuffer();
String sessionId = mobileIdService.startSigningSession(
doc,
personalId,
phoneNumber,
"ENG",
"Drive DigiDoc",
"",
"",
"",
"",
"EE",
challenge);
return new SignSession(sessionId, challenge.toString());
} catch (DigiDocException e) {
throw new RuntimeException(e);
}
}
示例10: createContainer
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
public SignedDoc createContainer(String fileName, String mimeType, InputStream content) {
try {
SignedDoc signedDoc = DigiDocGenFactory.createSignedDoc(
SignedDoc.FORMAT_DIGIDOC_XML, null, null);
DataFile dataFile = new DataFile(
signedDoc.getNewDataFileId(),
DataFile.CONTENT_EMBEDDED_BASE64,
fileName,
mimeType,
signedDoc);
byte[] contentBytes = IOUtils.toByteArray(content);
dataFile.setBase64Body(contentBytes);
dataFile.calcHashes(new ByteArrayInputStream(contentBytes));//hack to make DigiDoc save file content
signedDoc.addDataFile(dataFile);
return signedDoc;
} catch (DigiDocException | IOException e) {
throw new RuntimeException(e);
}
}
示例11: isBdocFile
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
/**
* Checks if this stream could be a bdoc input stream
* @param is input stream, must support mark() and reset() operations!
* @return true if bdoc
*/
private boolean isBdocFile(InputStream is)
throws DigiDocException
{
try {
if(is.markSupported())
is.mark(10);
byte[] tdata = new byte[10];
int n = is.read(tdata);
if(is.markSupported())
is.reset();
if(n >= 2 && tdata[0] == (byte)'P' && tdata[1] == (byte)'K')
return true; // probably a zip file
if(n >= 5 && tdata[0] == (byte)'<' && tdata[1] == (byte)'?' &&
tdata[2] == (byte)'x' && tdata[3] == (byte)'m' &&
tdata[4] == (byte)'l')
return false; // an xml file - probably ddoc format?
} catch(Exception ex) {
m_logger.error("Error determining file type: " + ex);
}
return false;
}
示例12: verifyRespStatus
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
/**
* Helper method to verify response status
* @param resp OCSP response
* @throws DigiDocException if the response status is not ok
*/
private void verifyRespStatus(OCSPResp resp)
throws DigiDocException
{
int status = resp.getStatus();
switch (status) {
case OCSPRespStatus.INTERNAL_ERROR: m_logger.error("An internal error occured in the OCSP Server!"); break;
case OCSPRespStatus.MALFORMED_REQUEST: m_logger.error("Your request did not fit the RFC 2560 syntax!"); break;
case OCSPRespStatus.SIGREQUIRED: m_logger.error("Your request was not signed!"); break;
case OCSPRespStatus.TRY_LATER: m_logger.error("The server was too busy to answer you!"); break;
case OCSPRespStatus.UNAUTHORIZED: m_logger.error("The server could not authenticate you!"); break;
case OCSPRespStatus.SUCCESSFUL: break;
default: m_logger.error("Unknown OCSPResponse status code! "+status);
}
if(resp == null || resp.getStatus() != OCSPRespStatus.SUCCESSFUL)
throw new DigiDocException(DigiDocException.ERR_OCSP_UNSUCCESSFULL,
"OCSP response unsuccessfull! ", null);
}
示例13: init
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
/**l
* initializes the implementation class
*/
public void init()
throws DigiDocException
{
try {
String proxyHost = ConfigManager.instance().
getProperty("DIGIDOC_PROXY_HOST");
String proxyPort = ConfigManager.instance().
getProperty("DIGIDOC_PROXY_PORT");
if(proxyHost != null && proxyPort != null) {
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
}
String sigFlag = ConfigManager.instance().getProperty("SIGN_OCSP_REQUESTS");
m_bSignRequests = (sigFlag != null && sigFlag.equals("true"));
// only need this if we must sign the requests
Provider prv = (Provider)Class.forName(ConfigManager.
instance().getProperty("DIGIDOC_SECURITY_PROVIDER")).newInstance();
//System.out.println("Provider");
//prv.list(System.out);
Security.addProvider(prv);
} catch(Exception ex) {
DigiDocException.handleException(ex, DigiDocException.ERR_NOT_FAC_INIT);
}
}
示例14: isWarning
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
/**
* Checks is DigiDoc4JException predefined as warning for DDOC
*
* @param documentFormat format SignedDoc
* @param exception error to check
* @return is this exception warning for DDOC utility program
* @see SignedDoc
*/
public static boolean isWarning(String documentFormat, DigiDoc4JException exception) {
int errorCode = exception.getErrorCode();
return (errorCode == DigiDocException.ERR_DF_INV_HASH_GOOD_ALT_HASH
|| errorCode == DigiDocException.ERR_OLD_VER
|| errorCode == DigiDocException.ERR_TEST_SIGNATURE
|| errorCode == DigiDocException.WARN_WEAK_DIGEST
|| (errorCode == DigiDocException.ERR_ISSUER_XMLNS && !documentFormat.equals(SignedDoc.FORMAT_SK_XML)));
}
示例15: isWarning
import ee.sk.digidoc.DigiDocException; //导入依赖的package包/类
private boolean isWarning(String documentFormat, DigiDoc4JException exception) {
int errorCode = exception.getErrorCode();
return (errorCode == DigiDocException.ERR_DF_INV_HASH_GOOD_ALT_HASH
|| errorCode == DigiDocException.ERR_OLD_VER
|| errorCode == DigiDocException.ERR_TEST_SIGNATURE
|| errorCode == DigiDocException.WARN_WEAK_DIGEST
|| (errorCode == DigiDocException.ERR_ISSUER_XMLNS && !documentFormat.equals(SignedDoc.FORMAT_SK_XML)));
}