RicezioneBusteConnector.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.services.connector;

  21. import java.util.Date;

  22. import javax.servlet.ServletException;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;

  25. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  26. import org.openspcoop2.pdd.services.connector.messages.HttpServletConnectorInMessage;
  27. import org.openspcoop2.pdd.services.connector.messages.HttpServletConnectorOutMessage;
  28. import org.openspcoop2.pdd.services.error.RicezioneBusteExternalErrorGenerator;
  29. import org.openspcoop2.pdd.services.service.RicezioneBusteService;
  30. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  31. import org.openspcoop2.protocol.sdk.constants.CodiceErroreIntegrazione;
  32. import org.openspcoop2.protocol.sdk.constants.ErroriIntegrazione;
  33. import org.openspcoop2.protocol.sdk.constants.IDService;
  34. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;
  35. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  36. import org.openspcoop2.utils.Utilities;
  37. import org.openspcoop2.utils.date.DateManager;
  38. import org.openspcoop2.utils.transport.http.HttpRequestMethod;
  39. import org.slf4j.Logger;


  40. /**
  41.  * RicezioneBusteSOAPConnector
  42.  *
  43.  * @author Poli Andrea (apoli@link.it)
  44.  * @author Lorenzo Nardi (nardi@link.it)
  45.  * @author $Author$
  46.  * @version $Rev$, $Date$
  47.  */

  48. public class RicezioneBusteConnector {


  49.     /** Variabile che indica il Nome del modulo dell'architettura di OpenSPCoop rappresentato da questa classe */
  50.     public static final IDService ID_SERVICE = IDService.PORTA_APPLICATIVA;
  51.     public static final String ID_MODULO = ID_SERVICE.getValue();

  52.    
  53.     public void doEngine(RequestInfo requestInfo,
  54.             HttpServletRequest req, HttpServletResponse res, HttpRequestMethod method) throws ServletException {
  55.        
  56.         Date dataAccettazioneRichiesta = DateManager.getDate();
  57.                
  58.         // Devo prima leggere l'API invocata per comprendere il service binding effettivo
  59.         if(method!=null) {
  60.             // nop
  61.         }
  62.         /**if(HttpRequestMethod.GET.equals(method)){
  63.             java.util.Enumeration<?> parameters = req.getParameterNames();
  64.             while(parameters.hasMoreElements()){
  65.                 String key = (String) parameters.nextElement();
  66.                 String value = req.getParameter(key);
  67.                 if("wsdl".equalsIgnoreCase(key) && (value==null || "".equals(value)) ){
  68.                     ConnectorDispatcherUtils.doWsdl(req, res, method, ID_SERVICE);
  69.                     return;
  70.                 }
  71.             }
  72.         }
  73.        
  74.         if(org.openspcoop2.message.constants.ServiceBinding.SOAP.equals(requestInfo.getProtocolServiceBinding()) && !HttpRequestMethod.POST.equals(method)){

  75.             ConnectorDispatcherUtils.doMethodNotSupported(req, res, method, ID_SERVICE);
  76.             return;
  77.            
  78.         }*/
  79.        
  80.        
  81.         Logger logCore = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  82.        
  83.         RicezioneBusteExternalErrorGenerator generatoreErrore = null;
  84.         try{
  85.             generatoreErrore =
  86.                     new RicezioneBusteExternalErrorGenerator(logCore,ID_MODULO, requestInfo, null);
  87.         }catch(Exception e){
  88.             String msg = "Inizializzazione Generatore Errore fallita: "+Utilities.readFirstErrorValidMessageFromException(e);
  89.             logCore.error(msg,e);
  90.             ConnectorDispatcherUtils.doError(requestInfo, generatoreErrore, // il metodo doError gestisce il generatoreErrore a null
  91.                     ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.
  92.                     get5XX_ErroreProcessamento(msg,CodiceErroreIntegrazione.CODICE_501_PDD_NON_INIZIALIZZATA),
  93.                     IntegrationFunctionError.GOVWAY_NOT_INITIALIZED, e, res, logCore);
  94.             return;
  95.         }
  96.            
  97.        
  98.         RicezioneBusteService ricezioneBuste = new RicezioneBusteService(generatoreErrore);
  99.        
  100.         HttpServletConnectorInMessage httpIn = null;
  101.         try{
  102.             httpIn = new HttpServletConnectorInMessage(requestInfo, req, ID_SERVICE, ID_MODULO);
  103.         }catch(Exception e){
  104.             doError("HttpServletConnectorInMessage init error", e);
  105.         }
  106.        
  107.         IProtocolFactory<?> protocolFactory = null;
  108.         try{
  109.             protocolFactory = httpIn.getProtocolFactory();
  110.         }catch(Exception e){
  111.             // ignore
  112.         }
  113.        
  114.         HttpServletConnectorOutMessage httpOut = null;
  115.         try{
  116.             httpOut = new HttpServletConnectorOutMessage(requestInfo, protocolFactory, res, ID_SERVICE, ID_MODULO);
  117.         }catch(Exception e){
  118.             doError("HttpServletConnectorOutMessage init error", e);
  119.         }
  120.            
  121.         try{
  122.             ricezioneBuste.process(httpIn, httpOut, dataAccettazioneRichiesta);
  123.         }catch(Exception e){
  124.             doError("RicezioneBuste.process error", e);
  125.         }
  126.        
  127.        
  128.     }
  129.    
  130.     private void doError(String msg, Exception e) throws ServletException {
  131.         String msgError = msg+": "+e.getMessage();
  132.         ConnectorUtils.getErrorLog().error(msgError,e);
  133.         throw new ServletException(e.getMessage(),e);
  134.     }

  135. }