PolicyGroupByActiveThreadsWS.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.core.controllo_traffico.policy.driver;

  21. import java.util.HashMap;
  22. import java.util.List;

  23. import org.openspcoop2.core.controllo_traffico.beans.DatiCollezionati;
  24. import org.openspcoop2.core.controllo_traffico.beans.IDUnivocoGroupByPolicy;
  25. import org.openspcoop2.core.controllo_traffico.beans.MisurazioniTransazione;
  26. import org.openspcoop2.core.controllo_traffico.driver.CostantiServizioControlloTraffico;
  27. import org.openspcoop2.core.controllo_traffico.driver.IPolicyGroupByActiveThreads;
  28. import org.openspcoop2.core.controllo_traffico.driver.PolicyException;
  29. import org.openspcoop2.core.controllo_traffico.driver.PolicyNotFoundException;
  30. import org.openspcoop2.utils.Map;
  31. import org.openspcoop2.utils.transport.TransportUtils;
  32. import org.openspcoop2.utils.transport.http.HttpResponse;
  33. import org.openspcoop2.utils.transport.http.HttpUtilities;
  34. import org.slf4j.Logger;

  35. /**    
  36.  * PolicyGroupByActiveThreadsWS
  37.  *
  38.  * @author Poli Andrea (poli@link.it)
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  */
  42. public class PolicyGroupByActiveThreadsWS implements IPolicyGroupByActiveThreads {

  43.     private String uriService;
  44.     private String activeId;
  45.     private Logger log;
  46.    
  47.     public PolicyGroupByActiveThreadsWS(String serviceUrl,String activeId,Logger log){
  48.         this.uriService = serviceUrl;
  49.         this.activeId = activeId;
  50.         this.log = log;
  51.     }
  52.    
  53.     @Override
  54.     public DatiCollezionati registerStartRequest(Logger log, String idTransazione, IDUnivocoGroupByPolicy datiGroupBy, Map<Object> ctx)
  55.             throws PolicyException {
  56.         try{
  57.             java.util.Map<String, List<String>> p = new HashMap<>();
  58.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_ACTIVE_ID, this.activeId);
  59.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_GROUP_BY_ID, IDUnivocoGroupByPolicy.serialize(datiGroupBy));
  60.             String url = TransportUtils.buildUrlWithParameters(p, this.uriService+CostantiServizioControlloTraffico.OPERAZIONE_REGISTER_START_REQUEST, this.log);
  61.            
  62.             this.log.debug("[PolicyGroupByActiveThreadsWS.registerStartRequest] invoke ("+url+") ...");
  63.             HttpResponse response = HttpUtilities.getHTTPResponse(url);
  64.             this.log.debug("[PolicyGroupByActiveThreadsWS.registerStartRequest] invoked with code ["+response.getResultHTTPOperation()+"]");
  65.            
  66.             if(response.getResultHTTPOperation()!=200){
  67.                 throw new Exception("[httpCode:"+response.getResultHTTPOperation()+"] "+new String(response.getContent()));
  68.             }
  69.            
  70.             return DatiCollezionati.deserialize(new String(response.getContent()));
  71.                        
  72.         }catch(Exception e){
  73.             this.log.error("registerStartRequest error: "+e.getMessage(),e);
  74.             throw new PolicyException(e.getMessage(),e);
  75.         }
  76.     }

  77.     @Override
  78.     public DatiCollezionati updateDatiStartRequestApplicabile(Logger log, String idTransazione, IDUnivocoGroupByPolicy datiGroupBy, Map<Object> ctx)
  79.             throws PolicyException, PolicyNotFoundException {
  80.         try{
  81.             java.util.Map<String, List<String>> p = new HashMap<>();
  82.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_ACTIVE_ID, this.activeId);
  83.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_GROUP_BY_ID, IDUnivocoGroupByPolicy.serialize(datiGroupBy));
  84.             String url = TransportUtils.buildUrlWithParameters(p, this.uriService+CostantiServizioControlloTraffico.OPERAZIONE_UPDATE_START_REQUEST, this.log);
  85.            
  86.             this.log.debug("[PolicyGroupByActiveThreadsWS.updateDatiStartRequestApplicabile] invoke ("+url+") ...");
  87.             HttpResponse response = HttpUtilities.getHTTPResponse(url);
  88.             this.log.debug("[PolicyGroupByActiveThreadsWS.updateDatiStartRequestApplicabile] invoked with code ["+response.getResultHTTPOperation()+"]");
  89.            
  90.             if(response.getResultHTTPOperation()!=200){
  91.                 throw new Exception("[httpCode:"+response.getResultHTTPOperation()+"] "+new String(response.getContent()));
  92.             }
  93.            
  94.             return DatiCollezionati.deserialize(new String(response.getContent()));
  95.                        
  96.         }catch(Exception e){
  97.             this.log.error("updateDatiStartRequestApplicabile error: "+e.getMessage(),e);
  98.             throw new PolicyException(e.getMessage(),e);
  99.         }
  100.     }

  101.     @Override
  102.     public void registerStopRequest(Logger log, String idTransazione, IDUnivocoGroupByPolicy datiGroupBy, Map<Object> ctx, MisurazioniTransazione dati,
  103.             boolean isApplicabile, boolean isViolata) throws PolicyException, PolicyNotFoundException {
  104.         try{
  105.             java.util.Map<String, List<String>> p = new HashMap<>();
  106.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_ACTIVE_ID, this.activeId);
  107.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_GROUP_BY_ID, IDUnivocoGroupByPolicy.serialize(datiGroupBy));
  108.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_MISURAZIONI_TRANSAZIONE, MisurazioniTransazione.serialize(dati));
  109.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_APPLICABILE, isApplicabile+"");
  110.             TransportUtils.setHeader(p,CostantiServizioControlloTraffico.PARAMETER_VIOLATA, isViolata+"");
  111.             String url = TransportUtils.buildUrlWithParameters(p, this.uriService+CostantiServizioControlloTraffico.OPERAZIONE_REGISTER_STOP_REQUEST, this.log);
  112.            
  113.             this.log.debug("[PolicyGroupByActiveThreadsWS.registerStopRequest] invoke ("+url+") ...");
  114.             HttpResponse response = HttpUtilities.getHTTPResponse(url);
  115.             this.log.debug("[PolicyGroupByActiveThreadsWS.registerStopRequest] invoked with code ["+response.getResultHTTPOperation()+"]");
  116.            
  117.             if(response.getResultHTTPOperation()!=200){
  118.                 throw new Exception("[httpCode:"+response.getResultHTTPOperation()+"] "+new String(response.getContent()));
  119.             }
  120.                        
  121.         }catch(Exception e){
  122.             this.log.error("registerStopRequest error: "+e.getMessage(),e);
  123.             throw new PolicyException(e.getMessage(),e);
  124.         }
  125.     }

  126. }