/************************************************************************* * * * 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.validationservice.server; import java.util.LinkedList; import java.util.List; import javax.persistence.EntityManager; import org.apache.log4j.Logger; import org.signserver.common.*; import org.signserver.server.BaseProcessable; import org.signserver.server.WorkerContext; import org.signserver.validationservice.common.ValidateRequest; import org.signserver.validationservice.common.ValidationServiceConstants; /** * Class acting as middle-ware transforming an ISigner to * a IValidationService. * * @author Philip Vendil 16 nov 2007 * @version $Id: ValidationServiceWorker.java 3497 2013-05-22 12:06:32Z malu9369 $ */ public class ValidationServiceWorker extends BaseProcessable { /** Logger for this class. */ private static final Logger LOG = Logger.getLogger(ValidationServiceWorker.class); private IValidationService validationService; private List fatalErrors; /** * Initialization method creating the validation service * @see org.signserver.server.BaseWorker#init(int, org.signserver.common.WorkerConfig, javax.persistence.EntityManager) */ @Override public void init(int workerId, WorkerConfig config, WorkerContext workerContext, EntityManager workerEntityManager) { super.init(workerId, config, workerContext, workerEntityManager); fatalErrors = new LinkedList(); try { validationService = createValidationService(config); } catch (SignServerException e) { final String error = "Could not get crypto token: " + e.getMessage(); LOG.error(error); fatalErrors.add(error); } } /** * Creating a Validation Service depending on the TYPE setting * @param config configuration containing the validation service to create * @return a non initialized group key service. */ private IValidationService createValidationService(WorkerConfig config) throws SignServerException { String classPath = config.getProperties().getProperty(ValidationServiceConstants.VALIDATIONSERVICE_TYPE, ValidationServiceConstants.DEFAULT_TYPE); IValidationService retval = null; String error = null; try { if (classPath != null) { Class implClass = Class.forName(classPath); retval = (IValidationService) implClass.newInstance(); retval.init(workerId, config, em, getCryptoToken()); } } catch (ClassNotFoundException e) { error = "Error instatiating Validation Service, check that the TYPE setting of workerid : " + workerId + " have the correct class path."; LOG.error(error, e); } catch (IllegalAccessException e) { error = "Error instatiating Validation Service, check that the TYPE setting of workerid : " + workerId + " have the correct class path."; LOG.error(error, e); } catch (InstantiationException e) { error = "Error instatiating Validation Service, check that the TYPE setting of workerid : " + workerId + " have the correct class path."; LOG.error(error, e); } if (error != null) { fatalErrors.add(error); } return retval; } /** * Main method of the container calling the appropriate method * of the ValidationService depending on the type of request. * * @see org.signserver.server.IProcessable#processData(org.signserver.common.ProcessRequest, org.signserver.common.RequestContext) */ @Override public ProcessResponse processData(ProcessRequest processRequest, RequestContext requestContext) throws IllegalRequestException, CryptoTokenOfflineException, SignServerException { System.out.println("Hello"); final ISignRequest sReq = (ISignRequest) processRequest; return new GenericSignResponse(sReq.getRequestID(), "abc", 212, "Contract is locked or invalid"); /* if (processRequest instanceof ValidateRequest) { return validationService.validate((ValidateRequest) processRequest); } else { throw new IllegalRequestException("The process request sent to validation service with id " + workerId + " isn't supported"); } */ } /** * @see org.signserver.server.BaseProcessable#getStatus() */ @Override public WorkerStatus getStatus(final List additionalFatalErrors) { return validationService.getStatus(); } @Override protected List getFatalErrors() { final List errors = new LinkedList(); errors.addAll(super.getFatalErrors()); errors.addAll(fatalErrors); return errors; } }