HttpBodyParameters.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.http;

  21. import org.openspcoop2.utils.UtilsException;

  22. /**
  23.  * HttpBodyParameters
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class HttpBodyParameters {

  30.     private boolean doOutput = false;
  31.     private boolean doInput = false;
  32.    
  33.     public HttpBodyParameters(HttpRequestMethod httpMethod, String contentType) throws UtilsException{
  34.        

  35.         switch (httpMethod) {
  36.        
  37.             // standard
  38.        
  39.             case OPTIONS:
  40.                 // If the OPTIONS request includes an entity-body then the media type MUST be indicated by a Content-Type field.
  41.                 // non supportato da HttpUrlConnection, throw 'HTTP method OPTIONS doesn't support output'
  42.                 /*if(contentType!=null && !"".equals(contentType)){
  43.                     this.doOutput = true;
  44.                 }
  45.                 else{*/
  46.                 this.doOutput = false;
  47.                 //}
  48.                 // body is not defined by this specification, but might be defined by future extensions to HTTP.
  49.                 this.doInput = true;
  50.                 break;

  51.             case GET:
  52.                 this.doOutput = false;
  53.                 this.doInput = true;    
  54.                 break;

  55.             case HEAD:
  56.                 // The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
  57.                 this.doOutput = false;
  58.                 this.doInput = false;  
  59.                 break;
  60.                
  61.             case POST:
  62.                 this.doOutput = true;
  63.                 this.doInput = true;
  64.                 break;
  65.                
  66.             case PUT:
  67.                 this.doOutput = true;
  68.                 this.doInput = true;
  69.                 break;
  70.                
  71.             case DELETE:
  72.                 this.doOutput = false;
  73.                 this.doInput = true;
  74.                 break;
  75.                
  76.             case TRACE:
  77.                 // A TRACE request MUST NOT include an entity
  78.                 this.doOutput = false;
  79.                 this.doInput = true;
  80.                 break;

  81.             // additional: https://tools.ietf.org/html/rfc2068#section-19.6.1
  82.                
  83.             case PATCH:
  84.                 // The PATCH method is similar to PUT
  85.                 this.doOutput = true;
  86.                 this.doInput = true;
  87.                 break;
  88.                
  89.             case LINK:
  90.                 // The PATCH method is similar to PUT
  91.                 this.doOutput = true;
  92.                 this.doInput = true;
  93.                 break;
  94.                
  95.             case UNLINK:
  96.                 // The PATCH method is similar to PUT
  97.                 this.doOutput = true;
  98.                 this.doInput = true;
  99.                 break;
  100.                
  101.             default:
  102.                 throw new UtilsException("HttpMethod ["+httpMethod+"] unsupported");
  103.         }
  104.        
  105.         if(contentType==null || "".equals(contentType)){
  106.             this.doOutput = false;
  107.         }
  108.        
  109.     }

  110.     public boolean isDoOutput() {
  111.         return this.doOutput;
  112.     }

  113.     public boolean isDoInput() {
  114.         return this.doInput;
  115.     }

  116. }