NotifierCallbackEnableUtils.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.handlers.notifier.engine;

  21. import java.util.Iterator;
  22. import java.util.List;
  23. import java.util.Map;

  24. import org.openspcoop2.core.config.DumpConfigurazione;
  25. import org.openspcoop2.core.config.PortaApplicativa;
  26. import org.openspcoop2.core.config.PortaDelegata;
  27. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  28. import org.openspcoop2.core.constants.Costanti;
  29. import org.openspcoop2.core.constants.TipoPdD;
  30. import org.openspcoop2.core.id.IDSoggetto;
  31. import org.openspcoop2.core.transazioni.constants.TipoMessaggio;
  32. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  33. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  34. import org.openspcoop2.pdd.core.PdDContext;
  35. import org.openspcoop2.pdd.core.handlers.InRequestProtocolContext;
  36. import org.openspcoop2.pdd.core.handlers.PostOutRequestContext;
  37. import org.openspcoop2.pdd.core.handlers.PostOutResponseContext;
  38. import org.openspcoop2.pdd.core.handlers.PreInRequestContext;
  39. import org.openspcoop2.pdd.core.handlers.PreInResponseContext;
  40. import org.openspcoop2.pdd.core.handlers.notifier.NotifierBufferState;
  41. import org.openspcoop2.pdd.core.handlers.notifier.NotifierResult;
  42. import org.openspcoop2.pdd.core.handlers.notifier.NotifierType;
  43. import org.openspcoop2.pdd.services.connector.ConnectorException;
  44. import org.openspcoop2.pdd.services.connector.messages.ConnectorInMessage;
  45. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  46. import org.openspcoop2.utils.io.notifier.unblocked.PipedInputOutputStreamHandler;
  47. import org.openspcoop2.utils.transport.TransportUtils;
  48. import org.slf4j.Logger;

  49. /**    
  50.  * NotifierCallbackEnableUtils
  51.  *
  52.  * @author Poli Andrea (poli@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class NotifierCallbackEnableUtils {

  57.     // *** enableNotifierInputStream ***
  58.    
  59.     public static boolean enableNotifierInputStream(NotifierCallback notifierCallback, NotifierType notifierType,
  60.             Object context) throws ConnectorException{
  61.        
  62.         if(OpenSPCoop2Properties.getInstance().isNotifierInputStreamEnabled()==false){
  63.             return false;
  64.         }
  65.        
  66.         if(NotifierType.PRE_IN_REQUEST.equals(notifierType)){
  67.             PreInRequestContext op2Context = (PreInRequestContext) context;
  68.            
  69.             ConnectorInMessage request = (ConnectorInMessage)op2Context.getTransportContext().get(PreInRequestContext.SERVLET_REQUEST);
  70.            
  71.             int length = request.getContentLength();
  72.             notifierCallback.debug("CONTENT LENGTH ["+length+"]");
  73.             setManagementMode(notifierCallback, length, op2Context.getPddContext());
  74.            
  75.             String contentType = request.getContentType();
  76.             notifierCallback.debug("CONTENT TYPE ["+contentType+"]");
  77.             op2Context.getPddContext().addObject(NotifierConstants.REQUEST_CONTENT_TYPE, contentType);
  78.            
  79.             return true;
  80.         }
  81.                
  82.         else if(NotifierType.PRE_IN_RESPONSE.equals(notifierType)){
  83.             PreInResponseContext op2Context = (PreInResponseContext) context;

  84.             Boolean responseDumpPostProcessEnabled = (Boolean) op2Context.getPddContext().getObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_ENABLED);
  85.            
  86.             if(responseDumpPostProcessEnabled!=null && responseDumpPostProcessEnabled){
  87.                 notifierCallback.debug("ReturnCode ["+op2Context.getCodiceTrasporto()+"]");
  88.                
  89.                 int length = -1;
  90.                 if(op2Context.getResponseHeaders()!=null && op2Context.getResponseHeaders().size()>0){
  91.                     Iterator<String> keys = op2Context.getResponseHeaders().keySet().iterator();
  92.                     while (keys.hasNext()) {
  93.                         String key = (String) keys.next();
  94.                         //notifierCallback.debug("TRANSPORT ["+key+"]=["+op2Context.getPropertiesTrasportoRisposta().getProperty(key)+"]");
  95.                         if("Content-Length".equalsIgnoreCase(key)){
  96.                             String lengthParam = TransportUtils.getFirstValue(op2Context.getResponseHeaders(),key);
  97.                             length = Integer.parseInt(lengthParam);
  98.                             notifierCallback.debug("CONTENT LENGTH RESPONSE ["+length+"]");            
  99.                         }
  100.                         else if("Content-Type".equalsIgnoreCase(key)){
  101.                             String contentType = TransportUtils.getFirstValue(op2Context.getResponseHeaders(),key);
  102.                             notifierCallback.debug("CONTENT TYPE RESPONSE ["+contentType+"]");  
  103.                             op2Context.getPddContext().addObject(NotifierConstants.RESPONSE_CONTENT_TYPE, contentType);
  104.                         }
  105.                     }
  106.                 }
  107.                 setManagementMode(notifierCallback, length, op2Context.getPddContext());
  108.                
  109.                 return true;
  110.             }
  111.         }
  112.        
  113.         return false;
  114.     }

  115.     private static void setManagementMode(NotifierCallback notifierCallback,int length,PdDContext pddContext){
  116.         ManagementMode mode = null;
  117.         if(length>0){
  118.             mode = ManagementMode.STREAMING;
  119.             Integer thresholdInMemory = OpenSPCoop2Properties.getInstance().getDumpNonRealtimeInMemoryThreshold();
  120.             if(thresholdInMemory!=null){
  121.                 if(length<thresholdInMemory){
  122.                     mode = ManagementMode.BUFFER;
  123.                 }
  124.             }
  125.         }
  126.         else{
  127.             // Per forza streaming, potrebbe essere gigante
  128.             mode = ManagementMode.STREAMING;
  129.         }
  130.         pddContext.addObject(NotifierConstants.MANAGEMENT_MODE, mode);
  131.         notifierCallback.debug("MANAGEMENT MODE ["+mode.name()+"]");
  132.     }
  133.    
  134.    
  135.    
  136.     // *** notify ***
  137.    
  138.     public static NotifierResult notify(NotifierCallback notifierCallback, NotifierType notifierType, Object context)
  139.             throws Exception {
  140.        
  141.         NotifierResult result = new NotifierResult();
  142.        
  143.         newStreamingHandlers(notifierCallback, result, notifierType, context);
  144.        
  145.         result.setBufferState(getBufferState(notifierCallback, notifierType, context));
  146.        
  147.         return result;
  148.        
  149.     }
  150.    
  151.    
  152.     // *** newStreamingHandlers ***
  153.    
  154.     private static void newStreamingHandlers(NotifierCallback notifierCallback, NotifierResult notifierResult,NotifierType notifierType,
  155.             Object context) throws Exception{
  156.        
  157.         if(NotifierType.IN_REQUEST_PROTOCOL_INFO.equals(notifierType)){
  158.            
  159.             InRequestProtocolContext op2Context = (InRequestProtocolContext) context;
  160.             setConfigurazioneDump(notifierCallback, op2Context);
  161.            
  162.             Boolean requestDumpPostProcessEnabled = (Boolean) op2Context.getPddContext().getObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_ENABLED);
  163.             if(requestDumpPostProcessEnabled){
  164.                
  165.                 Map<String, List<String>> headerTrasporto = null;
  166.                 if(TipoPdD.DELEGATA.equals(op2Context.getTipoPorta())){
  167.                     if(op2Context.getConnettore()!=null && op2Context.getConnettore().getUrlProtocolContext().getHeaders()!=null){
  168.                         headerTrasporto = op2Context.getConnettore().getUrlProtocolContext().getHeaders();
  169.                         op2Context.getPddContext().addObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_HEADER_TRASPORTO, headerTrasporto);
  170.                     }
  171.                 }
  172.                
  173.                 ManagementMode managementMode = (ManagementMode) op2Context.getPddContext().getObject(NotifierConstants.MANAGEMENT_MODE);
  174.                 if(ManagementMode.STREAMING.equals(managementMode)){
  175.                     notifierCallback.debug("CREO HANDLER DI STREAMING ...");
  176.                                        
  177.                     Logger log = op2Context.getLogCore();
  178.                                        
  179. //                  PipedInputOutputStreamHandler streamingHandler =
  180. //                  new PipedInputOutputStreamHandler(NotifierConstants.ID_HANDLER, notifierStreamingHandler, log);
  181.                     IDSoggetto dominio = null;
  182.                     if(op2Context.getProtocollo()!=null){
  183.                         dominio = op2Context.getProtocollo().getDominio();
  184.                     }
  185.                     notifierResult.addStreamingHandler(NotifierConstants.ID_HANDLER,
  186.                             newHandler(notifierCallback, log, TipoMessaggio.RICHIESTA_INGRESSO, op2Context.getPddContext(), headerTrasporto, dominio), log);
  187.                    
  188.                     notifierCallback.debug("CREATO!");
  189.                    
  190.                 }
  191.             }
  192.                    
  193.         }
  194.        
  195.         else if(NotifierType.PRE_IN_RESPONSE.equals(notifierType)){
  196.            
  197.             PreInResponseContext op2Context = (PreInResponseContext) context;
  198.            
  199.             Boolean responseDumpPostProcessEnabled = (Boolean) op2Context.getPddContext().getObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_ENABLED);
  200.             if(responseDumpPostProcessEnabled){
  201.                
  202.                 Map<String, List<String>> headerTrasporto = null;
  203.                 if(TipoPdD.APPLICATIVA.equals(op2Context.getTipoPorta())){
  204.                     if(op2Context.getResponseHeaders()!=null){
  205.                         headerTrasporto = op2Context.getResponseHeaders();
  206.                         op2Context.getPddContext().addObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_HEADER_TRASPORTO, headerTrasporto);
  207.                     }
  208.                 }
  209.                
  210.                 ManagementMode managementMode = (ManagementMode) op2Context.getPddContext().getObject(NotifierConstants.MANAGEMENT_MODE);
  211.                 if(ManagementMode.STREAMING.equals(managementMode)){
  212.                     notifierCallback.debug("CREO HANDLER DI STREAMING DI RISPOSTA ...");
  213.                                        
  214.                     Logger log = op2Context.getLogCore();
  215.                                        
  216. //                  PipedInputOutputStreamHandler streamingHandler =
  217. //                  new PipedInputOutputStreamHandler(NotifierConstants.ID_HANDLER, notifierStreamingHandler, log);
  218.                     IDSoggetto dominio = null;
  219.                     if(op2Context.getProtocollo()!=null){
  220.                         dominio = op2Context.getProtocollo().getDominio();
  221.                     }
  222.                     notifierResult.addStreamingHandler(NotifierConstants.ID_HANDLER,
  223.                             newHandler(notifierCallback, log, TipoMessaggio.RISPOSTA_INGRESSO, op2Context.getPddContext(), headerTrasporto, dominio), log);
  224.                    
  225.                     notifierCallback.debug("CREATO!");
  226.                    
  227.                 }
  228.             }
  229.         }

  230.        
  231.     }
  232.    
  233.     private static NotifierStreamingHandler newHandler(NotifierCallback notifierCallback, Logger log, TipoMessaggio tipoMessaggio,
  234.             PdDContext pddContext,Map<String, List<String>> headerTrasporto, IDSoggetto dominio) throws Exception{
  235.         long dumpPostProcessConfigId = (Long) pddContext.getObject(NotifierConstants.DUMP_POST_PROCESS_ID_CONFIG);
  236.         String idTransazione = (String) pddContext.getObject(Costanti.ID_TRANSAZIONE);
  237.         String contentType = null;
  238.         if(TipoMessaggio.RICHIESTA_INGRESSO.equals(tipoMessaggio)){
  239.             contentType = (String) pddContext.getObject(NotifierConstants.REQUEST_CONTENT_TYPE);
  240.         }else{
  241.             contentType = (String) pddContext.getObject(NotifierConstants.RESPONSE_CONTENT_TYPE);
  242.         }
  243.        
  244.         NotifierStreamingHandler notifierStreamingHandler =
  245.                 new NotifierStreamingHandler(notifierCallback,
  246.                         idTransazione,
  247.                         tipoMessaggio,
  248.                         headerTrasporto,
  249.                         dumpPostProcessConfigId,
  250.                         contentType, log, dominio);
  251.        
  252.         return notifierStreamingHandler;
  253.     }
  254.    

  255.     // *** getBufferState ***
  256.    
  257.     @SuppressWarnings("unchecked")
  258.     private static NotifierBufferState getBufferState(NotifierCallback notifierCallback, NotifierType notifierType,
  259.             Object context) throws Exception  {
  260.        
  261.         NotifierBufferState state = NotifierBufferState.UNMODIFIED;
  262.        
  263.         if(NotifierType.PRE_IN_REQUEST.equals(notifierType)){
  264.            
  265.             state = NotifierBufferState.ENABLE;
  266.             notifierCallback.debug("ABILITO IL BUFFER!!");
  267.            
  268.         }
  269.        
  270.         else if(NotifierType.IN_REQUEST_PROTOCOL_INFO.equals(notifierType)){
  271.            
  272.             InRequestProtocolContext op2Context = (InRequestProtocolContext) context;
  273.             setConfigurazioneDump(notifierCallback, op2Context);
  274.            
  275.             Boolean requestDumpPostProcessEnabled = (Boolean) op2Context.getPddContext().getObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_ENABLED);
  276.             if(requestDumpPostProcessEnabled){
  277.                
  278.                 ManagementMode managementMode = (ManagementMode) op2Context.getPddContext().getObject(NotifierConstants.MANAGEMENT_MODE);
  279.                
  280.                 if(ManagementMode.BUFFER.equals(managementMode)){
  281.                     notifierCallback.debug("DUMP POST PROCESS ABILITATO COME BUFFER, LASCIO BUFFER ABILITATO");                
  282.                 }
  283.                 else{
  284.                     state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  285.                     notifierCallback.debug("RILASCIO IL BUFFER, DUMP POST PROCESS ABILITATO COME STREAMING");
  286.                 }
  287.                    
  288.             }
  289.             else{
  290.                 state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  291.                 notifierCallback.debug("RILASCIO IL BUFFER, DUMP POST PROCESS NON ABILITATO");
  292.             }
  293.            
  294.         }
  295.        
  296.         else if(NotifierType.POST_OUT_REQUEST.equals(notifierType)){
  297.            
  298.             PostOutRequestContext op2Context = (PostOutRequestContext) context;
  299.            
  300.             IDSoggetto dominio = null;
  301.             if(op2Context.getProtocollo()!=null){
  302.                 dominio = op2Context.getProtocollo().getDominio();
  303.             }
  304.            
  305.             Boolean requestDumpPostProcessEnabled = (Boolean) op2Context.getPddContext().getObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_ENABLED);
  306.             if(requestDumpPostProcessEnabled){
  307.            
  308.                 Map<String, List<String>> headerTrasporto = null;
  309.                 if(TipoPdD.DELEGATA.equals(op2Context.getTipoPorta())){
  310.                     Object o = op2Context.getPddContext().getObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_HEADER_TRASPORTO);
  311.                     if(o!=null){
  312.                         headerTrasporto = (Map<String, List<String>>) o;
  313.                     }
  314.                 }
  315.                 else{
  316.                     if(op2Context.getConnettore()!=null){
  317.                         headerTrasporto = op2Context.getConnettore().getHeaders();
  318.                     }
  319.                 }
  320.                
  321.                 long dumpPostProcessConfigId = (Long) op2Context.getPddContext().getObject(NotifierConstants.DUMP_POST_PROCESS_ID_CONFIG);
  322.                 String contentTypeRequest = (String) op2Context.getPddContext().getObject(NotifierConstants.REQUEST_CONTENT_TYPE);
  323.                 String idTransazione = (String)op2Context.getPddContext().getObject(Costanti.ID_TRANSAZIONE);
  324.                 TipoMessaggio tipoMessaggio = TipoMessaggio.RICHIESTA_INGRESSO;
  325.                
  326.                 ManagementMode managementMode = (ManagementMode) op2Context.getPddContext().getObject(NotifierConstants.MANAGEMENT_MODE);
  327.                 if(ManagementMode.BUFFER.equals(managementMode)){
  328.                    
  329.                     notifierCallback.debug("[BUFFER MODE] RILASCIO IL BUFFER, e salvo il contenuto su database");
  330.                    
  331.                     state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  332.                                    
  333.                     byte[] buffer = op2Context.getMessaggio().getNotifierInputStream().serializeAndConsume();
  334.                    
  335.                     NotifierDump.getInstance().saveBuffer(notifierCallback, idTransazione, tipoMessaggio, headerTrasporto,
  336.                             dumpPostProcessConfigId, contentTypeRequest, buffer, dominio);
  337.                    
  338.                 }
  339.                 else{
  340.                    
  341.                     // raccolgo esito handler
  342.                     PipedInputOutputStreamHandler streamingHandler =
  343.                             (PipedInputOutputStreamHandler) op2Context.getMessaggio().getNotifierInputStream().getStreamingHandler(NotifierConstants.ID_HANDLER);
  344.                    
  345.                     if(streamingHandler.getError()!=null || streamingHandler.getException()!=null){
  346.                         String msg = null;
  347.                         if(streamingHandler.getError()!=null){
  348.                             msg = streamingHandler.getError();
  349.                         }else{
  350.                             msg = streamingHandler.getException().getMessage();
  351.                         }
  352.                         notifierCallback.debug("EVENTUALE ERRORE ["+msg+"]");
  353.                         if(streamingHandler.getException()!=null){
  354.                             throw new Exception(msg,streamingHandler.getException());
  355.                         }
  356.                         else{
  357.                             throw new Exception(msg);
  358.                         }
  359.                     }
  360.                    
  361.                    
  362.                     NotifierResultStreamingHandler result = (NotifierResultStreamingHandler) streamingHandler.getResult();
  363.                     if(result==null){
  364.                         throw new Exception("Streaming Handler ["+NotifierConstants.ID_HANDLER+"] non ha ritornato un risultato, ma nemmeno una eccezione");
  365.                     }
  366.                     if(result.isSaveOnFileSystem()){
  367.                        
  368.                         notifierCallback.debug("[STREAMING MODE su FS] RILASCIO IL BUFFER, e salvo il contenuto su database (file:"+result.getFile().getAbsolutePath()+")");
  369.                        
  370.                         state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  371.                        
  372.                         NotifierDump.getInstance().saveOnFileSystem(notifierCallback, idTransazione, tipoMessaggio, headerTrasporto,
  373.                                 dumpPostProcessConfigId, contentTypeRequest, result.getFile(), dominio);
  374.                        
  375.                     }
  376.                     else{
  377.                        
  378.                         notifierCallback.debug("[STREAMING MODE su Database] INSERT EFFETTUATA (ExecuteUpdate:"+result.getExecuteUpdateRow()+")");
  379.                         int rowUpdate = result.getExecuteUpdateRow();
  380.                        
  381.                         if(TipoPdD.APPLICATIVA.equals(op2Context.getTipoPorta())){
  382.                             // aggiorno l'header di trasporto
  383.                             if(headerTrasporto!=null){
  384.                                 rowUpdate = NotifierDump.getInstance().update(notifierCallback, idTransazione, tipoMessaggio, headerTrasporto, dominio);
  385.                             }
  386.                         }
  387.                        
  388.                         notifierCallback.debug("[STREAMING MODE su Database] RILASCIO IL BUFFER (ExecuteUpdate:"+rowUpdate+")");
  389.                        
  390.                         state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  391.                        
  392.                     }
  393.                    
  394.                 }
  395.             }
  396.         }
  397.        
  398.         else if(NotifierType.PRE_IN_RESPONSE.equals(notifierType)){
  399.            
  400.             PreInResponseContext op2Context = (PreInResponseContext) context;
  401.            
  402.             Boolean responseDumpPostProcessEnabled = (Boolean) op2Context.getPddContext().getObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_ENABLED);  
  403.             if(responseDumpPostProcessEnabled){
  404.                
  405.                 ManagementMode managementMode = (ManagementMode) op2Context.getPddContext().getObject(NotifierConstants.MANAGEMENT_MODE);
  406.                
  407.                 if(ManagementMode.BUFFER.equals(managementMode)){
  408.                     notifierCallback.debug("[BUFFER] ABILITO IL BUFFER ");
  409.                    
  410.                     state = NotifierBufferState.ENABLE;
  411.                 }
  412.                
  413.             }
  414.            
  415.         }
  416.        
  417.         else if(NotifierType.POST_OUT_RESPONSE.equals(notifierType)){
  418.            
  419.             PostOutResponseContext op2Context = (PostOutResponseContext) context;
  420.            
  421.             IDSoggetto dominio = null;
  422.             if(op2Context.getProtocollo()!=null){
  423.                 dominio = op2Context.getProtocollo().getDominio();
  424.             }
  425.            
  426.             Boolean responseDumpPostProcessEnabled = (Boolean) op2Context.getPddContext().getObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_ENABLED);  
  427.             if(responseDumpPostProcessEnabled){
  428.            
  429.                 Map<String, List<String>> headerTrasporto = null;
  430.                 if(TipoPdD.APPLICATIVA.equals(op2Context.getTipoPorta())){
  431.                     Object o = op2Context.getPddContext().getObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_HEADER_TRASPORTO);
  432.                     if(o!=null){
  433.                         headerTrasporto = (Map<String, List<String>>) o;
  434.                     }
  435.                 }
  436.                 else{
  437.                     if(op2Context.getResponseHeaders()!=null){
  438.                         headerTrasporto = op2Context.getResponseHeaders();
  439.                     }
  440.                 }
  441.                
  442.                 long dumpPostProcessConfigId = (Long) op2Context.getPddContext().getObject(NotifierConstants.DUMP_POST_PROCESS_ID_CONFIG);
  443.                 String contentTypeResponse = (String) op2Context.getPddContext().getObject(NotifierConstants.RESPONSE_CONTENT_TYPE);
  444.                 String idTransazione = (String)op2Context.getPddContext().getObject(Costanti.ID_TRANSAZIONE);
  445.                 TipoMessaggio tipoMessaggio = TipoMessaggio.RISPOSTA_INGRESSO;
  446.                
  447.                 ManagementMode managementMode = (ManagementMode) op2Context.getPddContext().getObject(NotifierConstants.MANAGEMENT_MODE);
  448.                 if(ManagementMode.BUFFER.equals(managementMode)){
  449.                    
  450.                     notifierCallback.debug("[BUFFER MODE] RILASCIO IL BUFFER, e salvo il contenuto su database");
  451.                    
  452.                     state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  453.                                    
  454.                     byte[] buffer = op2Context.getMessaggio().getNotifierInputStream().serializeAndConsume();
  455.                                        
  456.                     NotifierDump.getInstance().saveBuffer(notifierCallback, idTransazione, tipoMessaggio, headerTrasporto,
  457.                             dumpPostProcessConfigId, contentTypeResponse, buffer, dominio);
  458.                    
  459.                 }
  460.                 else{
  461.                    
  462.                     // raccolgo esito handler
  463.                     PipedInputOutputStreamHandler streamingHandler =
  464.                             (PipedInputOutputStreamHandler) op2Context.getMessaggio().getNotifierInputStream().getStreamingHandler(NotifierConstants.ID_HANDLER);
  465.                    
  466.                     if(streamingHandler.getError()!=null || streamingHandler.getException()!=null){
  467.                         String msg = null;
  468.                         if(streamingHandler.getError()!=null){
  469.                             msg = streamingHandler.getError();
  470.                         }else{
  471.                             msg = streamingHandler.getException().getMessage();
  472.                         }
  473.                         notifierCallback.debug("EVENTUALE ERRORE ["+msg+"]");
  474.                         if(streamingHandler.getException()!=null){
  475.                             throw new Exception(msg,streamingHandler.getException());
  476.                         }
  477.                         else{
  478.                             throw new Exception(msg);
  479.                         }
  480.                     }
  481.                    
  482.                    
  483.                     NotifierResultStreamingHandler result = (NotifierResultStreamingHandler) streamingHandler.getResult();
  484.                     if(result==null){
  485.                         throw new Exception("Streaming Handler ["+NotifierConstants.ID_HANDLER+"] non ha ritornato un risultato, ma nemmeno una eccezione");
  486.                     }
  487.                     if(result.isSaveOnFileSystem()){
  488.                        
  489.                         notifierCallback.debug("[STREAMING MODE su FS] RILASCIO IL BUFFER, e salvo il contenuto della risposta su database (file:"+result.getFile().getAbsolutePath()+")");
  490.                        
  491.                         state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  492.                        
  493.                         NotifierDump.getInstance().saveOnFileSystem(notifierCallback, idTransazione, tipoMessaggio, headerTrasporto,
  494.                                 dumpPostProcessConfigId, contentTypeResponse, result.getFile(), dominio);
  495.                        
  496.                     }
  497.                     else{
  498.                        
  499.                         notifierCallback.debug("[STREAMING MODE su Database] INSERT EFFETTUATA (ExecuteUpdate:"+result.getExecuteUpdateRow()+")");
  500.                         int rowUpdate = result.getExecuteUpdateRow();
  501.                        
  502.                         if(TipoPdD.DELEGATA.equals(op2Context.getTipoPorta())){
  503.                             // aggiorno l'header di trasporto
  504.                             if(headerTrasporto!=null){
  505.                                 rowUpdate = NotifierDump.getInstance().update(notifierCallback, idTransazione, tipoMessaggio, headerTrasporto, dominio);
  506.                             }
  507.                         }
  508.                        
  509.                         notifierCallback.debug("[STREAMING MODE su Database] RILASCIO IL BUFFER (ExecuteUpdate:"+rowUpdate+")");
  510.                        
  511.                         state = NotifierBufferState.DISABLE_AND_RELEASE_BUFFER_READED;
  512.                        
  513.                     }
  514.                    
  515.                 }
  516.             }
  517.         }
  518.        
  519.         return state;
  520.        
  521.     }
  522.    
  523.    
  524.    
  525.    
  526.    
  527.    
  528.     // Accesso configurazione Dump
  529.    
  530.     private static void setConfigurazioneDump(NotifierCallback notifierCallback, InRequestProtocolContext inRequestProtocolContext) throws Exception{
  531.        
  532.         if(inRequestProtocolContext.getPddContext().getObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_ENABLED)==null){
  533.        
  534.             DumpConfigurazione regolaDump = readConfigurazioneDump(inRequestProtocolContext);
  535.            
  536.             if(regolaDump!=null){
  537.                
  538.                 if(StatoFunzionalita.ABILITATO.equals(regolaDump.getRealtime())){
  539.                    
  540.                     boolean requestDumpPostProcessEnabled =
  541.                             regolaDump.getRichiestaIngresso()!=null &&
  542.                             (
  543.                                 StatoFunzionalita.ABILITATO.equals(regolaDump.getRichiestaIngresso().getBody())
  544.                                     ||
  545.                                 StatoFunzionalita.ABILITATO.equals(regolaDump.getRichiestaIngresso().getHeaders())
  546.                                     ||
  547.                                 StatoFunzionalita.ABILITATO.equals(regolaDump.getRichiestaIngresso().getAttachments())
  548.                              );
  549.                    
  550.                     boolean responseDumpPostProcessEnabled =
  551.                             regolaDump.getRispostaIngresso()!=null &&
  552.                             (
  553.                                 StatoFunzionalita.ABILITATO.equals(regolaDump.getRispostaIngresso().getBody())
  554.                                     ||
  555.                                 StatoFunzionalita.ABILITATO.equals(regolaDump.getRispostaIngresso().getHeaders())
  556.                                     ||
  557.                                 StatoFunzionalita.ABILITATO.equals(regolaDump.getRispostaIngresso().getAttachments())
  558.                              );
  559.                    
  560.                     inRequestProtocolContext.getPddContext().addObject(NotifierConstants.DUMP_POST_PROCESS_ID_CONFIG, regolaDump.getId());
  561.                     inRequestProtocolContext.getPddContext().addObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_ENABLED, requestDumpPostProcessEnabled);
  562.                     inRequestProtocolContext.getPddContext().addObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_ENABLED, responseDumpPostProcessEnabled);
  563.                    
  564.                     notifierCallback.debug("REGOLA DUMP PRESENTE COME POST PROCESS REQUEST["+requestDumpPostProcessEnabled+"] RESPONSE["+responseDumpPostProcessEnabled+"]");
  565.                 }
  566.                 else{
  567.                     notifierCallback.debug("REGOLA DUMP PRESENTE COME REAL TIME");
  568.                     inRequestProtocolContext.getPddContext().addObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_ENABLED, false);
  569.                     inRequestProtocolContext.getPddContext().addObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_ENABLED, false);
  570.                 }
  571.                
  572.             }
  573.             else{
  574.                 notifierCallback.debug("REGOLA DUMP NON PRESENTE");
  575.                 inRequestProtocolContext.getPddContext().addObject(NotifierConstants.REQUEST_DUMP_POST_PROCESS_ENABLED, false);
  576.                 inRequestProtocolContext.getPddContext().addObject(NotifierConstants.RESPONSE_DUMP_POST_PROCESS_ENABLED, false);
  577.             }
  578.            
  579.         }
  580.     }
  581.    
  582.     private static DumpConfigurazione readConfigurazioneDump(InRequestProtocolContext inRequestProtocolContext) throws Exception{
  583.                
  584.        
  585.         if(inRequestProtocolContext.getIntegrazione()==null) {
  586.             throw new Exception("inRequestProtocolContext.getIntegrazione() is null");
  587.         }
  588.         if(inRequestProtocolContext.getIntegrazione().getIdPD()==null &&
  589.                 inRequestProtocolContext.getIntegrazione().getIdPA()==null  ) {
  590.             throw new Exception("non รจ presente ne un identificativo di porta delegata, ne uno di porta applicativa");
  591.         }
  592.        
  593.         RequestInfo requestInfo = null;
  594.         if(inRequestProtocolContext.getPddContext()!=null && inRequestProtocolContext.getPddContext().containsKey(org.openspcoop2.core.constants.Costanti.REQUEST_INFO)){
  595.             requestInfo = (RequestInfo) inRequestProtocolContext.getPddContext().getObject(org.openspcoop2.core.constants.Costanti.REQUEST_INFO);
  596.         }
  597.        
  598.         DumpConfigurazione config = null;
  599.         ConfigurazionePdDManager configPdDManager = ConfigurazionePdDManager.getInstance(inRequestProtocolContext.getStato());
  600.         if(inRequestProtocolContext.getIntegrazione().getIdPD()!=null) {
  601.             PortaDelegata pd = configPdDManager.getPortaDelegata(inRequestProtocolContext.getIntegrazione().getIdPD(), requestInfo);
  602.             config = configPdDManager.getDumpConfigurazione(pd);
  603.         }
  604.         else {
  605.             PortaApplicativa pa = configPdDManager.getPortaApplicativa(inRequestProtocolContext.getIntegrazione().getIdPA(), requestInfo);
  606.             config = configPdDManager.getDumpConfigurazione(pa);
  607.         }
  608.        
  609.         return config;
  610.     }
  611.    
  612. }