HttpUtilities.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 java.io.ByteArrayOutputStream;
  22. import java.io.File;
  23. import java.io.FileInputStream;
  24. import java.io.InputStream;
  25. import java.io.OutputStream;
  26. import java.lang.reflect.Field;
  27. import java.net.HttpURLConnection;
  28. import java.net.InetSocketAddress;
  29. import java.net.Proxy;
  30. import java.net.URL;
  31. import java.net.URLConnection;
  32. import java.security.Key;
  33. import java.security.KeyStore;
  34. import java.security.Provider;
  35. import java.security.cert.CertStore;
  36. import java.util.ArrayList;
  37. import java.util.Enumeration;
  38. import java.util.HashMap;
  39. import java.util.Iterator;
  40. import java.util.List;
  41. import java.util.Map;

  42. import javax.net.ssl.CertPathTrustManagerParameters;
  43. import javax.net.ssl.HttpsURLConnection;
  44. import javax.net.ssl.KeyManager;
  45. import javax.net.ssl.KeyManagerFactory;
  46. import javax.net.ssl.SSLContext;
  47. import javax.net.ssl.TrustManager;
  48. import javax.net.ssl.TrustManagerFactory;
  49. import javax.net.ssl.X509KeyManager;
  50. import javax.servlet.http.HttpServletRequest;
  51. import javax.servlet.http.HttpServletResponse;

  52. import org.apache.commons.codec.digest.DigestUtils;
  53. import org.apache.commons.lang.StringUtils;
  54. import org.openspcoop2.utils.CopyStream;
  55. import org.openspcoop2.utils.LoggerWrapperFactory;
  56. import org.openspcoop2.utils.Utilities;
  57. import org.openspcoop2.utils.UtilsException;
  58. import org.openspcoop2.utils.certificate.KeystoreType;
  59. import org.openspcoop2.utils.certificate.KeystoreUtils;
  60. import org.openspcoop2.utils.certificate.hsm.HSMManager;
  61. import org.openspcoop2.utils.digest.DigestEncoding;
  62. import org.openspcoop2.utils.io.Base64Utilities;
  63. import org.openspcoop2.utils.mime.MimeTypes;
  64. import org.openspcoop2.utils.random.RandomGenerator;
  65. import org.openspcoop2.utils.regexp.RegExpUtilities;
  66. import org.openspcoop2.utils.resources.FileSystemUtilities;
  67. import org.openspcoop2.utils.resources.Loader;
  68. import org.openspcoop2.utils.transport.TransportUtils;
  69. import org.slf4j.Logger;


  70. /**
  71.  * Classe che contiene utility per accedere a risorse http
  72.  *
  73.  * @author Poli Andrea (apoli@link.it)
  74.  * @author $Author$
  75.  * @version $Rev$, $Date$
  76.  */
  77. public class HttpUtilities {
  78.    
  79.     private HttpUtilities() {}

  80.     /**
  81.      * Si occupa di effettuare la connessione verso l'indirizzo specificato dal<var>path</var>.
  82.      *
  83.      *
  84.      * @param path url del file xml contenente la definizione di un servizio.
  85.      * @return i byte del file xml situato all'indirizzo <var>path</var>.
  86.      *
  87.      */
  88.     /** TIMEOUT_CONNECTION (2 minuti) */
  89.     public static final int HTTP_CONNECTION_TIMEOUT = 10000;
  90.     /** TIMEOUT_READ (2 minuti) */
  91.     public static final int HTTP_READ_CONNECTION_TIMEOUT = 120000;

  92.    
  93.     public static List<String> getClientAddressHeaders() {
  94.         // X-Forwarded-For: A de facto standard for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or load balancer
  95.         // Forwarded: Disclose original information of a client connecting to a web server through an HTTP proxy.'
  96.         List<String> possibiliHeaders = new ArrayList<>();
  97.         possibiliHeaders.add("X-Forwarded-For");
  98.         possibiliHeaders.add("Forwarded-For"); // senza la 'X-' nel caso l'header venga fatto rendere uno standard
  99.         possibiliHeaders.add("X-Forwarded");
  100.         possibiliHeaders.add("Forwarded");
  101.         possibiliHeaders.add("X-Client-IP");
  102.         possibiliHeaders.add("Client-IP");
  103.         possibiliHeaders.add("X-Cluster-Client-IP");
  104.         possibiliHeaders.add("Cluster-Client-IP");
  105.         return possibiliHeaders;
  106.     }
  107.     public static String getClientAddress(HttpServletRequest request) throws UtilsException{
  108.         try{
  109.             return getClientAddress(getClientAddressHeaders(), request);
  110.         }catch(Exception e){
  111.             throw new UtilsException(e.getMessage(),e);
  112.         }
  113.     }
  114.     public static String getClientAddressFirstValue(HttpServletRequest request) throws UtilsException{
  115.         return getClientAddress(request);
  116.     }
  117.     private static String getClientAddress(List<String> headers, HttpServletRequest request) throws UtilsException{
  118.         if(!headers.isEmpty()){
  119.             for (String header : headers) {
  120.                 List<String> l = TransportUtils.getHeaderValues(request,header);
  121.                 if(l!=null && !l.isEmpty()) {
  122.                     return l.get(0);
  123.                 }
  124.             }
  125.         }
  126.         return null;
  127.     }
  128.    
  129.     @Deprecated
  130.     public static String getClientAddress(Map<String, String> transportProperties) throws UtilsException{
  131.         return getClientAddress(getClientAddressHeaders(), TransportUtils.convertToMapListValues(transportProperties));
  132.     }
  133.     public static String getClientAddressFirstValue(Map<String, List<String>> headers) throws UtilsException{
  134.         return getClientAddress(getClientAddressHeaders(), headers);
  135.     }
  136.     private static String getClientAddress(List<String> headers, Map<String, List<String>> transportProperties) {
  137.         if(!headers.isEmpty()){
  138.             for (String header : headers) {
  139.                 List<String> l = TransportUtils.getRawObject(transportProperties,header);
  140.                 if(l!=null && !l.isEmpty()) {
  141.                     return l.get(0);
  142.                 }
  143.             }
  144.         }
  145.         return null;
  146.     }
  147.    
  148.    
  149.     public static String getHttpReason(int status) {
  150.    
  151.         if(status==100) {
  152.             return "Continue"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.2.1]
  153.         }
  154.         else if(status==101) {
  155.             return "Switching Protocols"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.2.2]
  156.         }
  157.         else if(status==102) {
  158.             return "Processing"; // WebDAV - RFC 2518  [RFC2518]
  159.         }
  160.         // 103-199  Unassigned  
  161.        
  162.                
  163.        
  164.         else if(status==200) {
  165.             return "OK"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.3.1]
  166.         }
  167.         else if(status==201) {
  168.             return "Created"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.3.2]
  169.         }
  170.         else if(status==202) {
  171.             return "Accepted"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.3.3]
  172.         }
  173.         else if(status==203) {
  174.             return "Non-Authoritative Information"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.3.4]
  175.         }
  176.         else if(status==204) {
  177.             return "No Content"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.3.5]
  178.         }
  179.         else if(status==205) {
  180.             return "Reset Content"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.3.6]
  181.         }
  182.         else if(status==206) {
  183.             return "Partial Content"; // HTTP/1.1 - RFC 2616  [RFC7233, Section 4.1]
  184.         }
  185.         else if(status==207) {
  186.             return "Multi-Status"; // (WebDAV - RFC 2518)  [RFC4918] or 207 Partial Update OK (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?)
  187.         }
  188.         else if(status==208) {
  189.             return "Already Reported"; // WebDAV - RFC 2518  [RFC5842]
  190.         }
  191.         // 209-225  Unassigned  
  192.         else if(status==226) {
  193.             return "IM Used"; // [RFC3229]
  194.         }
  195.         // 227-299  Unassigned  
  196.        
  197.        
  198.         else if(status==300) {
  199.             return "Multiple Choices"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.4.1]
  200.         }
  201.         else if(status==301) {
  202.             return "Moved Permanently"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.4.2]
  203.         }
  204.         else if(status==302) {
  205.             return "Found"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.4.3]
  206.         }
  207.         else if(status==303) {
  208.             return "See Other"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.4.4]
  209.         }      
  210.         else if(status==304) {
  211.             return "Not Modified"; // HTTP/1.0 - RFC 1945  [RFC7232, Section 4.1]
  212.         }
  213.         else if(status==305) {
  214.             return "Use Proxy"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.4.5]
  215.         }
  216.         else if(status==306) {
  217.             return "Switch Proxy"; // (Unused)  [RFC7231, Section 6.4.6]
  218.         }
  219.         else if(status==307) {
  220.             return "Temporary Redirect"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.4.7]
  221.         }
  222.         else if(status==308) {
  223.             return "Permanent Redirect"; // [RFC7538]
  224.         }
  225.         // 309-399  Unassigned  
  226.        

  227.         else if(status==400) {
  228.             return "Bad Request"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.1]
  229.         }
  230.         else if(status==401) {
  231.             return "Unauthorized"; // HTTP/1.0 - RFC 1945  [RFC7235, Section 3.1]
  232.         }
  233.         else if(status==402) {
  234.             return "Payment Required"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.2]
  235.         }
  236.         else if(status==403) {
  237.             return "Forbidden"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.5.3]
  238.         }
  239.         else if(status==404) {
  240.             return "Not Found"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.5.4]
  241.         }
  242.         else if(status==405) {
  243.             return "Method Not Allowed"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.5]
  244.         }
  245.         else if(status==406) {
  246.             return "Not Acceptable"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.6]
  247.         }
  248.         else if(status==407) {
  249.             return "Proxy Authentication Required"; // HTTP/1.1 - RFC 2616  [RFC7235, Section 3.2]
  250.         }
  251.         else if(status==408) {
  252.             return "Request Timeout"; // [RFC7231, Section 6.5.7]
  253.         }
  254.         else if(status==409) {
  255.             return "Conflict"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.8]
  256.         }
  257.         else if(status==410) {
  258.             return "Gone"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.9]
  259.         }
  260.         else if(status==411) {
  261.             return "Length Required"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.10]
  262.         }
  263.         else if(status==412) {
  264.             return "Precondition Failed"; // HTTP/1.1 - RFC 2616  [RFC7232, Section 4.2][RFC8144, Section 3.2]
  265.         }
  266.         else if(status==413) {
  267.             return "Payload Too Large"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.11]
  268.         }
  269.         else if(status==414) {
  270.             return "URI Too Long"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.12]
  271.         }
  272.         else if(status==415) {
  273.             return "Unsupported Media Type"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.13][RFC7694, Section 3]
  274.         }
  275.         else if(status==416) {
  276.             return "Range Not Satisfiable"; // HTTP/1.1 - RFC 2616  [RFC7233, Section 4.4]
  277.         }
  278.         else if(status==417) {
  279.             return "Expectation Failed"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.5.14]
  280.         }
  281.         // 418 Unassigned
  282.         else if(status==419) {
  283.             return "Authentication Timeout"; // HTTP/1.1 - RFC 2616
  284.         }
  285.         // 420 Unassigned
  286.         else if(status==421) {
  287.             return "Misdirected Request"; // [RFC7540, Section 9.1.2]
  288.         }
  289.         else if(status==422) {
  290.             return "Unprocessable Entity"; // WebDAV - RFC 2518  [RFC4918]
  291.         }
  292.         else if(status==423) {
  293.             return "Locked"; // (WebDAV - RFC 2518) [RFC4918]
  294.         }
  295.         else if(status==424) {
  296.             return "Failed Dependency"; // WebDAV - RFC 2518 [RFC4918]
  297.         }
  298.         // 425 Unassigned
  299.         else if(status==426) {
  300.             return "Upgrade Required"; // [RFC7231, Section 6.5.15]
  301.         }
  302.         // 427 Unassigned
  303.         else if(status==428) {
  304.             return "Precondition Required"; // [RFC6585]
  305.         }
  306.         else if(status==429) {
  307.             return "Too Many Requests"; // [RFC6585]
  308.         }
  309.         // 430 Unassigned
  310.         else if(status==431) {
  311.             return "Request Header Fields Too Large"; // [RFC6585]
  312.         }
  313.         // 432-450  Unassigned
  314.         else if(status==451) {
  315.             return "Unavailable For Legal Reasons"; // [RFC7725]
  316.         }
  317.         // 452-499  Unassigned  
  318.        

  319.         else if(status==500) {
  320.             return "Internal Server Error"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.6.1]
  321.         }
  322.         else if(status==501) {
  323.             return "Not Implemented"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.6.2]
  324.         }
  325.         else if(status==502) {
  326.             return "Bad Gateway"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.6.3]
  327.         }
  328.         else if(status==503) {
  329.             return "Service Unavailable"; // HTTP/1.0 - RFC 1945  [RFC7231, Section 6.6.4]
  330.         }
  331.         else if(status==504) {
  332.             return "Gateway Timeout"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.6.5]
  333.         }
  334.         else if(status==505) {
  335.             return "HTTP Version Not Supported"; // HTTP/1.1 - RFC 2616  [RFC7231, Section 6.6.6]
  336.         }
  337.         else if(status==506) {
  338.             return "Variant Also Negotiates"; // [RFC2295]
  339.         }
  340.         else if(status==507) {
  341.             return "Insufficient Storage"; // WebDAV - RFC 2518  [RFC4918]
  342.         }
  343.         else if(status==508) {
  344.             return "Loop Detected"; // [RFC5842]
  345.         }
  346.         else if(status==509) {
  347.             return "Bandwidth Limit Exceeded"; // [Apache]
  348.         }
  349.         else if(status==510) {
  350.             return "Not Extended"; // [RFC2774]
  351.         }
  352.         else if(status==511) {
  353.             return "Network Authentication Required"; // [RFC6585]
  354.         }
  355.         // 512-599  Unassigned  

  356.         return null;
  357.     }
  358.    
  359.    
  360.    
  361.     public static final String HEADER_X_DOWNLOAD = "application/x-download";
  362.     public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition";
  363.     public static final String HEADER_ATTACH_FILE = "attachment; filename=";
  364.    
  365.     public static void setOutputFile(HttpServletResponse response, boolean noCache, String fileName) throws UtilsException{
  366.        
  367.         if(fileName==null) {
  368.             throw new UtilsException("Param filename is null");
  369.         }
  370.        
  371.         // setto content-type e header per gestire il download lato client
  372.         String mimeType = null;
  373.         if(fileName.contains(".")){
  374.             String ext = null;
  375.             try{
  376.                 ext = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
  377.             }catch(Exception e){
  378.                 // ext non disponibile
  379.             }
  380.             MimeTypes mimeTypes = MimeTypes.getInstance();
  381.             if(ext!=null && mimeTypes.existsExtension(ext)){
  382.                 mimeType = mimeTypes.getMimeType(ext);
  383.                 /**System.out.println("CUSTOM ["+mimeType+"]");*/      
  384.             }
  385.             else{
  386.                 mimeType = HttpConstants.CONTENT_TYPE_X_DOWNLOAD;
  387.             }
  388.         }
  389.         else{
  390.             mimeType = HttpConstants.CONTENT_TYPE_X_DOWNLOAD;
  391.         }
  392.        
  393.         setOutputFile(response, noCache, fileName, mimeType);
  394.     }
  395.    
  396.     public static void setOutputFile(HttpServletResponse response, boolean noCache, String fileName, String mimeType) throws UtilsException{
  397.                
  398.         if(response==null) {
  399.             throw new UtilsException("Param response is null");
  400.         }
  401.        
  402.         if(mimeType!=null){
  403.             response.setContentType(mimeType);
  404.         }

  405.         response.setHeader(HttpConstants.CONTENT_DISPOSITION, (new StringBuilder()).append(HttpConstants.CONTENT_DISPOSITION_ATTACH_FILE_PREFIX+"\"").append(fileName).append("\"").toString());
  406.        
  407.         // no cache
  408.         if(noCache){
  409.             setNoCache(response);
  410.         }
  411.        
  412.     }
  413.    
  414.    
  415.    
  416.     public static void setNoCache(HttpServletResponse response) {
  417.         response.setHeader(HttpConstants.CACHE_STATUS_HTTP_1_1, HttpConstants.CACHE_STATUS_HTTP_1_1_DISABLE_CACHE); // HTTP 1.1.
  418.         response.setHeader(HttpConstants.CACHE_STATUS_HTTP_1_0, HttpConstants.CACHE_STATUS_HTTP_1_0_DISABLE_CACHE); // HTTP 1.0.
  419.         response.setDateHeader(HttpConstants.CACHE_STATUS_PROXY_EXPIRES, HttpConstants.CACHE_STATUS_PROXY_EXPIRES_DISABLE_CACHE); // Proxies.
  420.         response.setHeader(HttpConstants.CACHE_STATUS_VARY, HttpConstants.CACHE_STATUS_VARY_UNCACHABLE);
  421.     }
  422.    
  423.    
  424.     @Deprecated
  425.     public static boolean isNoCache(Map<String, String> headers) throws UtilsException{
  426.         return isDirectiveNoCache(TransportUtils.convertToMapListValues(headers));
  427.     }
  428.     public static boolean isDirectiveNoCache(Map<String, List<String>> headers) throws UtilsException{
  429.         List<String> l = getCacheControlDirectives(headers);
  430.         if(l.isEmpty()) {
  431.             l = getPragmaDirectives(headers);
  432.         }
  433.         if(l.isEmpty()) {
  434.             return false;
  435.         }
  436.         else {
  437.             return l.contains(HttpConstants.CACHE_STATUS_DIRECTIVE_NO_CACHE);
  438.         }
  439.     }
  440.    
  441.     @Deprecated
  442.     public static boolean isNoStore(Map<String, String> headers) throws UtilsException{
  443.         return isDirectiveNoStore(TransportUtils.convertToMapListValues(headers));
  444.     }
  445.     public static boolean isDirectiveNoStore(Map<String, List<String>> headers) throws UtilsException{
  446.         List<String> l = getCacheControlDirectives(headers);
  447.         if(l.isEmpty()) {
  448.             l = getPragmaDirectives(headers);
  449.             if(l.isEmpty()) {
  450.                 return false;
  451.             }else{
  452.                 return l.contains(HttpConstants.CACHE_STATUS_DIRECTIVE_NO_CACHE); // no cache in pragma vale anche per nostore.
  453.             }
  454.         }
  455.         else {
  456.             return l.contains(HttpConstants.CACHE_STATUS_DIRECTIVE_NO_STORE);
  457.         }
  458.     }
  459.    
  460.     @Deprecated
  461.     public static Integer getCacheMaxAge(Map<String, String> headers) {
  462.         return getDirectiveCacheMaxAge(TransportUtils.convertToMapListValues(headers));
  463.     }
  464.     public static Integer getDirectiveCacheMaxAge(Map<String, List<String>> headers) {
  465.         List<String> l = getCacheControlDirectives(headers);
  466.         if(l.isEmpty()) {
  467.             return null;
  468.         }
  469.         else {
  470.             for (String direttiva : l) {
  471.                 if(direttiva!=null && direttiva.startsWith(HttpConstants.CACHE_STATUS_DIRECTIVE_MAX_AGE+"=") && !direttiva.endsWith("=")) {
  472.                     try {
  473.                         String age = direttiva.substring((HttpConstants.CACHE_STATUS_DIRECTIVE_MAX_AGE+"=").length(), direttiva.length());
  474.                         return Integer.valueOf(age);
  475.                     }catch(Exception t) {
  476.                         // ignore
  477.                     }
  478.                 }
  479.             }
  480.             return null;
  481.         }
  482.     }
  483.    
  484.     @Deprecated
  485.     public static List<String> getDirectiveCacheControl(Map<String, String> headers){
  486.         return getCacheControlDirectives(TransportUtils.convertToMapListValues(headers));
  487.     }
  488.     public static List<String> getCacheControlDirectives(Map<String, List<String>> headers){
  489.        
  490.         List<String> l = TransportUtils.getRawObject(headers, HttpConstants.CACHE_STATUS_HTTP_1_1);
  491.         String cacheControl = null;
  492.         if(l!=null && !l.isEmpty()) {
  493.             cacheControl = l.get(0);
  494.         }
  495.        
  496.         List<String> values = new ArrayList<>();
  497.         if(cacheControl!=null) {
  498.             if(cacheControl.contains(",")) {
  499.                 String [] tmp = cacheControl.split(",");
  500.                 for (int i = 0; i < tmp.length; i++) {
  501.                     values.add(tmp[i].trim());
  502.                 }
  503.             }
  504.             else {
  505.                 values.add(cacheControl);
  506.             }
  507.         }
  508.        
  509.         return values;
  510.     }
  511.    
  512.     @Deprecated
  513.     public static List<String> getDirectivePragma(Map<String, String> headers){
  514.         return getPragmaDirectives(TransportUtils.convertToMapListValues(headers));
  515.     }
  516.     public static List<String> getPragmaDirectives(Map<String, List<String>> headers){
  517.        
  518.         List<String> l = TransportUtils.getRawObject(headers, HttpConstants.CACHE_STATUS_HTTP_1_0);
  519.         String cacheControl = null;
  520.         if(l!=null && !l.isEmpty()) {
  521.             cacheControl = l.get(0);
  522.         }
  523.        
  524.         List<String> values = new ArrayList<>();
  525.         if(cacheControl!=null) {
  526.             if(cacheControl.contains(",")) {
  527.                 String [] tmp = cacheControl.split(",");
  528.                 for (int i = 0; i < tmp.length; i++) {
  529.                     values.add(tmp[i].trim());
  530.                 }
  531.             }
  532.             else {
  533.                 values.add(cacheControl);
  534.             }
  535.         }
  536.        
  537.         return values;
  538.     }
  539.    
  540.    
  541.    
  542.     public static void enableHttpUrlConnectionForwardRestrictedHeaders() {
  543.         System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
  544.     }
  545.    
  546.    
  547.    
  548.     public static void setChunkedStreamingMode(HttpURLConnection httpConn, int chunkLength, HttpRequestMethod httpMethod, String contentType) throws UtilsException{
  549.        
  550.         HttpBodyParameters params = new HttpBodyParameters(httpMethod, contentType);
  551.        
  552.         // Devo impostarlo solo se e' previsto un output
  553.         if(params.isDoOutput()){
  554.             httpConn.setChunkedStreamingMode(chunkLength);
  555.         }
  556.     }
  557.    
  558.     public static boolean isHttpBodyPermitted(boolean isRequest,HttpRequestMethod httpMethod, String contentType) throws UtilsException{
  559.        
  560.         HttpBodyParameters params = new HttpBodyParameters(httpMethod, contentType);
  561.         if(isRequest){
  562.             return params.isDoOutput();
  563.         }
  564.         else{
  565.             return params.isDoInput();
  566.         }
  567.        
  568.     }
  569.    

  570.     public static void setStream(HttpURLConnection httpConn, HttpRequestMethod httpMethod) throws UtilsException{
  571.         setStream(httpConn, httpMethod, null);
  572.     }
  573.     public static void setStream(HttpURLConnection httpConn, HttpRequestMethod httpMethod, String contentType) throws UtilsException{
  574.         try{
  575.             HttpBodyParameters params = new HttpBodyParameters(httpMethod, contentType);
  576.                        
  577.             setHttpMethod(httpConn, httpMethod);
  578.             if(params.isDoOutput()){
  579.                 httpConn.setDoOutput(params.isDoOutput());
  580.             }
  581.             if(params.isDoInput()){
  582.                 httpConn.setDoInput(params.isDoInput());
  583.             }
  584.         }catch(Exception e){
  585.             throw new UtilsException(e.getMessage(),e);
  586.         }
  587.     }
  588.     public static void setHttpMethod(HttpURLConnection httpConn, HttpRequestMethod httpMethod) throws UtilsException {

  589.         // NOTA: comunque l'invio di metodi PATCH,LINK,... funzionano solo con java 8
  590.        
  591.         try {
  592.             if(httpMethod.isStandardMethod()) {
  593.                 httpConn.setRequestMethod(httpMethod.name());
  594.             }
  595.             else {
  596.                 // Fix errore:
  597.                 //java.net.ProtocolException: HTTP method PATCH doesn't support output
  598.                 //  at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1081)
  599.                 try {
  600.                     Object objectModifyMethodField = httpConn;
  601.                    
  602.                      Class<?> classHttpsUrlConnectionImpl = getClassHttpsURLConnectionImpl(); // all'interno c'e' un delegate su cui deve essere impostato il metodo http
  603.                    
  604.                     // Change protected field "method" of public class HttpURLConnection
  605.                     // Nella classe  HttpsURLConnectionImpl il field "method" non viene ereditato dalla superclasse ma deve essere modificato nell'oggetto 'delegate'
  606.                     if(classHttpsUrlConnectionImpl!=null && httpConn.getClass().isAssignableFrom(classHttpsUrlConnectionImpl)) {
  607.                         // Devo gestire il delegate
  608.                         /**System.out.println("GESTIONE HTTPS");*/
  609.                         objectModifyMethodField = readDelegateHttpsURLConnection(classHttpsUrlConnectionImpl, httpConn);
  610.                     }
  611.                    
  612.                     setProtectedFieldValue(HttpURLConnection.class, "method", objectModifyMethodField, httpMethod.name());
  613.                     /**System.out.println("DOPO '"+httpConn.getRequestMethod()+"'");*/
  614.                 } catch (Throwable ex) {
  615.                     throw new Exception("Unsupported Method '"+httpMethod+"' and set by reflection error: "+ex.getMessage(),ex);
  616.                 }
  617.             }
  618.         }catch(Exception e){
  619.             throw new UtilsException(e.getMessage(),e);
  620.         }
  621.     }
  622.     private static void setProtectedFieldValue(Class<?> clazz, String fieldName, Object object, Object newValue) throws Exception {
  623.                
  624.         /**System.out.println("SET IN '"+object.getClass().getName()+"'");*/
  625.        
  626.         Field field = getField(clazz, fieldName);

  627.         field.setAccessible(true);
  628.         field.set(object, newValue);
  629.        
  630.         /**System.out.println("SET OK IN '"+object.getClass().getName()+"' (field:"+field.getName()+"): "+field.get(object));*/
  631.     }
  632.     private static Field getField(Class<?> clazz, String fieldName) throws UtilsException {
  633.         Field field = null;
  634.         try {
  635.             field = clazz.getDeclaredField(fieldName);
  636.         }catch(Exception e) {
  637.             Field [] f = clazz.getDeclaredFields();
  638.             System.out.println("================= (size:"+f.length+" class:"+clazz.getName()+" fieldName:"+fieldName+") ==========================");
  639.             for (int i = 0; i < f.length; i++) {
  640.                 System.out.println("NOME["+f[i].getName()+"] TIPO["+f[i].getType()+"]");
  641.             }
  642.             f = clazz.getFields();
  643.             System.out.println("================= (FIELDS size:"+f.length+" class:"+clazz.getName()+" fieldName:"+fieldName+") ==========================");
  644.             for (int i = 0; i < f.length; i++) {
  645.                 System.out.println("NOME["+f[i].getName()+"] TIPO["+f[i].getType()+"]");
  646.             }
  647.             throw new UtilsException(e.getMessage(),e);
  648.         }
  649.         return field;
  650.     }
  651.     private static Class<?> classHttpsURLConnectionImpl = null;
  652.     private static Boolean classHttpsURLConnectionImplRead = null;
  653.     private static synchronized void initClassHttpsURLConnectionImpl() {
  654.         if(classHttpsURLConnectionImplRead==null) {
  655.             try {
  656.                 classHttpsURLConnectionImpl = Class.forName("sun.net.www.protocol.https.HttpsURLConnectionImpl");
  657.             }catch(Exception e) {
  658.                 System.out.println("Classe 'sun.net.www.protocol.https.HttpsURLConnectionImpl' non esistente: "+e.getMessage());
  659.             } finally {
  660.                 classHttpsURLConnectionImplRead = true;
  661.             }
  662.         }
  663.     }
  664.     private static Class<?> getClassHttpsURLConnectionImpl() {
  665.         if(classHttpsURLConnectionImplRead==null) {
  666.             initClassHttpsURLConnectionImpl();
  667.         }
  668.         return classHttpsURLConnectionImpl;
  669.     }
  670.     private static Object readDelegateHttpsURLConnection(Class<?> classHttpsUrlConnectionImpl, HttpURLConnection httpConn) throws IllegalArgumentException, IllegalAccessException, UtilsException {
  671.         Field field = getField(classHttpsUrlConnectionImpl, "delegate");
  672.         field.setAccessible(true);
  673.         Object fieldInstance = field.get(httpConn);
  674.         /**System.out.println("Delegate '"+fieldInstance.getClass().getName()+"'");*/
  675.         return fieldInstance;
  676.     }


  677.    
  678.    
  679.     /* ********* HTTP INVOKE ************ */

  680.     // getHTTPResponse (no options)
  681.    
  682.     public static byte[] requestHTTPFile(String path) throws UtilsException{
  683.         return requestHTTPFile(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  684.                 (HttpOptions[]) null);
  685.     }
  686.     public static byte[] requestHTTPFile(String path,int readTimeout,int connectTimeout) throws UtilsException{
  687.         return requestHTTPFile(path, readTimeout, connectTimeout, null, null,
  688.                 (HttpOptions[]) null);
  689.     }
  690.     public static byte[] requestHTTPFile(String path,String username,String password) throws UtilsException{
  691.         return requestHTTPFile(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  692.                 (HttpOptions[]) null);
  693.     }  
  694.     public static byte[] requestHTTPFile(String path,int readTimeout,int connectTimeout,String username,String password) throws UtilsException{
  695.         HttpResponse res = getHTTPResponse(path, readTimeout, connectTimeout, username, password,
  696.                 (HttpOptions[]) null);
  697.         return res.getContent();
  698.     }
  699.     public static HttpResponse getHTTPResponse(String path) throws UtilsException{
  700.         return getHTTPResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  701.                 (HttpOptions[]) null);
  702.     }
  703.     public static HttpResponse getHTTPResponse(String path,int readTimeout,int connectTimeout) throws UtilsException{
  704.         return getHTTPResponse(path, readTimeout, connectTimeout, null, null,
  705.                 (HttpOptions[]) null);
  706.     }
  707.     public static HttpResponse getHTTPResponse(String path,String username,String password) throws UtilsException{
  708.         return getHTTPResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  709.                 (HttpOptions[]) null);
  710.     }
  711.    
  712.     public static HttpResponse getHTTPResponse(String path,int readTimeout,int connectTimeout,String username,String password) throws UtilsException{
  713.         return getHTTPResponse(path, readTimeout, connectTimeout, username, password,
  714.                 (HttpOptions[]) null);
  715.     }
  716.    
  717.    
  718.     // getHTTPResponse (options)
  719.    
  720.     public static byte[] requestHTTPFile(String path,
  721.             HttpOptions ... options) throws UtilsException{
  722.         return requestHTTPFile(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  723.                 options);
  724.     }
  725.     public static byte[] requestHTTPFile(String path,int readTimeout,int connectTimeout,
  726.             HttpOptions ... options) throws UtilsException{
  727.         return requestHTTPFile(path, readTimeout, connectTimeout, null, null,
  728.                 options);
  729.     }
  730.     public static byte[] requestHTTPFile(String path,String username,String password,
  731.             HttpOptions ... options) throws UtilsException{
  732.         return requestHTTPFile(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  733.                 options);
  734.     }  
  735.     public static byte[] requestHTTPFile(String path,int readTimeout,int connectTimeout,String username,String password,
  736.             HttpOptions ... options) throws UtilsException{
  737.         HttpResponse res = getHTTPResponse(path, readTimeout, connectTimeout, username, password,
  738.                 options);
  739.         return res.getContent();
  740.     }
  741.     public static HttpResponse getHTTPResponse(String path,
  742.             HttpOptions ... options) throws UtilsException{
  743.         return getHTTPResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  744.                 options);
  745.     }
  746.     public static HttpResponse getHTTPResponse(String path,int readTimeout,int connectTimeout,
  747.             HttpOptions ... options) throws UtilsException{
  748.         return getHTTPResponse(path, readTimeout, connectTimeout, null, null,
  749.                 options);
  750.     }
  751.     public static HttpResponse getHTTPResponse(String path,String username,String password,
  752.             HttpOptions ... options) throws UtilsException{
  753.         return getHTTPResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  754.                 options);
  755.     }  
  756.     public static HttpResponse getHTTPResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  757.             HttpOptions ... options) throws UtilsException{
  758.        
  759.         HttpRequest httpRequest = new HttpRequest();
  760.         httpRequest.setUrl(path);
  761.         httpRequest.setReadTimeout(readTimeout);
  762.         httpRequest.setConnectTimeout(connectTimeout);
  763.         httpRequest.setUsername(username);
  764.         httpRequest.setPassword(password);
  765.         httpRequest.setMethod(HttpRequestMethod.GET);
  766.        
  767.         if(options!=null && options.length>0) {
  768.             for (HttpOptions httpOptions : options) {
  769.                 httpOptions.fill(httpRequest);
  770.             }
  771.         }
  772.        
  773.         HttpResponse response = null;
  774.         try{
  775.             response = httpInvoke(httpRequest);
  776.            
  777.         }catch(Exception e){
  778.             throw new UtilsException("Utilities.requestHTTPFile error "+e.getMessage(),e);
  779.         }
  780.         if(response.getResultHTTPOperation()==404){
  781.             throw new UtilsException("404");
  782.         }
  783.         return response;
  784.        
  785.     }
  786.    
  787.    
  788.    
  789.    
  790.    
  791.     // getHTTPSResponse (no options)
  792.    
  793.     public static byte[] requestHTTPSFile(String path,
  794.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  795.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  796.                 trustStore, trustStorePassword, trustStoreType,
  797.                 null, null,
  798.                 (HttpOptions[]) null);
  799.         return res.getContent();
  800.     }
  801.     public static byte[] requestHTTPSFile(String path,
  802.             String trustStore, String trustStorePassword, String trustStoreType,
  803.             String crlPath) throws UtilsException{
  804.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  805.                 trustStore, trustStorePassword, trustStoreType,
  806.                 crlPath, null,
  807.                 (HttpOptions[]) null);
  808.         return res.getContent();
  809.     }
  810.     public static byte[] requestHTTPSFile(String path,
  811.             String trustStore, String trustStorePassword, String trustStoreType,
  812.             IOCSPValidator ocspValidator) throws UtilsException{
  813.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  814.                 trustStore, trustStorePassword, trustStoreType,
  815.                 null, ocspValidator,
  816.                 (HttpOptions[]) null);
  817.         return res.getContent();
  818.     }
  819.     public static byte[] requestHTTPSFile(String path,
  820.             String trustStore, String trustStorePassword, String trustStoreType,
  821.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  822.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  823.                 trustStore, trustStorePassword, trustStoreType,
  824.                 crlPath, ocspValidator,
  825.                 (HttpOptions[]) null);
  826.         return res.getContent();
  827.     }
  828.    
  829.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  830.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  831.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  832.                 trustStore, trustStorePassword, trustStoreType,
  833.                 null, null,
  834.                 (HttpOptions[]) null);
  835.         return res.getContent();
  836.     }
  837.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  838.             String trustStore, String trustStorePassword, String trustStoreType,
  839.             String crlPath) throws UtilsException{
  840.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  841.                 trustStore, trustStorePassword, trustStoreType,
  842.                 crlPath, null,
  843.                 (HttpOptions[]) null);
  844.         return res.getContent();
  845.     }
  846.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  847.             String trustStore, String trustStorePassword, String trustStoreType,
  848.             IOCSPValidator ocspValidator) throws UtilsException{
  849.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  850.                 trustStore, trustStorePassword, trustStoreType,
  851.                 null, ocspValidator,
  852.                 (HttpOptions[]) null);
  853.         return res.getContent();
  854.     }
  855.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  856.             String trustStore, String trustStorePassword, String trustStoreType,
  857.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  858.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  859.                 trustStore, trustStorePassword, trustStoreType,
  860.                 crlPath, ocspValidator,
  861.                 (HttpOptions[]) null);
  862.         return res.getContent();
  863.     }
  864.    
  865.     public static byte[] requestHTTPSFile(String path,String username,String password,
  866.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  867.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  868.                 trustStore, trustStorePassword, trustStoreType,
  869.                 null, null,
  870.                 (HttpOptions[]) null);
  871.         return res.getContent();
  872.     }
  873.     public static byte[] requestHTTPSFile(String path,String username,String password,
  874.             String trustStore, String trustStorePassword, String trustStoreType,
  875.             String crlPath) throws UtilsException{
  876.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  877.                 trustStore, trustStorePassword, trustStoreType,
  878.                 crlPath, null,
  879.                 (HttpOptions[]) null);
  880.         return res.getContent();
  881.     }  
  882.     public static byte[] requestHTTPSFile(String path,String username,String password,
  883.             String trustStore, String trustStorePassword, String trustStoreType,
  884.             IOCSPValidator ocspValidator) throws UtilsException{
  885.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  886.                 trustStore, trustStorePassword, trustStoreType,
  887.                 null, ocspValidator,
  888.                 (HttpOptions[]) null);
  889.         return res.getContent();
  890.     }  
  891.     public static byte[] requestHTTPSFile(String path,String username,String password,
  892.             String trustStore, String trustStorePassword, String trustStoreType,
  893.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  894.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  895.                 trustStore, trustStorePassword, trustStoreType,
  896.                 crlPath, ocspValidator,
  897.                 (HttpOptions[]) null);
  898.         return res.getContent();
  899.     }  
  900.    
  901.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  902.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  903.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  904.                 trustStore, trustStorePassword, trustStoreType,
  905.                 null, null,
  906.                 (HttpOptions[]) null);
  907.         return res.getContent();
  908.     }
  909.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  910.             String trustStore, String trustStorePassword, String trustStoreType,
  911.             String crlPath) throws UtilsException{
  912.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  913.                 trustStore, trustStorePassword, trustStoreType,
  914.                 crlPath, null,
  915.                 (HttpOptions[]) null);
  916.         return res.getContent();
  917.     }
  918.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  919.             String trustStore, String trustStorePassword, String trustStoreType,
  920.             IOCSPValidator ocspValidator) throws UtilsException{
  921.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  922.                 trustStore, trustStorePassword, trustStoreType,
  923.                 null, ocspValidator,
  924.                 (HttpOptions[]) null);
  925.         return res.getContent();
  926.     }
  927.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  928.             String trustStore, String trustStorePassword, String trustStoreType,
  929.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  930.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  931.                 trustStore, trustStorePassword, trustStoreType,
  932.                 null, ocspValidator,
  933.                 (HttpOptions[]) null);
  934.         return res.getContent();
  935.     }
  936.    
  937.     public static HttpResponse getHTTPSResponse(String path,
  938.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  939.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  940.                 trustStore, trustStorePassword, trustStoreType,
  941.                 null, null,
  942.                 (HttpOptions[]) null);
  943.     }
  944.     public static HttpResponse getHTTPSResponse(String path,
  945.             String trustStore, String trustStorePassword, String trustStoreType,
  946.             String crlPath) throws UtilsException{
  947.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  948.                 trustStore, trustStorePassword, trustStoreType,
  949.                 crlPath, null,
  950.                 (HttpOptions[]) null);
  951.     }
  952.     public static HttpResponse getHTTPSResponse(String path,
  953.             String trustStore, String trustStorePassword, String trustStoreType,
  954.             IOCSPValidator ocspValidator) throws UtilsException{
  955.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  956.                 trustStore, trustStorePassword, trustStoreType,
  957.                 null, ocspValidator,
  958.                 (HttpOptions[]) null);
  959.     }
  960.     public static HttpResponse getHTTPSResponse(String path,
  961.             String trustStore, String trustStorePassword, String trustStoreType,
  962.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  963.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  964.                 trustStore, trustStorePassword, trustStoreType,
  965.                 crlPath, ocspValidator,
  966.                 (HttpOptions[]) null);
  967.     }
  968.    
  969.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  970.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  971.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  972.                 trustStore, trustStorePassword, trustStoreType,
  973.                 null, null,
  974.                 (HttpOptions[]) null);
  975.     }
  976.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  977.             String trustStore, String trustStorePassword, String trustStoreType,
  978.             String crlPath) throws UtilsException{
  979.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  980.                 trustStore, trustStorePassword, trustStoreType,
  981.                 crlPath, null,
  982.                 (HttpOptions[]) null);
  983.     }
  984.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  985.             String trustStore, String trustStorePassword, String trustStoreType,
  986.             IOCSPValidator ocspValidator) throws UtilsException{
  987.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  988.                 trustStore, trustStorePassword, trustStoreType,
  989.                 null, ocspValidator,
  990.                 (HttpOptions[]) null);
  991.     }
  992.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  993.             String trustStore, String trustStorePassword, String trustStoreType,
  994.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  995.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  996.                 trustStore, trustStorePassword, trustStoreType,
  997.                 crlPath, ocspValidator,
  998.                 (HttpOptions[]) null);
  999.     }
  1000.    
  1001.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1002.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  1003.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1004.                 trustStore, trustStorePassword, trustStoreType,
  1005.                 null, null,
  1006.                 (HttpOptions[]) null);
  1007.     }
  1008.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1009.             String trustStore, String trustStorePassword, String trustStoreType,
  1010.             String crlPath) throws UtilsException{
  1011.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1012.                 trustStore, trustStorePassword, trustStoreType,
  1013.                 crlPath, null,
  1014.                 (HttpOptions[]) null);
  1015.     }
  1016.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1017.             String trustStore, String trustStorePassword, String trustStoreType,
  1018.             IOCSPValidator ocspValidator) throws UtilsException{
  1019.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1020.                 trustStore, trustStorePassword, trustStoreType,
  1021.                 null, ocspValidator,
  1022.                 (HttpOptions[]) null);
  1023.     }
  1024.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1025.             String trustStore, String trustStorePassword, String trustStoreType,
  1026.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  1027.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1028.                 trustStore, trustStorePassword, trustStoreType,
  1029.                 crlPath, ocspValidator,
  1030.                 (HttpOptions[]) null);
  1031.     }
  1032.    
  1033.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1034.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException{
  1035.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1036.                 trustStore, trustStorePassword, trustStoreType,
  1037.                 null, null,
  1038.                 (HttpOptions[]) null);
  1039.     }
  1040.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1041.             String trustStore, String trustStorePassword, String trustStoreType,
  1042.             String crlPath) throws UtilsException{
  1043.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1044.                 trustStore, trustStorePassword, trustStoreType,
  1045.                 crlPath, null,
  1046.                 (HttpOptions[]) null);
  1047.     }
  1048.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1049.             String trustStore, String trustStorePassword, String trustStoreType,
  1050.             IOCSPValidator ocspValidator) throws UtilsException{
  1051.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1052.                 trustStore, trustStorePassword, trustStoreType,
  1053.                 null, ocspValidator,
  1054.                 (HttpOptions[]) null);
  1055.     }
  1056.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1057.             String trustStore, String trustStorePassword, String trustStoreType,
  1058.             String crlPath, IOCSPValidator ocspValidator) throws UtilsException{
  1059.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1060.                 trustStore, trustStorePassword, trustStoreType,
  1061.                 crlPath, ocspValidator,
  1062.                 (HttpOptions[]) null);
  1063.     }
  1064.    
  1065.    
  1066.     // getHTTPSResponse (options)
  1067.    
  1068.     public static byte[] requestHTTPSFile(String path,
  1069.             String trustStore, String trustStorePassword, String trustStoreType,
  1070.             HttpOptions ... options) throws UtilsException{
  1071.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1072.                 trustStore, trustStorePassword, trustStoreType,
  1073.                 null, null,
  1074.                 options);
  1075.         return res.getContent();
  1076.     }
  1077.     public static byte[] requestHTTPSFile(String path,
  1078.             String trustStore, String trustStorePassword, String trustStoreType,
  1079.             String crlPath,
  1080.             HttpOptions ... options) throws UtilsException{
  1081.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1082.                 trustStore, trustStorePassword, trustStoreType,
  1083.                 crlPath, null,
  1084.                 options);
  1085.         return res.getContent();
  1086.     }
  1087.     public static byte[] requestHTTPSFile(String path,
  1088.             String trustStore, String trustStorePassword, String trustStoreType,
  1089.             IOCSPValidator ocspValidator,
  1090.             HttpOptions ... options) throws UtilsException{
  1091.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1092.                 trustStore, trustStorePassword, trustStoreType,
  1093.                 null, ocspValidator,
  1094.                 options);
  1095.         return res.getContent();
  1096.     }
  1097.     public static byte[] requestHTTPSFile(String path,
  1098.             String trustStore, String trustStorePassword, String trustStoreType,
  1099.             String crlPath, IOCSPValidator ocspValidator,
  1100.             HttpOptions ... options) throws UtilsException{
  1101.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1102.                 trustStore, trustStorePassword, trustStoreType,
  1103.                 crlPath, ocspValidator,
  1104.                 options);
  1105.         return res.getContent();
  1106.     }
  1107.    
  1108.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1109.             String trustStore, String trustStorePassword, String trustStoreType,
  1110.             HttpOptions ... options) throws UtilsException{
  1111.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1112.                 trustStore, trustStorePassword, trustStoreType,
  1113.                 null, null,
  1114.                 options);
  1115.         return res.getContent();
  1116.     }
  1117.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1118.             String trustStore, String trustStorePassword, String trustStoreType,
  1119.             String crlPath,
  1120.             HttpOptions ... options) throws UtilsException{
  1121.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1122.                 trustStore, trustStorePassword, trustStoreType,
  1123.                 crlPath, null,
  1124.                 options);
  1125.         return res.getContent();
  1126.     }
  1127.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1128.             String trustStore, String trustStorePassword, String trustStoreType,
  1129.             IOCSPValidator ocspValidator,
  1130.             HttpOptions ... options) throws UtilsException{
  1131.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1132.                 trustStore, trustStorePassword, trustStoreType,
  1133.                 null, ocspValidator,
  1134.                 options);
  1135.         return res.getContent();
  1136.     }
  1137.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1138.             String trustStore, String trustStorePassword, String trustStoreType,
  1139.             String crlPath, IOCSPValidator ocspValidator,
  1140.             HttpOptions ... options) throws UtilsException{
  1141.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1142.                 trustStore, trustStorePassword, trustStoreType,
  1143.                 crlPath, ocspValidator,
  1144.                 options);
  1145.         return res.getContent();
  1146.     }
  1147.    
  1148.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1149.             String trustStore, String trustStorePassword, String trustStoreType,
  1150.             HttpOptions ... options) throws UtilsException{
  1151.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1152.                 trustStore, trustStorePassword, trustStoreType,
  1153.                 null, null,
  1154.                 options);
  1155.         return res.getContent();
  1156.     }
  1157.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1158.             String trustStore, String trustStorePassword, String trustStoreType,
  1159.             String crlPath,
  1160.             HttpOptions ... options) throws UtilsException{
  1161.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1162.                 trustStore, trustStorePassword, trustStoreType,
  1163.                 crlPath, null,
  1164.                 options);
  1165.         return res.getContent();
  1166.     }  
  1167.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1168.             String trustStore, String trustStorePassword, String trustStoreType,
  1169.             IOCSPValidator ocspValidator,
  1170.             HttpOptions ... options) throws UtilsException{
  1171.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1172.                 trustStore, trustStorePassword, trustStoreType,
  1173.                 null, ocspValidator,
  1174.                 options);
  1175.         return res.getContent();
  1176.     }  
  1177.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1178.             String trustStore, String trustStorePassword, String trustStoreType,
  1179.             String crlPath, IOCSPValidator ocspValidator,
  1180.             HttpOptions ... options) throws UtilsException{
  1181.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1182.                 trustStore, trustStorePassword, trustStoreType,
  1183.                 crlPath, ocspValidator,
  1184.                 options);
  1185.         return res.getContent();
  1186.     }  
  1187.    
  1188.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1189.             String trustStore, String trustStorePassword, String trustStoreType,
  1190.             HttpOptions ... options) throws UtilsException{
  1191.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1192.                 trustStore, trustStorePassword, trustStoreType,
  1193.                 null, null,
  1194.                 options);
  1195.         return res.getContent();
  1196.     }
  1197.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1198.             String trustStore, String trustStorePassword, String trustStoreType,
  1199.             String crlPath,
  1200.             HttpOptions ... options) throws UtilsException{
  1201.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1202.                 trustStore, trustStorePassword, trustStoreType,
  1203.                 crlPath, null,
  1204.                 options);
  1205.         return res.getContent();
  1206.     }
  1207.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1208.             String trustStore, String trustStorePassword, String trustStoreType,
  1209.             IOCSPValidator ocspValidator,
  1210.             HttpOptions ... options) throws UtilsException{
  1211.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1212.                 trustStore, trustStorePassword, trustStoreType,
  1213.                 null, ocspValidator,
  1214.                 options);
  1215.         return res.getContent();
  1216.     }
  1217.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1218.             String trustStore, String trustStorePassword, String trustStoreType,
  1219.             String crlPath, IOCSPValidator ocspValidator,
  1220.             HttpOptions ... options) throws UtilsException{
  1221.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1222.                 trustStore, trustStorePassword, trustStoreType,
  1223.                 null, ocspValidator,
  1224.                 options);
  1225.         return res.getContent();
  1226.     }
  1227.    
  1228.     public static HttpResponse getHTTPSResponse(String path,
  1229.             String trustStore, String trustStorePassword, String trustStoreType,
  1230.             HttpOptions ... options) throws UtilsException{
  1231.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1232.                 trustStore, trustStorePassword, trustStoreType,
  1233.                 null, null,
  1234.                 options);
  1235.     }
  1236.     public static HttpResponse getHTTPSResponse(String path,
  1237.             String trustStore, String trustStorePassword, String trustStoreType,
  1238.             String crlPath,
  1239.             HttpOptions ... options) throws UtilsException{
  1240.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1241.                 trustStore, trustStorePassword, trustStoreType,
  1242.                 crlPath, null,
  1243.                 options);
  1244.     }
  1245.     public static HttpResponse getHTTPSResponse(String path,
  1246.             String trustStore, String trustStorePassword, String trustStoreType,
  1247.             IOCSPValidator ocspValidator,
  1248.             HttpOptions ... options) throws UtilsException{
  1249.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1250.                 trustStore, trustStorePassword, trustStoreType,
  1251.                 null, ocspValidator,
  1252.                 options);
  1253.     }
  1254.     public static HttpResponse getHTTPSResponse(String path,
  1255.             String trustStore, String trustStorePassword, String trustStoreType,
  1256.             String crlPath, IOCSPValidator ocspValidator,
  1257.             HttpOptions ... options) throws UtilsException{
  1258.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1259.                 trustStore, trustStorePassword, trustStoreType,
  1260.                 crlPath, ocspValidator,
  1261.                 options);
  1262.     }
  1263.    
  1264.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1265.             String trustStore, String trustStorePassword, String trustStoreType,
  1266.             HttpOptions ... options) throws UtilsException{
  1267.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1268.                 trustStore, trustStorePassword, trustStoreType,
  1269.                 null, null,
  1270.                 options);
  1271.     }
  1272.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1273.             String trustStore, String trustStorePassword, String trustStoreType,
  1274.             String crlPath,
  1275.             HttpOptions ... options) throws UtilsException{
  1276.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1277.                 trustStore, trustStorePassword, trustStoreType,
  1278.                 crlPath, null,
  1279.                 options);
  1280.     }
  1281.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1282.             String trustStore, String trustStorePassword, String trustStoreType,
  1283.             IOCSPValidator ocspValidator,
  1284.             HttpOptions ... options) throws UtilsException{
  1285.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1286.                 trustStore, trustStorePassword, trustStoreType,
  1287.                 null, ocspValidator,
  1288.                 options);
  1289.     }
  1290.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1291.             String trustStore, String trustStorePassword, String trustStoreType,
  1292.             String crlPath, IOCSPValidator ocspValidator,
  1293.             HttpOptions ... options) throws UtilsException{
  1294.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1295.                 trustStore, trustStorePassword, trustStoreType,
  1296.                 crlPath, ocspValidator,
  1297.                 options);
  1298.     }
  1299.    
  1300.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1301.             String trustStore, String trustStorePassword, String trustStoreType,
  1302.             HttpOptions ... options) throws UtilsException{
  1303.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1304.                 trustStore, trustStorePassword, trustStoreType,
  1305.                 null, null,
  1306.                 options);
  1307.     }
  1308.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1309.             String trustStore, String trustStorePassword, String trustStoreType,
  1310.             String crlPath,
  1311.             HttpOptions ... options) throws UtilsException{
  1312.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1313.                 trustStore, trustStorePassword, trustStoreType,
  1314.                 crlPath, null,
  1315.                 options);
  1316.     }
  1317.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1318.             String trustStore, String trustStorePassword, String trustStoreType,
  1319.             IOCSPValidator ocspValidator,
  1320.             HttpOptions ... options) throws UtilsException{
  1321.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1322.                 trustStore, trustStorePassword, trustStoreType,
  1323.                 null, ocspValidator,
  1324.                 options);
  1325.     }
  1326.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1327.             String trustStore, String trustStorePassword, String trustStoreType,
  1328.             String crlPath, IOCSPValidator ocspValidator,
  1329.             HttpOptions ... options) throws UtilsException{
  1330.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1331.                 trustStore, trustStorePassword, trustStoreType,
  1332.                 crlPath, ocspValidator,
  1333.                 options);
  1334.     }
  1335.    
  1336.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1337.             String trustStore, String trustStorePassword, String trustStoreType,
  1338.             HttpOptions ... options) throws UtilsException{
  1339.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1340.                 trustStore, trustStorePassword, trustStoreType,
  1341.                 null, null,
  1342.                 options);
  1343.     }
  1344.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1345.             String trustStore, String trustStorePassword, String trustStoreType,
  1346.             String crlPath,
  1347.             HttpOptions ... options) throws UtilsException{
  1348.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1349.                 trustStore, trustStorePassword, trustStoreType,
  1350.                 crlPath, null,
  1351.                 options);
  1352.     }
  1353.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1354.             String trustStore, String trustStorePassword, String trustStoreType,
  1355.             IOCSPValidator ocspValidator,
  1356.             HttpOptions ... options) throws UtilsException{
  1357.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1358.                 trustStore, trustStorePassword, trustStoreType,
  1359.                 null, ocspValidator,
  1360.                 options);
  1361.     }
  1362.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1363.             String trustStore, String trustStorePassword, String trustStoreType,
  1364.             String crlPath, IOCSPValidator ocspValidator,
  1365.             HttpOptions ... options) throws UtilsException{
  1366.        
  1367.         HttpRequest httpRequest = new HttpRequest();
  1368.         httpRequest.setUrl(path);
  1369.         httpRequest.setReadTimeout(readTimeout);
  1370.         httpRequest.setConnectTimeout(connectTimeout);
  1371.         httpRequest.setUsername(username);
  1372.         httpRequest.setPassword(password);
  1373.         httpRequest.setMethod(HttpRequestMethod.GET);
  1374.        
  1375.         httpRequest.setTrustStorePath(trustStore);
  1376.         httpRequest.setTrustStorePassword(trustStorePassword);
  1377.         httpRequest.setTrustStoreType(trustStoreType);
  1378.         httpRequest.setCrlPath(crlPath);
  1379.         httpRequest.setOcspValidator(ocspValidator);
  1380.        
  1381.         if(options!=null && options.length>0) {
  1382.             for (HttpOptions httpOptions : options) {
  1383.                 httpOptions.fill(httpRequest);
  1384.             }
  1385.         }
  1386.        
  1387.         HttpResponse response = null;
  1388.         try{
  1389.             response = httpInvoke(httpRequest);
  1390.            
  1391.         }catch(Exception e){
  1392.             throw new UtilsException("Utilities.requestHTTPFile error "+e.getMessage(),e);
  1393.         }
  1394.         if(response.getResultHTTPOperation()==404){
  1395.             throw new UtilsException("404");
  1396.         }
  1397.         return response;
  1398.        
  1399.     }
  1400.    
  1401.    
  1402.    
  1403.     // getHTTPSResponse (no options)
  1404.    
  1405.     public static byte[] requestHTTPSFile(String path,
  1406.             KeyStore trustStore) throws UtilsException{
  1407.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1408.                 trustStore, null, null,
  1409.                 (HttpOptions[]) null);
  1410.         return res.getContent();
  1411.     }
  1412.     public static byte[] requestHTTPSFile(String path,
  1413.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1414.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1415.                 trustStore, crlStore, null,
  1416.                 (HttpOptions[]) null);
  1417.         return res.getContent();
  1418.     }
  1419.     public static byte[] requestHTTPSFile(String path,
  1420.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1421.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1422.                 trustStore, null, ocspValidator,
  1423.                 (HttpOptions[]) null);
  1424.         return res.getContent();
  1425.     }
  1426.     public static byte[] requestHTTPSFile(String path,
  1427.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1428.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1429.                 trustStore, crlStore, ocspValidator,
  1430.                 (HttpOptions[]) null);
  1431.         return res.getContent();
  1432.     }
  1433.    
  1434.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1435.             KeyStore trustStore) throws UtilsException{
  1436.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1437.                 trustStore, null, null,
  1438.                 (HttpOptions[]) null);
  1439.         return res.getContent();
  1440.     }
  1441.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1442.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1443.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1444.                 trustStore, crlStore, null,
  1445.                 (HttpOptions[]) null);
  1446.         return res.getContent();
  1447.     }
  1448.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1449.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1450.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1451.                 trustStore, null, ocspValidator,
  1452.                 (HttpOptions[]) null);
  1453.         return res.getContent();
  1454.     }
  1455.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1456.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1457.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1458.                 trustStore, crlStore, ocspValidator,
  1459.                 (HttpOptions[]) null);
  1460.         return res.getContent();
  1461.     }
  1462.    
  1463.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1464.             KeyStore trustStore) throws UtilsException{
  1465.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1466.                 trustStore, null, null,
  1467.                 (HttpOptions[]) null);
  1468.         return res.getContent();
  1469.     }
  1470.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1471.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1472.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1473.                 trustStore, crlStore, null,
  1474.                 (HttpOptions[]) null);
  1475.         return res.getContent();
  1476.     }
  1477.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1478.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1479.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1480.                 trustStore, null, ocspValidator,
  1481.                 (HttpOptions[]) null);
  1482.         return res.getContent();
  1483.     }
  1484.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1485.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1486.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1487.                 trustStore, crlStore, ocspValidator,
  1488.                 (HttpOptions[]) null);
  1489.         return res.getContent();
  1490.     }
  1491.    
  1492.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1493.             KeyStore trustStore) throws UtilsException{
  1494.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1495.                 trustStore, null, null,
  1496.                 (HttpOptions[]) null);
  1497.         return res.getContent();
  1498.     }
  1499.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1500.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1501.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1502.                 trustStore, crlStore, null,
  1503.                 (HttpOptions[]) null);
  1504.         return res.getContent();
  1505.     }
  1506.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1507.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1508.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1509.                 trustStore, null, ocspValidator,
  1510.                 (HttpOptions[]) null);
  1511.         return res.getContent();
  1512.     }
  1513.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1514.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1515.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1516.                 trustStore, crlStore, ocspValidator,
  1517.                 (HttpOptions[]) null);
  1518.         return res.getContent();
  1519.     }
  1520.    
  1521.     public static HttpResponse getHTTPSResponse(String path,
  1522.             KeyStore trustStore) throws UtilsException{
  1523.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1524.                 trustStore, null, null,
  1525.                 (HttpOptions[]) null);
  1526.     }
  1527.     public static HttpResponse getHTTPSResponse(String path,
  1528.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1529.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1530.                 trustStore, crlStore, null,
  1531.                 (HttpOptions[]) null);
  1532.     }
  1533.     public static HttpResponse getHTTPSResponse(String path,
  1534.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1535.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1536.                 trustStore, null, ocspValidator,
  1537.                 (HttpOptions[]) null);
  1538.     }
  1539.     public static HttpResponse getHTTPSResponse(String path,
  1540.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1541.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1542.                 trustStore, crlStore, ocspValidator,
  1543.                 (HttpOptions[]) null);
  1544.     }
  1545.    
  1546.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1547.             KeyStore trustStore) throws UtilsException{
  1548.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1549.                 trustStore, null, null,
  1550.                 (HttpOptions[]) null);
  1551.     }
  1552.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1553.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1554.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1555.                 trustStore, crlStore, null,
  1556.                 (HttpOptions[]) null);
  1557.     }
  1558.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1559.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1560.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1561.                 trustStore, null, ocspValidator,
  1562.                 (HttpOptions[]) null);
  1563.     }
  1564.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1565.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1566.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1567.                 trustStore, crlStore, ocspValidator,
  1568.                 (HttpOptions[]) null);
  1569.     }
  1570.    
  1571.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1572.             KeyStore trustStore) throws UtilsException{
  1573.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1574.                 trustStore, null, null,
  1575.                 (HttpOptions[]) null);
  1576.     }
  1577.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1578.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1579.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1580.                 trustStore, crlStore, null,
  1581.                 (HttpOptions[]) null);
  1582.     }
  1583.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1584.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1585.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1586.                 trustStore, null, ocspValidator,
  1587.                 (HttpOptions[]) null);
  1588.     }
  1589.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1590.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1591.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1592.                 trustStore, crlStore, ocspValidator,
  1593.                 (HttpOptions[]) null);
  1594.     }
  1595.    
  1596.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1597.             KeyStore trustStore) throws UtilsException{
  1598.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1599.                 trustStore, null, null,
  1600.                 (HttpOptions[]) null);
  1601.     }
  1602.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1603.             KeyStore trustStore, CertStore crlStore) throws UtilsException{
  1604.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1605.                 trustStore, crlStore, null,
  1606.                 (HttpOptions[]) null);
  1607.     }
  1608.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1609.             KeyStore trustStore, IOCSPValidator ocspValidator) throws UtilsException{
  1610.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1611.                 trustStore, null, ocspValidator,
  1612.                 (HttpOptions[]) null);
  1613.     }
  1614.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1615.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator) throws UtilsException{
  1616.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1617.                 trustStore, crlStore, ocspValidator,
  1618.                 (HttpOptions[]) null);
  1619.     }
  1620.    
  1621.    
  1622.     // getHTTPSResponse (options)
  1623.    
  1624.     public static byte[] requestHTTPSFile(String path,
  1625.             KeyStore trustStore,
  1626.             HttpOptions ... options) throws UtilsException{
  1627.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1628.                 trustStore, null, null,
  1629.                 options);
  1630.         return res.getContent();
  1631.     }
  1632.     public static byte[] requestHTTPSFile(String path,
  1633.             KeyStore trustStore, CertStore crlStore,
  1634.             HttpOptions ... options) throws UtilsException{
  1635.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1636.                 trustStore, crlStore, null,
  1637.                 options);
  1638.         return res.getContent();
  1639.     }
  1640.     public static byte[] requestHTTPSFile(String path,
  1641.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1642.             HttpOptions ... options) throws UtilsException{
  1643.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1644.                 trustStore, null, ocspValidator,
  1645.                 options);
  1646.         return res.getContent();
  1647.     }
  1648.     public static byte[] requestHTTPSFile(String path,
  1649.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1650.             HttpOptions ... options) throws UtilsException{
  1651.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1652.                 trustStore, crlStore, ocspValidator,
  1653.                 options);
  1654.         return res.getContent();
  1655.     }
  1656.    
  1657.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1658.             KeyStore trustStore,
  1659.             HttpOptions ... options) throws UtilsException{
  1660.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1661.                 trustStore, null, null,
  1662.                 options);
  1663.         return res.getContent();
  1664.     }
  1665.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1666.             KeyStore trustStore, CertStore crlStore,
  1667.             HttpOptions ... options) throws UtilsException{
  1668.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1669.                 trustStore, crlStore, null,
  1670.                 options);
  1671.         return res.getContent();
  1672.     }
  1673.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1674.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1675.             HttpOptions ... options) throws UtilsException{
  1676.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1677.                 trustStore, null, ocspValidator,
  1678.                 options);
  1679.         return res.getContent();
  1680.     }
  1681.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,
  1682.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1683.             HttpOptions ... options) throws UtilsException{
  1684.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1685.                 trustStore, crlStore, ocspValidator,
  1686.                 options);
  1687.         return res.getContent();
  1688.     }
  1689.    
  1690.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1691.             KeyStore trustStore,
  1692.             HttpOptions ... options) throws UtilsException{
  1693.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1694.                 trustStore, null, null,
  1695.                 options);
  1696.         return res.getContent();
  1697.     }
  1698.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1699.             KeyStore trustStore, CertStore crlStore,
  1700.             HttpOptions ... options) throws UtilsException{
  1701.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1702.                 trustStore, crlStore, null,
  1703.                 options);
  1704.         return res.getContent();
  1705.     }
  1706.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1707.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1708.             HttpOptions ... options) throws UtilsException{
  1709.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1710.                 trustStore, null, ocspValidator,
  1711.                 options);
  1712.         return res.getContent();
  1713.     }
  1714.     public static byte[] requestHTTPSFile(String path,String username,String password,
  1715.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1716.             HttpOptions ... options) throws UtilsException{
  1717.         HttpResponse res = getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1718.                 trustStore, crlStore, ocspValidator,
  1719.                 options);
  1720.         return res.getContent();
  1721.     }
  1722.    
  1723.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1724.             KeyStore trustStore,
  1725.             HttpOptions ... options) throws UtilsException{
  1726.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1727.                 trustStore, null, null,
  1728.                 options);
  1729.         return res.getContent();
  1730.     }
  1731.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1732.             KeyStore trustStore, CertStore crlStore,
  1733.             HttpOptions ... options) throws UtilsException{
  1734.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1735.                 trustStore, crlStore, null,
  1736.                 options);
  1737.         return res.getContent();
  1738.     }
  1739.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1740.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1741.             HttpOptions ... options) throws UtilsException{
  1742.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1743.                 trustStore, null, ocspValidator,
  1744.                 options);
  1745.         return res.getContent();
  1746.     }
  1747.     public static byte[] requestHTTPSFile(String path,int readTimeout,int connectTimeout,String username,String password,
  1748.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1749.             HttpOptions ... options) throws UtilsException{
  1750.         HttpResponse res = getHTTPSResponse(path, readTimeout, connectTimeout, username, password,
  1751.                 trustStore, crlStore, ocspValidator,
  1752.                 options);
  1753.         return res.getContent();
  1754.     }
  1755.    
  1756.     public static HttpResponse getHTTPSResponse(String path,
  1757.             KeyStore trustStore,
  1758.             HttpOptions ... options) throws UtilsException{
  1759.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1760.                 trustStore, null, null,
  1761.                 options);
  1762.     }
  1763.     public static HttpResponse getHTTPSResponse(String path,
  1764.             KeyStore trustStore, CertStore crlStore,
  1765.             HttpOptions ... options) throws UtilsException{
  1766.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1767.                 trustStore, crlStore, null,
  1768.                 options);
  1769.     }
  1770.     public static HttpResponse getHTTPSResponse(String path,
  1771.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1772.             HttpOptions ... options) throws UtilsException{
  1773.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1774.                 trustStore, null, ocspValidator,
  1775.                 options);
  1776.     }
  1777.     public static HttpResponse getHTTPSResponse(String path,
  1778.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1779.             HttpOptions ... options) throws UtilsException{
  1780.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1781.                 trustStore, crlStore, ocspValidator,
  1782.                 options);
  1783.     }
  1784.    
  1785.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1786.             KeyStore trustStore,
  1787.             HttpOptions ... options) throws UtilsException{
  1788.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1789.                 trustStore, null, null,
  1790.                 options);
  1791.     }
  1792.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1793.             KeyStore trustStore, CertStore crlStore,
  1794.             HttpOptions ... options) throws UtilsException{
  1795.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1796.                 trustStore, crlStore, null,
  1797.                 options);
  1798.     }
  1799.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1800.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1801.             HttpOptions ... options) throws UtilsException{
  1802.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1803.                 trustStore, null, ocspValidator,
  1804.                 options);
  1805.     }
  1806.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,
  1807.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1808.             HttpOptions ... options) throws UtilsException{
  1809.         return getHTTPSResponse(path, readTimeout, connectTimeout, null, null,
  1810.                 trustStore, crlStore, ocspValidator,
  1811.                 options);
  1812.     }
  1813.    
  1814.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1815.             KeyStore trustStore,
  1816.             HttpOptions ... options) throws UtilsException{
  1817.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1818.                 trustStore, null, null,
  1819.                 options);
  1820.     }
  1821.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1822.             KeyStore trustStore, CertStore crlStore,
  1823.             HttpOptions ... options) throws UtilsException{
  1824.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1825.                 trustStore, crlStore, null,
  1826.                 options);
  1827.     }
  1828.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1829.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1830.             HttpOptions ... options) throws UtilsException{
  1831.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1832.                 trustStore, null, ocspValidator,
  1833.                 options);
  1834.     }
  1835.     public static HttpResponse getHTTPSResponse(String path,String username,String password,
  1836.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1837.             HttpOptions ... options) throws UtilsException{
  1838.         return getHTTPSResponse(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1839.                 trustStore, crlStore, ocspValidator,
  1840.                 options);
  1841.     }
  1842.    
  1843.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1844.             KeyStore trustStore,
  1845.             HttpOptions ... options) throws UtilsException{
  1846.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1847.                 trustStore, null, null,
  1848.                 options);
  1849.     }
  1850.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1851.             KeyStore trustStore, CertStore crlStore,
  1852.             HttpOptions ... options) throws UtilsException{
  1853.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1854.                 trustStore, crlStore, null,
  1855.                 options);
  1856.     }
  1857.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1858.             KeyStore trustStore, IOCSPValidator ocspValidator,
  1859.             HttpOptions ... options) throws UtilsException{
  1860.         return getHTTPSResponse(path,readTimeout,connectTimeout,username,password,
  1861.                 trustStore, null, ocspValidator,
  1862.                 options);
  1863.     }
  1864.        
  1865.     public static HttpResponse getHTTPSResponse(String path,int readTimeout,int connectTimeout,String username,String password,
  1866.             KeyStore trustStore, CertStore crlStore, IOCSPValidator ocspValidator,
  1867.             HttpOptions ... options) throws UtilsException{
  1868.        
  1869.         HttpRequest httpRequest = new HttpRequest();
  1870.         httpRequest.setUrl(path);
  1871.         httpRequest.setReadTimeout(readTimeout);
  1872.         httpRequest.setConnectTimeout(connectTimeout);
  1873.         httpRequest.setUsername(username);
  1874.         httpRequest.setPassword(password);
  1875.         httpRequest.setMethod(HttpRequestMethod.GET);
  1876.        
  1877.         httpRequest.setTrustStore(trustStore);
  1878.         httpRequest.setCrlStore(crlStore);
  1879.         httpRequest.setOcspValidator(ocspValidator);
  1880.        
  1881.         if(options!=null && options.length>0) {
  1882.             for (HttpOptions httpOptions : options) {
  1883.                 httpOptions.fill(httpRequest);
  1884.             }
  1885.         }
  1886.        
  1887.         HttpResponse response = null;
  1888.         try{
  1889.             response = httpInvoke(httpRequest);
  1890.            
  1891.         }catch(Exception e){
  1892.             throw new UtilsException("Utilities.requestHTTPFile error "+e.getMessage(),e);
  1893.         }
  1894.         if(response.getResultHTTPOperation()==404){
  1895.             throw new UtilsException("404");
  1896.         }
  1897.         return response;
  1898.        
  1899.     }
  1900.    
  1901.    
  1902.    
  1903.    
  1904.     // getHTTPSResponse_trustAllCerts (no options)
  1905.    
  1906.     public static byte[] requestHTTPSFile_trustAllCerts(String path) throws UtilsException{
  1907.         return requestHTTPSFile_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1908.                 (HttpOptions[]) null);
  1909.     }
  1910.    
  1911.     public static byte[] requestHTTPSFile_trustAllCerts(String path,int readTimeout,int connectTimeout) throws UtilsException{
  1912.         return requestHTTPSFile_trustAllCerts(path, readTimeout, connectTimeout, null, null,
  1913.                 (HttpOptions[]) null);
  1914.     }
  1915.    
  1916.     public static byte[] requestHTTPSFile_trustAllCerts(String path,String username,String password) throws UtilsException{
  1917.         return requestHTTPSFile_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1918.                 (HttpOptions[]) null);
  1919.     }

  1920.     public static byte[] requestHTTPSFile_trustAllCerts(String path,int readTimeout,int connectTimeout,String username,String password) throws UtilsException{
  1921.         HttpResponse res = getHTTPSResponse_trustAllCerts(path, readTimeout, connectTimeout, username, password,
  1922.                 (HttpOptions[]) null);
  1923.         return res.getContent();
  1924.     }
  1925.    
  1926.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path) throws UtilsException{
  1927.         return getHTTPSResponse_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1928.                 (HttpOptions[]) null);
  1929.     }
  1930.    
  1931.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path,int readTimeout,int connectTimeout) throws UtilsException{
  1932.         return getHTTPSResponse_trustAllCerts(path, readTimeout, connectTimeout, null, null,
  1933.                 (HttpOptions[]) null);
  1934.     }
  1935.    
  1936.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path,String username,String password) throws UtilsException{
  1937.         return getHTTPSResponse_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1938.                 (HttpOptions[]) null);
  1939.     }  
  1940.    
  1941.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path,int readTimeout,int connectTimeout,String username,String password) throws UtilsException{
  1942.         return getHTTPSResponse_trustAllCerts(path, readTimeout, connectTimeout, username, password,
  1943.                 (HttpOptions[]) null);
  1944.     }
  1945.    
  1946.    
  1947.     // getHTTPSResponse_trustAllCerts (options)
  1948.    
  1949.     public static byte[] requestHTTPSFile_trustAllCerts(String path,
  1950.             HttpOptions ... options) throws UtilsException{
  1951.         return requestHTTPSFile_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1952.                 options);
  1953.     }
  1954.    
  1955.     public static byte[] requestHTTPSFile_trustAllCerts(String path,int readTimeout,int connectTimeout,
  1956.             HttpOptions ... options) throws UtilsException{
  1957.         return requestHTTPSFile_trustAllCerts(path, readTimeout, connectTimeout, null, null,
  1958.                 options);
  1959.     }
  1960.    
  1961.     public static byte[] requestHTTPSFile_trustAllCerts(String path,String username,String password,
  1962.             HttpOptions ... options) throws UtilsException{
  1963.         return requestHTTPSFile_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1964.                 options);
  1965.     }

  1966.     public static byte[] requestHTTPSFile_trustAllCerts(String path,int readTimeout,int connectTimeout,String username,String password,
  1967.             HttpOptions ... options) throws UtilsException{
  1968.         HttpResponse res = getHTTPSResponse_trustAllCerts(path, readTimeout, connectTimeout, username, password,
  1969.                 options);
  1970.         return res.getContent();
  1971.     }
  1972.    
  1973.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path,
  1974.             HttpOptions ... options) throws UtilsException{
  1975.         return getHTTPSResponse_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  1976.                 options);
  1977.     }
  1978.    
  1979.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path,int readTimeout,int connectTimeout,
  1980.             HttpOptions ... options) throws UtilsException{
  1981.         return getHTTPSResponse_trustAllCerts(path, readTimeout, connectTimeout, null, null,
  1982.                 options);
  1983.     }
  1984.    
  1985.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path,String username,String password,
  1986.             HttpOptions ... options) throws UtilsException{
  1987.         return getHTTPSResponse_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  1988.                 options);
  1989.     }  
  1990.    
  1991.     public static HttpResponse getHTTPSResponse_trustAllCerts(String path,int readTimeout,int connectTimeout,String username,String password,
  1992.             HttpOptions ... options) throws UtilsException{
  1993.        
  1994.         HttpRequest httpRequest = new HttpRequest();
  1995.         httpRequest.setUrl(path);
  1996.         httpRequest.setReadTimeout(readTimeout);
  1997.         httpRequest.setConnectTimeout(connectTimeout);
  1998.         httpRequest.setUsername(username);
  1999.         httpRequest.setPassword(password);
  2000.         httpRequest.setMethod(HttpRequestMethod.GET);
  2001.        
  2002.         httpRequest.setTrustAllCerts(true);
  2003.        
  2004.         if(options!=null && options.length>0) {
  2005.             for (HttpOptions httpOptions : options) {
  2006.                 httpOptions.fill(httpRequest);
  2007.             }
  2008.         }
  2009.        
  2010.         HttpResponse response = null;
  2011.         try{
  2012.             response = httpInvoke(httpRequest);
  2013.            
  2014.         }catch(Exception e){
  2015.             throw new UtilsException("Utilities.requestHTTPFile error "+e.getMessage(),e);
  2016.         }
  2017.         if(response.getResultHTTPOperation()==404){
  2018.             throw new UtilsException("404");
  2019.         }
  2020.         return response;
  2021.        
  2022.     }
  2023.    
  2024.     private static final String TEST_FILE_ORIGIN = "file://";
  2025.    
  2026.     public static HttpResponse httpInvoke(HttpRequest request) throws UtilsException{
  2027.        
  2028.         String path = request.getUrl();
  2029.         if(path!=null && path.startsWith(TEST_FILE_ORIGIN)){
  2030.             String filePath = path.substring(TEST_FILE_ORIGIN.length());
  2031.             File f = new File(filePath);
  2032.             if(!f.exists()){
  2033.                 throw new UtilsException("404");
  2034.             }
  2035.             if(!f.canRead()){
  2036.                 throw new UtilsException("404");
  2037.             }
  2038.             HttpResponse response = new HttpResponse();
  2039.             try{
  2040.                 response.setContent(FileSystemUtilities.readBytesFromFile(f));
  2041.             }catch(Exception e){
  2042.                 throw new UtilsException(e.getMessage(),e);
  2043.             }
  2044.             response.setResultHTTPOperation(200);
  2045.             response.setContentType(MimeTypes.getInstance().getMimeType(f));
  2046.             return response;
  2047.         }
  2048.        
  2049.        
  2050.         InputStream is = null;
  2051.         ByteArrayOutputStream outResponse = null;
  2052.         InputStream finKeyStore = null;
  2053.         InputStream finTrustStore = null;
  2054.         try {
  2055.             SSLContext sslContext = null;
  2056.             OCSPTrustManager ocspTrustManager = null;
  2057.            
  2058.             if(request.isTrustAllCerts() || request.getTrustStore()!=null || request.getTrustStorePath()!=null){
  2059.                
  2060.                 KeyManager[] km = null;
  2061.                 TrustManager[] tm = null;
  2062.                                
  2063.                 // Autenticazione CLIENT
  2064.                 if(request.getKeyStore()!=null || request.getKeyStorePath()!=null){
  2065.                     String location = null;
  2066.                     try {
  2067.                         location = request.getKeyStorePath(); // per debug
  2068.                    
  2069.                         boolean hsmKeystore = false;
  2070.                         HSMManager hsmManager = HSMManager.getInstance();
  2071.                         String hsmType = null;
  2072.                         if(hsmManager!=null) {
  2073.                             if(request.getKeyStore()!=null) {
  2074.                                 hsmType = request.getKeyStore().getType();
  2075.                             }
  2076.                             else {
  2077.                                 hsmType = request.getKeyStoreType();
  2078.                             }
  2079.                             if(hsmType!=null) {
  2080.                                 hsmKeystore = hsmManager.existsKeystoreType(hsmType);
  2081.                                 if(!hsmKeystore) {
  2082.                                     hsmType = null;
  2083.                                 }
  2084.                             }
  2085.                         }
  2086.                        
  2087.                         KeyStore keystore = null;
  2088.                         KeyStore keystoreParam = null;
  2089.                         @SuppressWarnings("unused")
  2090.                         Provider keystoreProvider = null;
  2091.                         if(request.getKeyStore()!=null) {
  2092.                             keystoreParam = request.getKeyStore();
  2093.                             if(hsmKeystore) {
  2094.                                 keystoreProvider = keystoreParam.getProvider();
  2095.                             }
  2096.                         }
  2097.                         else {
  2098.                             if(hsmKeystore) {
  2099.                                 org.openspcoop2.utils.certificate.KeyStore ks = hsmManager.getKeystore(hsmType);
  2100.                                 if(ks==null) {
  2101.                                     throw new UtilsException("Keystore not found");
  2102.                                 }
  2103.                                 keystoreParam = ks.getKeystore();
  2104.                                 keystoreProvider = keystoreParam.getProvider();
  2105.                             }
  2106.                             else {
  2107.                                 File file = new File(location);
  2108.                                 if(file.exists()) {
  2109.                                     finKeyStore = new FileInputStream(file);
  2110.                                 }
  2111.                                 else {
  2112.                                     finKeyStore = SSLUtilities.class.getResourceAsStream(location);
  2113.                                 }
  2114.                                 if(finKeyStore == null) {
  2115.                                     throw new UtilsException("Keystore not found");
  2116.                                 }
  2117.                                 String tipo = request.getKeyStoreType()!=null ? request.getKeyStoreType() : KeystoreType.JKS.getNome();
  2118.                                 keystoreParam = KeystoreUtils.readKeystore(finKeyStore, tipo, request.getKeyStorePassword());
  2119.                             }
  2120.                         }
  2121.                        
  2122.                         boolean oldMethodKeyAlias = false; // Questo metodo non funzirequestonava con PKCS11
  2123.                         if(oldMethodKeyAlias && request.getKeyAlias()!=null) {
  2124.                             Key key = keystoreParam.getKey(request.getKeyAlias(), request.getKeyPassword().toCharArray());
  2125.                             if(key==null) {
  2126.                                 throw new UtilsException("Key with alias '"+request.getKeyAlias()+"' not found");
  2127.                             }
  2128.                             if(hsmKeystore) {
  2129.                                 // uso un JKS come tmp
  2130.                                 keystore = KeyStore.getInstance(KeystoreType.JKS.getNome());
  2131.                             }
  2132.                             else {
  2133.                                 keystore = KeyStore.getInstance(request.getKeyStoreType());
  2134.                             }
  2135.                             keystore.load(null); // inizializza il keystore
  2136.                             keystore.setKeyEntry(request.getKeyAlias(), key,
  2137.                                     request.getKeyPassword().toCharArray()!=null ? request.getKeyPassword().toCharArray() : "".toCharArray(),
  2138.                                     keystoreParam.getCertificateChain(request.getKeyAlias()));
  2139.                         }
  2140.                         else {
  2141.                             keystore = keystoreParam;
  2142.                         }
  2143.                        
  2144.                         KeyManagerFactory keyManagerFactory = null;
  2145.                         // NO: no such algorithm: SunX509 for provider SunPKCS11-xxx
  2146.                         /**if(keystoreProvider!=null) {
  2147.                         //  keyManagerFactory = KeyManagerFactory.getInstance(sslConfig.getKeyManagementAlgorithm(), keystoreProvider);
  2148.                         //}
  2149.                         //else {*/
  2150.                         keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
  2151.                        
  2152.                         keyManagerFactory.init(keystore, request.getKeyPassword().toCharArray()!=null ? request.getKeyPassword().toCharArray() : "".toCharArray());
  2153.                         km = keyManagerFactory.getKeyManagers();
  2154.                         if(!oldMethodKeyAlias && request.getKeyAlias()!=null &&
  2155.                             km!=null && km.length>0 && km[0]!=null && km[0] instanceof X509KeyManager) {
  2156.                                
  2157.                             String alias = request.getKeyAlias();
  2158.                            
  2159.                             // Fix case insensitive
  2160.                             Enumeration<String> enAliases = keystore.aliases();
  2161.                             if(enAliases!=null) {
  2162.                                 while (enAliases.hasMoreElements()) {
  2163.                                     String a = enAliases.nextElement();
  2164.                                     if(a.equalsIgnoreCase(alias)) {
  2165.                                         alias = a; // uso quello presente nel keystore
  2166.                                         break;
  2167.                                     }
  2168.                                 }
  2169.                             }
  2170.                            
  2171.                             X509KeyManager wrapperX509KeyManager = new SSLX509ManagerForcedClientAlias(alias, (X509KeyManager)km[0] );
  2172.                             km[0] = wrapperX509KeyManager;
  2173.                            
  2174.                         }
  2175.                     }catch(Throwable e) {
  2176.                         if(location!=null) {
  2177.                             throw new UtilsException("["+location+"] "+e.getMessage(),e);
  2178.                         }
  2179.                         else {
  2180.                             throw new UtilsException(e.getMessage(),e);
  2181.                         }
  2182.                     }
  2183.                 }
  2184.                
  2185.                 // Autenticazione Server
  2186.                 KeyStore truststore = null;
  2187.                 if(request.isTrustAllCerts()) {
  2188.                     tm = SSLUtilities.getTrustAllCertsManager();
  2189.                 }
  2190.                 else {
  2191.                    
  2192.                     boolean hsmTruststore = false;
  2193.                     HSMManager hsmManager = HSMManager.getInstance();
  2194.                     if(hsmManager!=null) {
  2195.                         if(request.getTrustStore()!=null) {
  2196.                             hsmTruststore = request.isTrustStoreHsm();
  2197.                         }
  2198.                         else {
  2199.                             if(request.getTrustStoreType()!=null && hsmManager.existsKeystoreType(request.getTrustStoreType())) {
  2200.                                 hsmTruststore = true;          
  2201.                             }
  2202.                         }
  2203.                     }
  2204.                    
  2205.                     @SuppressWarnings("unused")
  2206.                     Provider truststoreProvider = null;
  2207.                     if(request.getTrustStore()!=null ) {
  2208.                         truststore = request.getTrustStore();
  2209.                         if(hsmTruststore) {
  2210.                             truststoreProvider = truststore.getProvider();
  2211.                         }
  2212.                     }
  2213.                     else {
  2214.                         if(request.getTrustStoreType()==null) {
  2215.                             throw new UtilsException("Ssl TrustStore type required");
  2216.                         }
  2217.                         if(request.getTrustStorePassword()==null) {
  2218.                             throw new UtilsException("Ssl TrustStore password required");
  2219.                         }
  2220.                         if(hsmTruststore) {
  2221.                             org.openspcoop2.utils.certificate.KeyStore ks = hsmManager.getKeystore(request.getTrustStoreType());
  2222.                             if(ks==null) {
  2223.                                 throw new UtilsException("Keystore not found");
  2224.                             }
  2225.                             truststore = ks.getKeystore();
  2226.                             truststoreProvider = truststore.getProvider();
  2227.                         }
  2228.                         else {
  2229.                             File file = new File(request.getTrustStorePath());
  2230.                             if(file.exists()) {
  2231.                                 finTrustStore = new FileInputStream(file);
  2232.                             }
  2233.                             else {
  2234.                                 finTrustStore = SSLUtilities.class.getResourceAsStream(request.getTrustStorePath());
  2235.                             }
  2236.                             if(finTrustStore == null) {
  2237.                                 throw new UtilsException("Keystore ["+request.getTrustStorePath()+"] not found");
  2238.                             }
  2239.                             truststore = KeystoreUtils.readKeystore(finTrustStore, request.getTrustStoreType(), request.getTrustStorePassword());
  2240.                         }
  2241.                     }
  2242.                                        
  2243.                     TrustManagerFactory trustManagerFactory = null;
  2244.                     // NO: no such algorithm: PKIX for provider SunPKCS11-xxx
  2245.                     /**if(truststoreProvider!=null) {
  2246.                     //  trustManagerFactory = TrustManagerFactory.getInstance("PKIX", truststoreProvider);
  2247.                     //}
  2248.                     //else {*/
  2249.                     trustManagerFactory = TrustManagerFactory.getInstance("PKIX");
  2250.                    
  2251.                     Provider sigProvider = null;                    
  2252.                     CertPathTrustManagerParameters params = SSLUtilities.buildCertPathTrustManagerParameters(truststore, request.getCrlStore(), request.getCrlPath(), sigProvider);
  2253.                     trustManagerFactory.init(params);
  2254.                     tm = trustManagerFactory.getTrustManagers();
  2255.                 }

  2256.                 IOCSPValidator ocspValidator = request.getOcspValidator();
  2257.                 if(truststore!=null && ocspValidator==null && request.getOcspPolicy()!=null && StringUtils.isNotEmpty(request.getOcspPolicy())) {
  2258.                     Logger log = LoggerWrapperFactory.getLogger(HttpUtilities.class);
  2259.                     IOCSPValidatorBuilder builder = (IOCSPValidatorBuilder) new Loader().newInstance("org.openspcoop2.utils.certificate.ocsp.OCSPValidatorBuilderImpl");
  2260.                     ocspValidator = builder.newInstance(log, truststore, request.getCrlPath(), request.getOcspPolicy());
  2261.                 }
  2262.                 if(ocspValidator!=null) {
  2263.                     tm = OCSPTrustManager.wrap(tm, ocspValidator);
  2264.                     ocspTrustManager = OCSPTrustManager.read(tm);
  2265.                     ocspValidator.setOCSPTrustManager(ocspTrustManager);
  2266.                 }

  2267.                
  2268.                 sslContext = SSLContext.getInstance(SSLUtilities.getSafeDefaultProtocol()); // ritorna l'ultima versione disponibile
  2269.                
  2270.                 if(request.isSecureRandom()) {
  2271.                     RandomGenerator randomGenerator = null;
  2272.                     if(request.getSecureRandomAlgorithm()!=null && !"".equals(request.getSecureRandomAlgorithm())) {
  2273.                         randomGenerator = new RandomGenerator(true, request.getSecureRandomAlgorithm());
  2274.                     }
  2275.                     else {
  2276.                         randomGenerator = new RandomGenerator(true);
  2277.                     }
  2278.                     java.security.SecureRandom secureRandom = (java.security.SecureRandom) randomGenerator.getRandomEngine();
  2279.                     sslContext.init(km, tm, secureRandom);
  2280.                 }
  2281.                 else {
  2282.                     sslContext.init(km, tm, null);
  2283.                 }
  2284.             }
  2285.            
  2286.             if(request.getUrl()==null){
  2287.                 throw new UtilsException("Url required");
  2288.             }
  2289.             String connectionUrl = request.getUrl();
  2290.             if(request.getForwardProxyEndpoint()!=null && request.getForwardProxyConfig()!=null) {
  2291.                 Map<String, List<String>> parameters = new HashMap<>();
  2292.                 if(request.getForwardProxyConfig().getQuery()!=null) {
  2293.                     if(request.getForwardProxyConfig().isQueryBase64()) {
  2294.                         String base64Location = Base64Utilities.encodeAsString(connectionUrl.getBytes());
  2295.                         TransportUtils.addParameter(parameters,request.getForwardProxyConfig().getQuery(), base64Location);
  2296.                     }
  2297.                     else {
  2298.                         TransportUtils.addParameter(parameters,request.getForwardProxyConfig().getQuery(), connectionUrl);
  2299.                     }
  2300.                 }
  2301.                 else if(request.getForwardProxyConfig().getHeader()!=null) {
  2302.                     if(request.getForwardProxyConfig().isHeaderBase64()) {
  2303.                         String base64Location = Base64Utilities.encodeAsString(connectionUrl.getBytes());
  2304.                         request.addHeader(request.getForwardProxyConfig().getHeader(), base64Location);
  2305.                     }
  2306.                     else {
  2307.                         request.addHeader(request.getForwardProxyConfig().getHeader(), connectionUrl);
  2308.                     }
  2309.                 }
  2310.                 boolean encodeBaseLocation = true; // la base location può contenere dei parametri
  2311.                 connectionUrl = TransportUtils.buildUrlWithParameters(parameters, request.getForwardProxyEndpoint(), encodeBaseLocation, LoggerWrapperFactory.getLogger(HttpUtilities.class));
  2312.             }
  2313.             URL url = new URL(connectionUrl);
  2314.             URLConnection connection = null;
  2315.             if(request.getProxyType()==null){
  2316.                 connection = url.openConnection();
  2317.             }
  2318.             else {
  2319.                 if(request.getProxyHostname()==null) {
  2320.                     throw new UtilsException("Proxy require a hostname");
  2321.                 }
  2322.                 Proxy proxy = new Proxy(request.getProxyType(), new InetSocketAddress(request.getProxyHostname(), request.getProxyPort()));
  2323.                 connection = url.openConnection(proxy);
  2324.                
  2325.                 // Proxy Authentication BASIC
  2326.                 if(request.getProxyUsername()!=null && request.getProxyPassword()!=null){
  2327.                     String authentication = request.getProxyUsername() + ":" + request.getProxyPassword();
  2328.                     authentication = HttpConstants.AUTHORIZATION_PREFIX_BASIC + Base64Utilities.encodeAsString(authentication.getBytes());
  2329.                     request.addHeader(HttpConstants.PROXY_AUTHORIZATION,authentication);
  2330.                 }
  2331.             }
  2332.             HttpURLConnection httpConn = (HttpURLConnection) connection;
  2333.             if(sslContext!=null) {
  2334.                
  2335.                 HttpsURLConnection httpsConn = (HttpsURLConnection) httpConn;
  2336.                 httpsConn.setSSLSocketFactory(sslContext.getSocketFactory());
  2337.                 if(!request.isHostnameVerifier()) {
  2338.                     SSLHostNameVerifierDisabled disabilitato = new SSLHostNameVerifierDisabled(LoggerWrapperFactory.getLogger(HttpUtilities.class));
  2339.                     httpsConn.setHostnameVerifier(disabilitato);
  2340.                 }
  2341.             }

  2342.             String contentType = request.getContentType();
  2343.             if(contentType!=null){
  2344.                 httpConn.setRequestProperty(HttpConstants.CONTENT_TYPE,contentType);
  2345.             }
  2346.             else if(request.getContent()!=null){
  2347.                 String ct = request.getHeaderFirstValue(HttpConstants.CONTENT_TYPE);
  2348.                 if(ct==null || StringUtils.isEmpty(ct)) {
  2349.                     throw new UtilsException("Content require a Content Type");
  2350.                 }
  2351.                 else {
  2352.                     contentType = ct; // negli header verra impostato sotto
  2353.                 }
  2354.             }
  2355.            
  2356.             httpConn.setConnectTimeout(request.getConnectTimeout());
  2357.             httpConn.setReadTimeout(request.getReadTimeout());
  2358.            
  2359.             if(request.getFollowRedirects()!=null) {
  2360.                 httpConn.setInstanceFollowRedirects(request.getFollowRedirects());
  2361.             }
  2362.             else {
  2363.                 httpConn.setInstanceFollowRedirects(false);
  2364.             }
  2365.            
  2366.             if(request.getUsername()!=null && request.getPassword()!=null){
  2367.                 String authentication = request.getUsername() + ":" + request.getPassword();
  2368.                 authentication = HttpConstants.AUTHORIZATION_PREFIX_BASIC + Base64Utilities.encodeAsString(authentication.getBytes());
  2369.                 httpConn.setRequestProperty(HttpConstants.AUTHORIZATION,authentication);
  2370.             }
  2371.            
  2372.             Map<String, List<String>> requestHeaders = request.getHeadersValues();
  2373.             if(requestHeaders!=null && requestHeaders.size()>0){
  2374.                 Iterator<String> itReq = requestHeaders.keySet().iterator();
  2375.                 while (itReq.hasNext()) {
  2376.                     String key = itReq.next();
  2377.                     List<String> values = requestHeaders.get(key);
  2378.                     if(values!=null && !values.isEmpty()) {
  2379.                         for (String value : values) {
  2380.                             httpConn.addRequestProperty(key, value);        
  2381.                         }
  2382.                     }
  2383.                 }
  2384.             }
  2385.            
  2386.             boolean sendThrottling = false;
  2387.             if(request.getThrottlingSendByte()!=null && request.getThrottlingSendByte()>0 &&
  2388.                     request.getThrottlingSendMs()!=null && request.getThrottlingSendMs()>0) {
  2389.                 sendThrottling = true;
  2390.             }
  2391.            
  2392.             if(request.getMethod()==null){
  2393.                 throw new UtilsException("HttpMethod required");
  2394.             }
  2395.             if(sendThrottling || request.isForceTransferEncodingChunked()) {
  2396.                 httpConn.setChunkedStreamingMode(0);
  2397.             }
  2398.             setStream(httpConn, request.getMethod(), contentType);

  2399.             HttpBodyParameters httpContent = new  HttpBodyParameters(request.getMethod(), contentType);
  2400.             // Spedizione byte
  2401.             if(httpContent.isDoOutput() && request.getContent() != null){
  2402.                 OutputStream out = httpConn.getOutputStream();
  2403.                 /**System.out.println("Classe '"+out.getClass().getName()+"'");*/
  2404.                 if(sendThrottling) {
  2405.                     int lengthSendContent = request.getContent().length;
  2406.                     for (int i = 0; i < lengthSendContent; ) {
  2407.                         int length = request.getThrottlingSendByte();
  2408.                         int remaining = lengthSendContent-i;
  2409.                         if(remaining<length) {
  2410.                             length = remaining;
  2411.                         }
  2412.                         out.write(request.getContent(),i,length);
  2413.                         i = i+length;
  2414.                         out.flush();
  2415.                         /**System.out.println("Spediti "+length+" bytes");*/
  2416.                         Utilities.sleep(request.getThrottlingSendMs());
  2417.                     }
  2418.                 }
  2419.                 else {
  2420.                     out.write(request.getContent());
  2421.                 }
  2422.                 out.flush();
  2423.                 out.close();
  2424.             }
  2425.             else if(httpContent.isDoOutput() && request.getContentStream() != null){
  2426.                 OutputStream out = httpConn.getOutputStream();
  2427.                 CopyStream.copy(request.getContentStream(), out);
  2428.             }
  2429.            
  2430.             HttpResponse response = new HttpResponse();
  2431.            
  2432.             // Ricezione header
  2433.             Map<String, List<String>> mapHeaderHttpResponse = httpConn.getHeaderFields();
  2434.             if(mapHeaderHttpResponse!=null && mapHeaderHttpResponse.size()>0){
  2435.                 Iterator<String> itHttpResponse = mapHeaderHttpResponse.keySet().iterator();
  2436.                 while(itHttpResponse.hasNext()){
  2437.                     String keyHttpResponse = itHttpResponse.next();
  2438.                     List<String> valueHttpResponse = mapHeaderHttpResponse.get(keyHttpResponse);
  2439.                     if(keyHttpResponse==null){ // Check per evitare la coppia che ha come chiave null e come valore HTTP OK 200
  2440.                         keyHttpResponse=HttpConstants.RETURN_CODE;
  2441.                     }
  2442.                     response.addHeader(keyHttpResponse, valueHttpResponse);
  2443.                 }
  2444.             }
  2445.            
  2446.             // ContentType Risposta
  2447.             if(response.getHeadersValues()!=null && !response.getHeadersValues().isEmpty()){
  2448.                 response.setContentType(response.getHeaderFirstValue(HttpConstants.CONTENT_TYPE));
  2449.             }

  2450.             // Ricezione Result HTTP Code
  2451.             int resultHTTPOperation = httpConn.getResponseCode();

  2452.             response.setResultHTTPOperation(resultHTTPOperation);
  2453.            
  2454.             // Ricezione Risposta
  2455.             if(httpContent.isDoInput()){
  2456.                 outResponse = new ByteArrayOutputStream();
  2457.                 if(resultHTTPOperation>399){
  2458.                     is = httpConn.getErrorStream();
  2459.                     if(is==null){
  2460.                         is = httpConn.getInputStream();
  2461.                     }
  2462.                 }else{
  2463.                     is = httpConn.getInputStream();
  2464.                     if(is==null){
  2465.                         is = httpConn.getErrorStream();
  2466.                     }
  2467.                 }
  2468.                 CopyStream.copy(is, outResponse);
  2469.                 is.close();
  2470.                 outResponse.flush();
  2471.                 outResponse.close();
  2472.                 response.setContent(outResponse.toByteArray());
  2473.             }
  2474.                
  2475.             // fine HTTP.
  2476.             httpConn.disconnect();
  2477.    
  2478.             // certificati server
  2479.             if(ocspTrustManager!=null) {
  2480.                 response.setServerCertificate(ocspTrustManager.getPeerCertificates());
  2481.             }
  2482.            
  2483.             return response;
  2484.         }catch(Exception e){
  2485.             try{
  2486.                 if(is!=null)
  2487.                     is.close();
  2488.             }catch(Exception eis){
  2489.                 // ignore
  2490.             }
  2491.             try{
  2492.                 if(outResponse!=null)
  2493.                     outResponse.close();
  2494.             }catch(Exception eis){
  2495.                 // ignore
  2496.             }
  2497.             throw new UtilsException(e.getMessage(),e);
  2498.         }
  2499.         finally{
  2500.             try{
  2501.                 if(finKeyStore!=null){
  2502.                     finKeyStore.close();
  2503.                 }
  2504.             }catch(Exception e){
  2505.                 // ignore
  2506.             }
  2507.             try{
  2508.                 if(finTrustStore!=null){
  2509.                     finTrustStore.close();
  2510.                 }
  2511.             }catch(Exception e){
  2512.                 // close
  2513.             }
  2514.         }
  2515.     }




  2516.    
  2517.    
  2518.     /* ********* CHECK ************ */
  2519.    
  2520.     // check (no options)
  2521.    
  2522.     public static void check(String path) throws UtilsException,HttpUtilsException{
  2523.         check(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2524.                 (HttpOptions[]) null);
  2525.     }
  2526.     public static void check(String path,int readTimeout,int connectTimeout) throws UtilsException,HttpUtilsException{
  2527.         check(path, readTimeout, connectTimeout, null, null,
  2528.                 (HttpOptions[]) null);
  2529.     }
  2530.     public static void check(String path,String username,String password) throws UtilsException,HttpUtilsException{
  2531.         check(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2532.                 (HttpOptions[]) null);
  2533.     }
  2534.     public static void check(String path,int readTimeout,int connectTimeout,String username,String password) throws UtilsException,HttpUtilsException{
  2535.         check(path, readTimeout, connectTimeout, username, password,
  2536.                 (HttpOptions[]) null);
  2537.     }
  2538.    
  2539.     // check (options)
  2540.    
  2541.     public static void check(String path,
  2542.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2543.         check(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2544.                 options);
  2545.     }
  2546.     public static void check(String path,int readTimeout,int connectTimeout,
  2547.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2548.         check(path, readTimeout, connectTimeout, null, null,
  2549.                 options);
  2550.     }
  2551.     public static void check(String path,String username,String password,
  2552.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2553.         check(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2554.                 options);
  2555.     }  
  2556.     public static void check(String path,int readTimeout,int connectTimeout,String username,String password,
  2557.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2558.        
  2559.         HttpRequest httpRequest = new HttpRequest();
  2560.         httpRequest.setUrl(path);
  2561.         httpRequest.setReadTimeout(readTimeout);
  2562.         httpRequest.setConnectTimeout(connectTimeout);
  2563.         httpRequest.setUsername(username);
  2564.         httpRequest.setPassword(password);
  2565.         httpRequest.setMethod(HttpRequestMethod.GET);
  2566.        
  2567.         if(options!=null && options.length>0) {
  2568.             for (HttpOptions httpOptions : options) {
  2569.                 httpOptions.fill(httpRequest);
  2570.             }
  2571.         }
  2572.        
  2573.         check(httpRequest);
  2574.        
  2575.     }
  2576.    
  2577.    
  2578.    
  2579.    
  2580.     // checkHTTPS (no options)
  2581.    
  2582.     public static void checkHTTPS(String path,
  2583.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException,HttpUtilsException{
  2584.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2585.                 trustStore, trustStorePassword, trustStoreType,
  2586.                 null,
  2587.                 (HttpOptions[]) null);
  2588.     }
  2589.     public static void checkHTTPS(String path,
  2590.             String trustStore, String trustStorePassword, String trustStoreType,
  2591.             String crlPath) throws UtilsException,HttpUtilsException{
  2592.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2593.                 trustStore, trustStorePassword, trustStoreType,
  2594.                 crlPath,
  2595.                 (HttpOptions[]) null);
  2596.     }
  2597.    
  2598.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2599.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException,HttpUtilsException{
  2600.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2601.                 trustStore, trustStorePassword, trustStoreType,
  2602.                 null,
  2603.                 (HttpOptions[]) null);
  2604.     }
  2605.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2606.             String trustStore, String trustStorePassword, String trustStoreType,
  2607.             String crlPath) throws UtilsException,HttpUtilsException{
  2608.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2609.                 trustStore, trustStorePassword, trustStoreType,
  2610.                 crlPath,
  2611.                 (HttpOptions[]) null);
  2612.     }
  2613.    
  2614.     public static void checkHTTPS(String path,String username,String password,
  2615.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException,HttpUtilsException{
  2616.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2617.                 trustStore, trustStorePassword, trustStoreType,
  2618.                 null,
  2619.                 (HttpOptions[]) null);
  2620.     }
  2621.     public static void checkHTTPS(String path,String username,String password,
  2622.             String trustStore, String trustStorePassword, String trustStoreType,
  2623.             String crlPath) throws UtilsException,HttpUtilsException{
  2624.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2625.                 trustStore, trustStorePassword, trustStoreType,
  2626.                 crlPath,
  2627.                 (HttpOptions[]) null);
  2628.     }
  2629.    
  2630.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2631.             String trustStore, String trustStorePassword, String trustStoreType) throws UtilsException,HttpUtilsException{
  2632.         checkHTTPS(path,readTimeout,connectTimeout,username,password,
  2633.                 trustStore, trustStorePassword, trustStoreType,
  2634.                 null,
  2635.                 (HttpOptions[]) null);
  2636.     }
  2637.    
  2638.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2639.             String trustStore, String trustStorePassword, String trustStoreType,
  2640.             String crlPath) throws UtilsException,HttpUtilsException{
  2641.         checkHTTPS(path,readTimeout,connectTimeout,username,password,
  2642.                 trustStore, trustStorePassword, trustStoreType,
  2643.                 crlPath,
  2644.                 (HttpOptions[]) null);
  2645.     }
  2646.    
  2647.    
  2648.     // checkHTTPS (options)
  2649.    
  2650.     public static void checkHTTPS(String path,
  2651.             String trustStore, String trustStorePassword, String trustStoreType,
  2652.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2653.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2654.                 trustStore, trustStorePassword, trustStoreType,
  2655.                 null,
  2656.                 options);
  2657.     }
  2658.     public static void checkHTTPS(String path,
  2659.             String trustStore, String trustStorePassword, String trustStoreType,
  2660.             String crlPath,
  2661.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2662.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2663.                 trustStore, trustStorePassword, trustStoreType,
  2664.                 crlPath,
  2665.                 options);
  2666.     }
  2667.    
  2668.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2669.             String trustStore, String trustStorePassword, String trustStoreType,
  2670.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2671.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2672.                 trustStore, trustStorePassword, trustStoreType,
  2673.                 null,
  2674.                 options);
  2675.     }
  2676.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2677.             String trustStore, String trustStorePassword, String trustStoreType,
  2678.             String crlPath,
  2679.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2680.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2681.                 trustStore, trustStorePassword, trustStoreType,
  2682.                 crlPath,
  2683.                 options);
  2684.     }
  2685.    
  2686.     public static void checkHTTPS(String path,String username,String password,
  2687.             String trustStore, String trustStorePassword, String trustStoreType,
  2688.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2689.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2690.                 trustStore, trustStorePassword, trustStoreType,
  2691.                 null,
  2692.                 options);
  2693.     }
  2694.     public static void checkHTTPS(String path,String username,String password,
  2695.             String trustStore, String trustStorePassword, String trustStoreType,
  2696.             String crlPath,
  2697.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2698.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2699.                 trustStore, trustStorePassword, trustStoreType,
  2700.                 crlPath,
  2701.                 options);
  2702.     }
  2703.    
  2704.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2705.             String trustStore, String trustStorePassword, String trustStoreType,
  2706.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2707.         checkHTTPS(path,readTimeout,connectTimeout,username,password,
  2708.                 trustStore, trustStorePassword, trustStoreType,
  2709.                 null,
  2710.                 options);
  2711.     }
  2712.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2713.             String trustStore, String trustStorePassword, String trustStoreType,
  2714.             String crlPath,
  2715.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2716.        
  2717.         HttpRequest httpRequest = new HttpRequest();
  2718.         httpRequest.setUrl(path);
  2719.         httpRequest.setReadTimeout(readTimeout);
  2720.         httpRequest.setConnectTimeout(connectTimeout);
  2721.         httpRequest.setUsername(username);
  2722.         httpRequest.setPassword(password);
  2723.         httpRequest.setMethod(HttpRequestMethod.GET);
  2724.        
  2725.         httpRequest.setTrustStorePath(trustStore);
  2726.         httpRequest.setTrustStorePassword(trustStorePassword);
  2727.         httpRequest.setTrustStoreType(trustStoreType);
  2728.         httpRequest.setCrlPath(crlPath);
  2729.        
  2730.         if(options!=null && options.length>0) {
  2731.             for (HttpOptions httpOptions : options) {
  2732.                 httpOptions.fill(httpRequest);
  2733.             }
  2734.         }
  2735.        
  2736.         check(httpRequest);
  2737.        
  2738.     }
  2739.    
  2740.    
  2741.    
  2742.    
  2743.    
  2744.     // checkHTTPS (no options)
  2745.    
  2746.     public static void checkHTTPS(String path,
  2747.             KeyStore trustStore) throws UtilsException,HttpUtilsException{
  2748.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2749.                 trustStore, null,
  2750.                 (HttpOptions[]) null);
  2751.     }
  2752.     public static void checkHTTPS(String path,
  2753.             KeyStore trustStore, CertStore crlStore) throws UtilsException,HttpUtilsException{
  2754.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2755.                 trustStore, crlStore,
  2756.                 (HttpOptions[]) null);
  2757.     }
  2758.    
  2759.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2760.             KeyStore trustStore) throws UtilsException,HttpUtilsException{
  2761.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2762.                 trustStore, null,
  2763.                 (HttpOptions[]) null);
  2764.     }
  2765.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2766.             KeyStore trustStore, CertStore crlStore) throws UtilsException,HttpUtilsException{
  2767.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2768.                 trustStore, crlStore,
  2769.                 (HttpOptions[]) null);
  2770.     }
  2771.    
  2772.     public static void checkHTTPS(String path,String username,String password,
  2773.             KeyStore trustStore) throws UtilsException,HttpUtilsException{
  2774.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2775.                 trustStore, null,
  2776.                 (HttpOptions[]) null);
  2777.     }
  2778.     public static void checkHTTPS(String path,String username,String password,
  2779.             KeyStore trustStore, CertStore crlStore) throws UtilsException,HttpUtilsException{
  2780.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2781.                 trustStore, crlStore,
  2782.                 (HttpOptions[]) null);
  2783.     }  
  2784.    
  2785.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2786.             KeyStore trustStore) throws UtilsException,HttpUtilsException{
  2787.         checkHTTPS(path,readTimeout,connectTimeout,username,password,
  2788.                 trustStore, null,
  2789.                 (HttpOptions[]) null);
  2790.     }
  2791.    
  2792.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2793.             KeyStore trustStore, CertStore crlStore) throws UtilsException,HttpUtilsException{
  2794.         checkHTTPS(path,readTimeout,connectTimeout,username,password,
  2795.                 trustStore, crlStore,
  2796.                 (HttpOptions[]) null);
  2797.     }
  2798.    
  2799.    
  2800.    
  2801.     // checkHTTPS (options)
  2802.    
  2803.     public static void checkHTTPS(String path,
  2804.             KeyStore trustStore,
  2805.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2806.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2807.                 trustStore, null,
  2808.                 options);
  2809.     }
  2810.     public static void checkHTTPS(String path,
  2811.             KeyStore trustStore, CertStore crlStore,
  2812.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2813.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2814.                 trustStore, crlStore,
  2815.                 options);
  2816.     }
  2817.    
  2818.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2819.             KeyStore trustStore,
  2820.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2821.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2822.                 trustStore, null,
  2823.                 options);
  2824.     }
  2825.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,
  2826.             KeyStore trustStore, CertStore crlStore,
  2827.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2828.         checkHTTPS(path, readTimeout, connectTimeout, null, null,
  2829.                 trustStore, crlStore,
  2830.                 options);
  2831.     }
  2832.    
  2833.     public static void checkHTTPS(String path,String username,String password,
  2834.             KeyStore trustStore,
  2835.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2836.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2837.                 trustStore, null,
  2838.                 options);
  2839.     }
  2840.     public static void checkHTTPS(String path,String username,String password,
  2841.             KeyStore trustStore, CertStore crlStore,
  2842.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2843.         checkHTTPS(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2844.                 trustStore, crlStore,
  2845.                 options);
  2846.     }  
  2847.    
  2848.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2849.             KeyStore trustStore,
  2850.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2851.         checkHTTPS(path,readTimeout,connectTimeout,username,password,
  2852.                 trustStore, null,
  2853.                 options);
  2854.     }
  2855.    
  2856.     public static void checkHTTPS(String path,int readTimeout,int connectTimeout,String username,String password,
  2857.             KeyStore trustStore, CertStore crlStore,
  2858.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2859.        
  2860.         HttpRequest httpRequest = new HttpRequest();
  2861.         httpRequest.setUrl(path);
  2862.         httpRequest.setReadTimeout(readTimeout);
  2863.         httpRequest.setConnectTimeout(connectTimeout);
  2864.         httpRequest.setUsername(username);
  2865.         httpRequest.setPassword(password);
  2866.         httpRequest.setMethod(HttpRequestMethod.GET);
  2867.        
  2868.         httpRequest.setTrustStore(trustStore);
  2869.         httpRequest.setCrlStore(crlStore);
  2870.        
  2871.         if(options!=null && options.length>0) {
  2872.             for (HttpOptions httpOptions : options) {
  2873.                 httpOptions.fill(httpRequest);
  2874.             }
  2875.         }
  2876.        
  2877.         check(httpRequest);
  2878.        
  2879.     }
  2880.    
  2881.    
  2882.    
  2883.     // checkHTTPS_trustAllCerts (no options)
  2884.    
  2885.     public static void checkHTTPS_trustAllCerts(String path) throws UtilsException, HttpUtilsException{
  2886.         checkHTTPS_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2887.                 (HttpOptions[]) null);
  2888.     }
  2889.     public static void checkHTTPS_trustAllCerts(String path,int readTimeout,int connectTimeout) throws UtilsException, HttpUtilsException{
  2890.         checkHTTPS_trustAllCerts(path, readTimeout, connectTimeout, null, null,
  2891.                 (HttpOptions[]) null);
  2892.     }
  2893.     public static void checkHTTPS_trustAllCerts(String path,String username,String password) throws UtilsException, HttpUtilsException{
  2894.         checkHTTPS_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2895.                 (HttpOptions[]) null);
  2896.     }  
  2897.     public static void checkHTTPS_trustAllCerts(String path,int readTimeout,int connectTimeout,String username,String password) throws UtilsException,HttpUtilsException{
  2898.         checkHTTPS_trustAllCerts(path, readTimeout, connectTimeout, username, password,
  2899.                 (HttpOptions[]) null);
  2900.     }
  2901.    
  2902.     // checkHTTPS_trustAllCerts (options)
  2903.    
  2904.     public static void checkHTTPS_trustAllCerts(String path,
  2905.             HttpOptions ... options) throws UtilsException, HttpUtilsException{
  2906.         checkHTTPS_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, null, null,
  2907.                 options);
  2908.     }
  2909.     public static void checkHTTPS_trustAllCerts(String path,int readTimeout,int connectTimeout,
  2910.             HttpOptions ... options) throws UtilsException, HttpUtilsException{
  2911.         checkHTTPS_trustAllCerts(path, readTimeout, connectTimeout, null, null,
  2912.                 options);
  2913.     }
  2914.     public static void checkHTTPS_trustAllCerts(String path,String username,String password,
  2915.             HttpOptions ... options) throws UtilsException, HttpUtilsException{
  2916.         checkHTTPS_trustAllCerts(path, HTTP_READ_CONNECTION_TIMEOUT, HTTP_CONNECTION_TIMEOUT, username, password,
  2917.                 options);
  2918.     }  
  2919.     public static void checkHTTPS_trustAllCerts(String path,int readTimeout,int connectTimeout,String username,String password,
  2920.             HttpOptions ... options) throws UtilsException,HttpUtilsException{
  2921.         HttpRequest httpRequest = new HttpRequest();
  2922.         httpRequest.setUrl(path);
  2923.         httpRequest.setReadTimeout(readTimeout);
  2924.         httpRequest.setConnectTimeout(connectTimeout);
  2925.         httpRequest.setUsername(username);
  2926.         httpRequest.setPassword(password);
  2927.         httpRequest.setMethod(HttpRequestMethod.GET);
  2928.        
  2929.         httpRequest.setTrustAllCerts(true);
  2930.        
  2931.         if(options!=null && options.length>0) {
  2932.             for (HttpOptions httpOptions : options) {
  2933.                 httpOptions.fill(httpRequest);
  2934.             }
  2935.         }
  2936.        
  2937.         check(httpRequest);
  2938.        
  2939.     }
  2940.    
  2941.     public static void check(HttpRequest httpRequest) throws UtilsException,HttpUtilsException{
  2942.        
  2943.         HttpResponse response = null;
  2944.         try{
  2945.             response = httpInvoke(httpRequest);
  2946.            
  2947.         }catch(Exception e){
  2948.             throw new UtilsException(e.getMessage(),e);
  2949.         }
  2950.        
  2951.         check(response);
  2952.        
  2953.     }
  2954.    
  2955.     public static void check(HttpResponse response) throws HttpUtilsException{
  2956.         if(response.getResultHTTPOperation()!=200){
  2957.             if(response.getContent()!=null){
  2958.                 throw new HttpUtilsException(response.getResultHTTPOperation(), "Response Code ("+response.getResultHTTPOperation()+"): "+new String(response.getContent()));
  2959.             }
  2960.             else{
  2961.                 throw new HttpUtilsException(response.getResultHTTPOperation(), "Response Code ("+response.getResultHTTPOperation()+")");
  2962.             }
  2963.         }
  2964.     }
  2965.    
  2966.    
  2967.    
  2968.    
  2969.    
  2970.    
  2971.     /* ********* VALIDATE URI ************ */
  2972.    
  2973.     public static void validateUri(String uri,boolean checkEsistenzaFile) throws UtilsException,java.net.MalformedURLException{
  2974.        
  2975.         if (uri.startsWith("http://")
  2976.                 || uri.startsWith(TEST_FILE_ORIGIN)) {

  2977.             if(checkEsistenzaFile)
  2978.                 HttpUtilities.requestHTTPFile(uri);
  2979.             else
  2980.                 RegExpUtilities.validateUrl(uri);

  2981.         } else {
  2982.             File f = new File(uri);
  2983.             if(checkEsistenzaFile){
  2984.                 if(f.exists()==false){
  2985.                     throw new UtilsException("File non esistente");
  2986.                 }
  2987.                 else if(f.isDirectory()){
  2988.                     throw new UtilsException("File e' una directory");
  2989.                 }else if(f.canRead()==false){
  2990.                     throw new UtilsException("File non accessibile");
  2991.                 }
  2992.             }
  2993.         }
  2994.     }
  2995.    
  2996.    
  2997.     /* ********* DIGEST HEADER ************ */
  2998.    
  2999.     @Deprecated
  3000.     public static String getDigestHeaderValueByCommons(byte[] content, String algorithm) throws UtilsException{
  3001.         String digestValue = null;
  3002.         if(algorithm.equals(HttpConstants.DIGEST_ALGO_MD5)) {
  3003.             digestValue = DigestUtils.md5Hex(content);
  3004.         }
  3005.         else if(algorithm.equals(HttpConstants.DIGEST_ALGO_SHA_1) || algorithm.equals(HttpConstants.DIGEST_ALGO_SHA)) {
  3006.             digestValue = DigestUtils.sha1Hex(content);
  3007.         }
  3008.         else if(algorithm.equals(HttpConstants.DIGEST_ALGO_SHA_256)) {
  3009.             digestValue = DigestUtils.sha256Hex(content);
  3010.         }
  3011.         else if(algorithm.equals(HttpConstants.DIGEST_ALGO_SHA_384)) {
  3012.             digestValue = DigestUtils.sha384Hex(content);
  3013.         }
  3014.         else if(algorithm.equals(HttpConstants.DIGEST_ALGO_SHA_512)) {
  3015.             digestValue = DigestUtils.sha512Hex(content);
  3016.         }
  3017.         else {
  3018.             throw new UtilsException("Digest algorithm '"+algorithm+"' unsupported");
  3019.         }
  3020.         return algorithm+"="+digestValue;
  3021.     }
  3022.    
  3023.     public static String getDigestHeaderValue(byte[] content, String algorithm) throws UtilsException{
  3024.         // RFC 5843, il quale estende il precedente RFC 3230, vengono specificati sia gli algoritmi SHA 256 e 512 che la loro codifica, la quale deve essere base64.
  3025.         return getDigestHeaderValue(content, algorithm, DigestEncoding.BASE64);
  3026.     }
  3027.     public static String getDigestHeaderValue(byte[] content, String algorithm, DigestEncoding digestEncoding) throws UtilsException{
  3028.         boolean rfc3230 = true; // aggiunge prefisso algoritmo=
  3029.         return org.openspcoop2.utils.digest.DigestUtils.getDigestValue(content, algorithm, digestEncoding, rfc3230);
  3030.     }
  3031.     public static Map<DigestEncoding, String> getDigestHeaderValues(byte[] content, String algorithm, DigestEncoding ... digestEncoding) throws UtilsException{
  3032.         boolean rfc3230 = true; // aggiunge prefisso algoritmo=
  3033.         return org.openspcoop2.utils.digest.DigestUtils.getDigestValues(content, algorithm, rfc3230, digestEncoding);
  3034.     }
  3035. }