TimerGestoreChiaviPDNDUtilities.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.pdd.timers.pdnd;

  21. import org.openspcoop2.pdd.timers.TimerException;
  22. import org.openspcoop2.utils.certificate.remote.RemoteStoreConfig;
  23. import org.openspcoop2.utils.transport.http.ExternalResourceUtils;

  24. /**    
  25.  * TimerGestoreChiaviPDNDUtilities
  26.  *
  27.  * @author Poli Andrea (poli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class TimerGestoreChiaviPDNDUtilities {

  32.     private RemoteStoreConfig remoteStore;
  33.     private String urlCheckEventi;
  34.    
  35.     private String parameterLastEventId;
  36.    
  37.     private String parameterLimit;
  38.     private int limit;
  39.    
  40.     public TimerGestoreChiaviPDNDUtilities(RemoteStoreConfig remoteStore, String urlCheckEventi,
  41.             String parameterLastEventId, String parameterLimit, int limit) {
  42.        
  43.         this.remoteStore = remoteStore;
  44.         this.urlCheckEventi = urlCheckEventi;
  45.        
  46.         this.parameterLastEventId = parameterLastEventId;
  47.        
  48.         this.parameterLimit = parameterLimit;
  49.         this.limit = limit;
  50.     }
  51.    
  52.     public TimerGestoreChiaviPDNDEvents readNextEvents(long lastEventId) throws TimerException {
  53.        
  54.         String responseJson = null;
  55.         try {
  56.        
  57.             StringBuilder sb = new StringBuilder(this.urlCheckEventi).append("?");
  58.             sb.append(this.parameterLastEventId).append("=").append(lastEventId);
  59.             sb.append("&");
  60.             sb.append(this.parameterLimit).append("=").append(this.limit);
  61.            
  62.             String url = sb.toString();
  63.             byte[] response = ExternalResourceUtils.readResource(url, this.remoteStore);
  64.             responseJson = new String(response);
  65.            
  66.         }catch(Exception e) {
  67.             throw new TimerException(e.getMessage(),e);
  68.         }
  69.        
  70.         try {
  71.             return TimerGestoreChiaviPDNDEvents.toEvents(responseJson);
  72.         }catch(Exception e) {
  73.             throw new TimerException("Uncorrect json format ("+responseJson+"): "+e.getMessage(),e);
  74.         }
  75.        
  76.     }
  77.    
  78. }