SPCoopEsitoBuilder.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.protocol.spcoop.builder;

  21. import javax.xml.soap.SOAPBody;

  22. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  23. import org.openspcoop2.protocol.basic.Costanti;
  24. import org.openspcoop2.protocol.basic.builder.EsitoBuilder;
  25. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  26. import org.openspcoop2.protocol.sdk.ProtocolException;
  27. import org.openspcoop2.protocol.sdk.builder.EsitoTransazione;
  28. import org.openspcoop2.protocol.sdk.builder.ProprietaErroreApplicativo;
  29. import org.openspcoop2.protocol.sdk.constants.EsitoTransazioneName;
  30. import org.openspcoop2.protocol.spcoop.constants.SPCoopCostanti;
  31. import org.w3c.dom.NamedNodeMap;
  32. import org.w3c.dom.Node;
  33. import org.w3c.dom.NodeList;

  34. /**
  35.  * Classe che implementa, in base al protocollo SPCoop, l'interfaccia {@link org.openspcoop2.protocol.sdk.builder.IEsitoBuilder}
  36.  *
  37.  * @author Poli Andrea (apoli@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public class SPCoopEsitoBuilder extends EsitoBuilder {

  42.     public SPCoopEsitoBuilder(IProtocolFactory<?> protocolFactory) throws ProtocolException {
  43.         super(protocolFactory);
  44.     }
  45.    
  46.     @Override
  47.     public EsitoTransazione getEsitoMessaggioApplicativo(OpenSPCoop2MessageFactory messageFactory,
  48.             ProprietaErroreApplicativo erroreApplicativo,SOAPBody body,String tipoContext, String erroreGovway, String internalErrorCodeGovWay) throws ProtocolException{
  49.         Node childNode = body.getFirstChild();
  50.         if(childNode!=null){
  51.             if(childNode.getNextSibling()==null){

  52.                 if("MessaggioDiErroreApplicativo".equals(childNode.getLocalName()) &&
  53.                         SPCoopCostanti.NAMESPACE_ECCEZIONE_APPLICATIVA_EGOV.equals(childNode.getNamespaceURI())){
  54.                     NodeList elements = childNode.getChildNodes();
  55.                     if(elements!=null){
  56.                         for(int i=0;i<elements.getLength();i++){
  57.                             Node elem = elements.item(i);
  58.                             if("Eccezione".equals(elem.getLocalName())){
  59.                                 NodeList elementsEccezione = elem.getChildNodes();
  60.                                 if(elementsEccezione!=null){
  61.                                     for(int j=0;j<elementsEccezione.getLength();j++){
  62.                                         Node tipoEccezione = elementsEccezione.item(j);
  63.                                         if(SPCoopCostanti.ECCEZIONE_PROCESSAMENTO_SPCOOP.equals(tipoEccezione.getLocalName())){
  64.                                             NamedNodeMap attr = tipoEccezione.getAttributes();
  65.                                             if(attr!=null){
  66.                                                 Node at = attr.getNamedItem("codiceEccezione");
  67.                                                 if(at!=null){
  68.                                                     String value = at.getNodeValue();
  69.                                                     String prefixFaultCode = null;
  70.                                                     if(erroreApplicativo!=null)
  71.                                                         prefixFaultCode = erroreApplicativo.getFaultPrefixCode();
  72.                                                     if(prefixFaultCode==null){
  73.                                                         prefixFaultCode=Costanti.ERRORE_INTEGRAZIONE_PREFIX_CODE;
  74.                                                     }
  75.                                                     boolean prefixOpv2 = value.startsWith(prefixFaultCode);
  76.                                                    
  77.                                                     if(!prefixOpv2 && internalErrorCodeGovWay!=null) {
  78.                                                         if(internalErrorCodeGovWay.startsWith(prefixFaultCode)) {
  79.                                                             prefixOpv2 = true;
  80.                                                             value = internalErrorCodeGovWay;
  81.                                                         }                                  
  82.                                                     }

  83.                                                     if(prefixOpv2){
  84.                                                         value = value.substring(prefixFaultCode.length());
  85.                                                         int valueInt = Integer.parseInt(value);
  86.                                                         if(valueInt>=400 && valueInt<=499){
  87.                                                             return this.esitiProperties.convertToEsitoTransazione(EsitoTransazioneName.ERRORE_PROCESSAMENTO_PDD_4XX, tipoContext);
  88.                                                         }else if(valueInt>=500 && valueInt<=599){
  89.                                                             return this.esitiProperties.convertToEsitoTransazione(EsitoTransazioneName.ERRORE_PROCESSAMENTO_PDD_5XX, tipoContext);
  90.                                                         }else{
  91.                                                             return this.esitiProperties.convertToEsitoTransazione(EsitoTransazioneName.ERRORE_PROCESSAMENTO_PDD_5XX, tipoContext);
  92.                                                         }
  93.                                                     }else{
  94.                                                         return this.esitiProperties.convertToEsitoTransazione(EsitoTransazioneName.ERRORE_PROCESSAMENTO_PDD_5XX, tipoContext); // ???
  95.                                                     }
  96.                                                 }
  97.                                             }
  98.                                         }
  99.                                         else if(SPCoopCostanti.ECCEZIONE_VALIDAZIONE_BUSTA_SPCOOP.equals(tipoEccezione.getLocalName())){
  100.                                             return this.esitiProperties.convertToEsitoTransazione(EsitoTransazioneName.ERRORE_PROTOCOLLO, tipoContext);
  101.                                         }
  102.                                     }
  103.                                 }
  104.                             }
  105.                         }
  106.                     }
  107.                 }
  108.             }
  109.         }
  110.         return null;
  111.     }

  112. }