/*************************************************************************
* *
* SignServer: The OpenSource Automated Signing Server *
* *
* This software is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or any later version. *
* *
* See terms of license at gnu.org. *
* *
*************************************************************************/
package org.signserver.test.random.impl;
import java.io.IOException;
import java.math.BigInteger;
import java.security.cert.Certificate;
import java.util.Random;
import java.util.logging.Level;
import org.apache.log4j.Logger;
import org.bouncycastle.asn1.cmp.PKIStatus;
import org.bouncycastle.tsp.*;
import org.signserver.common.*;
import org.signserver.ejb.interfaces.IWorkerSession;
import org.signserver.test.random.FailedException;
import org.signserver.test.random.Task;
import org.signserver.test.random.WorkerSpec;
/**
* Signs a sample document.
*
* @author Markus KilÄs
* @version $Id: Sign.java 2673 2012-09-19 09:28:48Z netmackan $
*/
public class Sign implements Task {
/** Logger for this class. */
private static final Logger LOG = Logger.getLogger(Sign.class);
private final WorkerSpec signer;
private final IWorkerSession.IRemote workerSession;
private final Random random;
private int counter;
private final RequestContext requestContext = new RequestContext();
private static final String TESTXML1 = "Some sample XML to sign";
public Sign(final WorkerSpec signerId, final IWorkerSession.IRemote workerSession, final Random random) {
this.signer = signerId;
this.workerSession = workerSession;
this.random = random;
}
@Override
public void run() throws FailedException {
LOG.debug(">run");
try {
final int reqid = counter++;
LOG.info("Worker " + signer + " signing: " + counter);
process(signer, reqid);
} catch (IllegalRequestException ex) {
throw new FailedException("Illegal request", ex);
} catch (CryptoTokenOfflineException ex) {
throw new FailedException("Worker offline", ex);
} catch (SignServerException ex) {
throw new FailedException("Generic error", ex);
}
LOG.debug("