TransportResponseContext.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.utils.transport;

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

  23. import org.openspcoop2.utils.LoggerWrapperFactory;
  24. import org.openspcoop2.utils.UtilsException;
  25. import org.openspcoop2.utils.transport.http.HttpConstants;
  26. import org.slf4j.Logger;

  27. /**
  28.  * TransportResponseContext
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */


  34. public class TransportResponseContext implements java.io.Serializable {


  35.     /**
  36.      *
  37.      */
  38.     private static final long serialVersionUID = 1L;
  39.        
  40.     /* ---- Coppie nome/valori di invocazione inserite nell'header del trasporto --- */
  41.     protected Map<String, List<String>> headers;
  42.    
  43.     protected String codiceTrasporto = null;
  44.     protected long contentLength = -1;
  45.     protected String errore = null;
  46.     protected Exception exception = null;
  47.    
  48.     protected Logger log = null;
  49.    
  50.     public TransportResponseContext() throws UtilsException{
  51.         this(null);
  52.     }
  53.     public TransportResponseContext(Logger log) throws UtilsException{
  54.         if(log==null) {
  55.             this.log = LoggerWrapperFactory.getLogger(TransportResponseContext.class);
  56.         }
  57.         else {
  58.             this.log = log;
  59.         }
  60.     }
  61.     @Deprecated
  62.     public TransportResponseContext(Map<String, String> parametersTrasporto,String codiceTrasporto,long contentLength,String errore,Exception exception) throws UtilsException{
  63.         this(null, codiceTrasporto, TransportUtils.convertToMapListValues(parametersTrasporto), contentLength, errore, exception);
  64.     }
  65.     @Deprecated
  66.     public TransportResponseContext(Logger log, Map<String, String> parametersTrasporto,String codiceTrasporto,long contentLength,String errore,Exception exception) throws UtilsException{
  67.         this(log, codiceTrasporto, TransportUtils.convertToMapListValues(parametersTrasporto), contentLength, errore, exception);
  68.     }
  69.     @Deprecated
  70.     public TransportResponseContext(String codiceTrasporto,Map<String, List<String>> headers,long contentLength,String errore,Exception exception) throws UtilsException{
  71.         this(null, codiceTrasporto, headers, contentLength, errore, exception);
  72.     }
  73.     public TransportResponseContext(Logger log, String codiceTrasporto,Map<String, List<String>> headers,long contentLength,String errore,Exception exception) throws UtilsException{
  74.         if(log==null) {
  75.             this.log = LoggerWrapperFactory.getLogger(TransportResponseContext.class);
  76.         }
  77.         else {
  78.             this.log = log;
  79.         }
  80.         this.headers = headers;
  81.         this.codiceTrasporto = codiceTrasporto;
  82.         this.contentLength = contentLength;
  83.         this.errore = errore;
  84.         this.exception = exception;
  85.     }
  86.    
  87.    
  88.     public String getCodiceTrasporto() {
  89.         return this.codiceTrasporto;
  90.     }
  91.     public long getContentLength() {
  92.         return this.contentLength;
  93.     }
  94.     public String getErrore() {
  95.         return this.errore;
  96.     }
  97.    
  98.     @Deprecated
  99.     public Map<String, String> getParametersTrasporto() {
  100.         return TransportUtils.convertToMapSingleValue(this.headers);
  101.     }
  102.     public Map<String, List<String>> getHeaders(){
  103.         return this.headers;
  104.     }
  105.    
  106.     @Deprecated
  107.     public String getParameterTrasporto(String name){
  108.         if(this.headers==null){
  109.             return null;
  110.         }
  111.         return TransportUtils.getObjectAsString(this.headers, name);
  112.     }
  113.     public String getHeader_compactMultipleValues(String name){
  114.         if(this.headers==null){
  115.             return null;
  116.         }
  117.         return TransportUtils.getObjectAsString(this.headers, name);
  118.     }
  119.     public String getHeaderFirstValue(String name){
  120.         List<String> l = getHeaderValues(name);
  121.         if(l!=null && !l.isEmpty()) {
  122.             return l.get(0);
  123.         }
  124.         return null;
  125.     }
  126.     public List<String> getHeaderValues(String name){
  127.         if(this.headers==null){
  128.             return null;
  129.         }
  130.         return TransportUtils.getRawObject(this.headers, name);
  131.     }
  132.    
  133.     @Deprecated
  134.     public Object removeParameterTrasporto(String name){
  135.         if(this.headers==null){
  136.             return null;
  137.         }
  138.         return TransportUtils.removeObjectAsString(this.headers, name);
  139.     }
  140.     public String removeHeader_compactMultipleValues(String name){
  141.         if(this.headers==null){
  142.             return null;
  143.         }
  144.         return TransportUtils.removeObjectAsString(this.headers, name);
  145.     }
  146.     public List<String> removeHeader(String name){
  147.         if(this.headers==null){
  148.             return null;
  149.         }
  150.         return TransportUtils.removeRawObject(this.headers, name);
  151.     }
  152.    
  153.     public String getContentType(){
  154.         if(this.headers!=null){
  155.             return this.getHeaderFirstValue(HttpConstants.CONTENT_TYPE);
  156.         }
  157.         return null;
  158.     }

  159.     public void setCodiceTrasporto(String codiceTrasporto) {
  160.         this.codiceTrasporto = codiceTrasporto;
  161.     }
  162.     public void setContentLength(long contentLength) {
  163.         this.contentLength = contentLength;
  164.     }
  165.     public void setErrore(String errore) {
  166.         this.errore = errore;
  167.     }
  168.    
  169.     @Deprecated
  170.     public void setParametersTrasporto(Map<String, String> parametersTrasporto) {
  171.         this.headers = TransportUtils.convertToMapListValues(parametersTrasporto);
  172.     }
  173.     public void setHeaders(Map<String, List<String>> parametersFormBased) {
  174.         this.headers = parametersFormBased;
  175.     }

  176. }