RicezioneContenutiApplicativiHTTPtoSOAPConnector.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.io.IOException;
  22. import java.util.Date;

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

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

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

  48. public class RicezioneContenutiApplicativiHTTPtoSOAPConnector {


  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_DELEGATA_XML_TO_SOAP;
  51.     public static final String ID_MODULO = ID_SERVICE.getValue();

  52.     public void doEngine(RequestInfo requestInfo,
  53.             HttpServletRequest req, HttpServletResponse res, HttpRequestMethod method) throws ServletException, IOException {
  54.        
  55.         Date dataAccettazioneRichiesta = DateManager.getDate();
  56.        
  57.         // Devo prima leggere l'API invocata per comprendere il service binding effettivo
  58.         /**if(!org.openspcoop2.message.constants.ServiceBinding.SOAP.equals(requestInfo.getIntegrationServiceBinding())){

  59.             ConnectorDispatcherUtils.doServiceBindingNotSupported(req, res, method, requestInfo.getIntegrationServiceBinding(), ID_SERVICE);
  60.             return;
  61.            
  62.         }*/
  63.        
  64.         if(!HttpRequestMethod.POST.equals(method)){

  65.             ConnectorDispatcherUtils.doMethodNotSupported(req, res, method, ID_SERVICE);
  66.             return;
  67.            
  68.         }
  69.        
  70.        
  71.         Logger logCore = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  72.        
  73.         RicezioneContenutiApplicativiInternalErrorGenerator generatoreErrore = null;
  74.         try{
  75.             generatoreErrore =
  76.                     new RicezioneContenutiApplicativiInternalErrorGenerator(logCore, ID_MODULO, requestInfo);
  77.             RicezioneContenutiApplicativiHTTPtoSOAPService.forceXmlResponse(generatoreErrore);
  78.         }catch(Exception e){
  79.             String msg = "Inizializzazione Generatore Errore fallita: "+Utilities.readFirstErrorValidMessageFromException(e);
  80.             logCore.error(msg,e);
  81.             ConnectorDispatcherUtils.doError(requestInfo, generatoreErrore, // il metodo doError gestisce il generatoreErrore a null
  82.                     ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.
  83.                     get5XX_ErroreProcessamento(msg,CodiceErroreIntegrazione.CODICE_501_PDD_NON_INIZIALIZZATA),
  84.                     IntegrationFunctionError.GOVWAY_NOT_INITIALIZED, e, res, logCore);
  85.             return;
  86.         }

  87.        
  88.         RicezioneContenutiApplicativiHTTPtoSOAPService ricezioneContenutiApplicativi = new RicezioneContenutiApplicativiHTTPtoSOAPService(generatoreErrore);
  89.        
  90.         HttpServletConnectorInMessage httpIn = null;
  91.         try{
  92.             httpIn = new HttpServletConnectorInMessage(requestInfo, req, ID_SERVICE, ID_MODULO);
  93.         }catch(Exception e){
  94.             doError("HttpServletConnectorInMessage init error", e);
  95.         }
  96.        
  97.         IProtocolFactory<?> protocolFactory = null;
  98.         try{
  99.             protocolFactory = httpIn.getProtocolFactory();
  100.         }catch(Exception e){
  101.             // ignore
  102.         }
  103.        
  104.         HttpServletConnectorOutMessage httpOut = null;
  105.         try{
  106.             httpOut = new HttpServletConnectorOutMessage(requestInfo, protocolFactory, res, ID_SERVICE, ID_MODULO);
  107.         }catch(Exception e){
  108.             doError("HttpServletConnectorOutMessage init error", e);
  109.         }
  110.            
  111.         try{
  112.             ricezioneContenutiApplicativi.process(httpIn, httpOut, dataAccettazioneRichiesta);
  113.         }catch(Exception e){
  114.             doError("RicezioneContenutiApplicativiXMLtoSOAP.process error", e);
  115.         }
  116.            

  117.     }
  118.    
  119.     private void doError(String msg, Exception e) throws ServletException {
  120.         String msgError = msg+": "+e.getMessage();
  121.         ConnectorUtils.getErrorLog().error(msgError,e);
  122.         throw new ServletException(e.getMessage(),e);
  123.     }
  124. }