StatusApiServiceImpl.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.core.config.rs.server.api.impl;

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

  23. import org.openspcoop2.core.config.rs.server.api.StatusApi;
  24. import org.openspcoop2.core.config.rs.server.api.impl.soggetti.SoggettiEnv;
  25. import org.openspcoop2.core.config.rs.server.config.ServerProperties;
  26. import org.openspcoop2.core.config.rs.server.model.Problem;
  27. import org.openspcoop2.core.id.IDSoggetto;
  28. import org.openspcoop2.utils.beans.BeanUtils;
  29. import org.openspcoop2.utils.beans.BlackListElement;
  30. import org.openspcoop2.utils.service.BaseImpl;
  31. import org.openspcoop2.utils.service.authorization.AuthorizationConfig;
  32. import org.openspcoop2.utils.service.authorization.AuthorizationManager;
  33. import org.openspcoop2.utils.service.beans.ProfiloEnum;
  34. import org.openspcoop2.utils.service.context.IContext;
  35. import org.openspcoop2.utils.service.fault.jaxrs.FaultCode;

  36. /**
  37.  * StatusApiServiceImpl
  38.  *
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  */
  42. public class StatusApiServiceImpl extends BaseImpl implements StatusApi {

  43.     public StatusApiServiceImpl(){
  44.         super(org.slf4j.LoggerFactory.getLogger(StatusApiServiceImpl.class));
  45.     }

  46.     private AuthorizationConfig getAuthorizationConfig() throws Exception{
  47.         return new AuthorizationConfig(ServerProperties.getInstance().getProperties());
  48.     }

  49.     /**
  50.      * Ritorna lo stato dell&#x27;applicazione
  51.      *
  52.      * Ritorna lo stato dell&#x27;applicazione in formato problem+json
  53.      *
  54.      */
  55.     @Override
  56.     public Problem getStatus() {
  57.         IContext context = this.getContext();
  58.         try {
  59.             context.getLogger().info("Invocazione in corso ...");    

  60.             AuthorizationManager.authorize(context, getAuthorizationConfig());
  61.             context.getLogger().debug("Autorizzazione completata con successo");    
  62.            
  63.             Problem p = null;
  64.                      
  65.             // Cerco soggetto di default in modo che sicuro esiste, almeno verifico la connessione
  66.             SoggettiEnv env = new SoggettiEnv(context.getServletRequest(), ProfiloEnum.APIGATEWAY, context);            
  67.             IDSoggetto idSogg = env.idSoggetto.toIDSoggetto();
  68.            
  69.             boolean exists = false;
  70.             try {
  71.                 exists = env.soggettiCore.existsSoggetto(idSogg);
  72.             } catch (Exception e) {}
  73.            
  74.             if (exists) {
  75.                 p = new Problem();
  76.                 org.openspcoop2.utils.service.fault.jaxrs.ProblemRFC7807 pUtils = FaultCode.STATUS_OK.toFault();
  77.                 List<BlackListElement> metodiEsclusi = new ArrayList<BlackListElement>(0);
  78.                 BeanUtils.copy(p, pUtils, metodiEsclusi);
  79.             }
  80.             else {
  81.                 throw new Exception("Servizio non disponibile");
  82.             }
  83.            
  84.             context.getLogger().info("Invocazione completata con successo");
  85.             return p;
  86.         }
  87.         catch(javax.ws.rs.WebApplicationException e) {
  88.             context.getLogger().error("Invocazione terminata con errore '4xx': %s",e, e.getMessage());
  89.             throw e;
  90.         }
  91.         catch(Throwable e) {
  92.             context.getLogger().error("Invocazione terminata con errore: %s",e, e.getMessage());
  93.             throw FaultCode.ERRORE_INTERNO.toException(e);
  94.         }
  95.     }
  96.    
  97. }