HandlerException.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;

  21. import org.openspcoop2.message.AbstractBaseOpenSPCoop2Message;
  22. import org.openspcoop2.message.ForcedResponseMessage;
  23. import org.openspcoop2.message.OpenSPCoop2Message;
  24. import org.openspcoop2.protocol.sdk.constants.ErroreIntegrazione;
  25. import org.openspcoop2.protocol.sdk.constants.ErroriIntegrazione;
  26. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;

  27. /**
  28.  * Contiene la definizione di una eccezione lanciata dalle classi del package org.openspcoop.pdd.core.handlers
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */


  34. public class HandlerException extends Exception {

  35.     private boolean customizedResponse=false;  
  36.     public boolean isCustomizedResponse() {
  37.         return this.customizedResponse;
  38.     }
  39.     public void setCustomizedResponse(boolean customizedResponse) {
  40.         this.customizedResponse = customizedResponse;
  41.     }

  42.     private boolean customizedResponseAs4xxCode=false; // se false viene ritornato un errore 5xx
  43.     public boolean isCustomizedResponseAs4xxCode() {
  44.         return this.customizedResponseAs4xxCode;
  45.     }
  46.     public void setCustomizedResponseAs4xxCode(boolean customizedResponseAs4xxCode) {
  47.         this.customizedResponseAs4xxCode = customizedResponseAs4xxCode;
  48.     }
  49.    
  50.     private String customizedResponseCode=null;
  51.     public String getCustomizedResponseCode() {
  52.         return this.customizedResponseCode;
  53.     }
  54.     public void setCustomizedResponseCode(String customizedResponseCode) {
  55.         this.customizedResponseCode = customizedResponseCode;
  56.     }

  57.     private String responseCode=null;
  58.     public String getResponseCode() {
  59.         return this.responseCode;
  60.     }
  61.     public void setResponseCode(String responseCode) {
  62.         this.responseCode = responseCode;
  63.     }

  64.     private boolean emptyResponse=false;
  65.     public boolean isEmptyResponse() {
  66.         return this.emptyResponse;
  67.     }
  68.     public void setEmptyResponse(boolean emptyResponse) {
  69.         this.emptyResponse = emptyResponse;
  70.     }

  71.     private byte [] response=null;
  72.     public byte[] getResponse() {
  73.         return this.response;
  74.     }
  75.     public void setResponse(byte[] response) {
  76.         this.response = response;
  77.     }

  78.     private String responseContentType;
  79.     public String getResponseContentType() {
  80.         return this.responseContentType;
  81.     }
  82.     public void setResponseContentType(String responseContentType) {
  83.         this.responseContentType = responseContentType;
  84.     }

  85.     private boolean emettiDiagnostico=true;
  86.     public boolean isEmettiDiagnostico() {
  87.         return this.emettiDiagnostico;
  88.     }
  89.     public void setEmettiDiagnostico(boolean emettiDiagnostico) {
  90.         this.emettiDiagnostico = emettiDiagnostico;
  91.     }

  92.     private String identitaHandler = null;
  93.     public String getIdentitaHandler() {
  94.         return this.identitaHandler;
  95.     }
  96.     // Impostato dal gestore degli handler
  97.     protected void setIdentitaHandler(String identitaHandler) {
  98.         this.identitaHandler = identitaHandler;
  99.     }

  100.     private IntegrationFunctionError integrationError = null;
  101.     public IntegrationFunctionError getIntegrationFunctionError() {
  102.         return this.integrationError;
  103.     }
  104.     public void setIntegrationFunctionError(IntegrationFunctionError integrationError) {
  105.         this.integrationError = integrationError;
  106.     }
  107.    
  108.     public ErroreIntegrazione convertToErroreIntegrazione() {
  109.         if(!this.customizedResponse) {
  110.             return null;
  111.         }
  112.         if(this.customizedResponseAs4xxCode) {
  113.             String customizedCode = "400";
  114.             if(this.customizedResponseCode!=null) {
  115.                 customizedCode = this.customizedResponseCode;
  116.             }
  117.             return ErroriIntegrazione.ERRORE_4XX_CUSTOM.get4XX_Custom(this.getMessage(), customizedCode);
  118.         }
  119.         else {
  120.             String customizedCode = "500";
  121.             if(this.customizedResponseCode!=null) {
  122.                 customizedCode = this.customizedResponseCode;
  123.             }
  124.             return ErroriIntegrazione.ERRORE_5XX_CUSTOM.get5XX_Custom(this.getMessage(), customizedCode);
  125.         }
  126.     }
  127.     public void customized(OpenSPCoop2Message responseMessage) {    
  128.         if(!this.customizedResponse) {
  129.             return;
  130.         }
  131.         if(this.isEmptyResponse()) {
  132.             responseMessage.forceEmptyResponse();
  133.         }
  134.         else if(this.getResponse()!=null) {
  135.             ForcedResponseMessage force = null;
  136.             if(responseMessage instanceof AbstractBaseOpenSPCoop2Message) {
  137.                 force = new ForcedResponseMessage((AbstractBaseOpenSPCoop2Message)responseMessage);
  138.             }
  139.             else {
  140.                 force = new ForcedResponseMessage();
  141.             }
  142.             force.setContent(this.getResponse());
  143.             if(this.getResponseContentType()!=null) {
  144.                 force.setContentType(this.getResponseContentType());
  145.             }
  146.             responseMessage.forceResponse(force);
  147.         }
  148.         if(this.getResponseCode()!=null) {
  149.             responseMessage.setForcedResponseCode(this.getResponseCode());
  150.         }
  151.     }
  152.    
  153.     public HandlerException(String message, Throwable cause)
  154.     {
  155.         super(message, cause);
  156.     }
  157.     public HandlerException(Throwable cause)
  158.     {
  159.         super(cause);
  160.     }
  161.     /**
  162.      * serialVersionUID
  163.      */
  164.     private static final long serialVersionUID = 1L;

  165.     public HandlerException() {
  166.         super();
  167.     }
  168.     public HandlerException(String msg) {
  169.         super(msg);
  170.     }

  171. }