svn commit: r549635 - /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/HttpClient.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r549635 - /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/HttpClient.java

jaz-3
Author: jaz
Date: Thu Jun 21 15:26:44 2007
New Revision: 549635

URL: http://svn.apache.org/viewvc?view=rev&rev=549635
Log:
updated http client with additional settings

Modified:
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/HttpClient.java

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/HttpClient.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/HttpClient.java?view=diff&rev=549635&r1=549634&r2=549635
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/HttpClient.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/HttpClient.java Thu Jun 21 15:26:44 2007
@@ -46,7 +46,9 @@
     private boolean lineFeed = true;
     private boolean trustAny = false;
     private boolean followRedirects = true;
-    
+    private boolean keepAlive = false;
+
+    private String contentType = null;
     private String url = null;
     private String rawStream = null;
     private String clientCertAlias = null;
@@ -168,7 +170,27 @@
     public String getUrl() {
         return url;
     }
-    
+
+    /** Sets the content-type */
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+
+    /** Returns the content type */
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    /** Toggle keep-alive setting */
+    public void setKeepAlive(boolean keepAlive) {
+        this.keepAlive = keepAlive;
+    }
+
+    /** Return keep-alive setting */
+    public boolean getKeepAlive() {
+        return this.keepAlive;
+    }
+
     /** Sets the client certificate alias (from the keystore) to use for this SSL connection. */
     public void setClientCertificateAlias(String alias) {
         this.clientCertAlias = alias;
@@ -384,9 +406,9 @@
         try {
             requestUrl = new URL(url);
             if (overrideTrust) {
-                con = URLConnector.openUntrustedConnection(requestUrl, timeout, clientCertAlias, SSLUtil.HOSTCERT_NORMAL_CHECK);
+                con = URLConnector.openUntrustedConnection(requestUrl, timeout, clientCertAlias, hostVerification);
             } else {
-                con = URLConnector.openConnection(requestUrl, timeout, clientCertAlias, SSLUtil.HOSTCERT_NORMAL_CHECK);
+                con = URLConnector.openConnection(requestUrl, timeout, clientCertAlias, hostVerification);
             }
             if (Debug.verboseOn() || debug) Debug.log("Connection opened to : " + requestUrl.toExternalForm(), module);
 
@@ -395,14 +417,22 @@
                 if (Debug.verboseOn() || debug) Debug.log("Connection is of type HttpURLConnection", module);
             }
 
+            // set the content type
+            if (contentType != null) {
+                con.setRequestProperty("Content-type", contentType);
+            }
+
+            // connection settings
             con.setDoOutput(true);
             con.setUseCaches(false);
-            if (Debug.verboseOn() || debug) Debug.log("Do Input = true / Use Caches = false", module);
+            if (keepAlive) {
+                con.setRequestProperty("Connection", "Keep-Alive");
+            }
 
             if (method.equalsIgnoreCase("post")) {
-                con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
+                if (contentType == null)
+                    con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
                 con.setDoInput(true);
-                if (Debug.verboseOn() || debug) Debug.log("Set content type to : application/x-www-form-urlencoded", module);
             }
 
             if (headers != null && headers.size() > 0) {
@@ -415,8 +445,6 @@
                     con.setRequestProperty(headerName, headerValue);
                     if (Debug.verboseOn() || debug) Debug.log("Header : " + headerName + " -> " + headerValue, module);
                 }
-            } else {
-                if (Debug.verboseOn() || debug) Debug.log("No headers to set", module);
             }
 
             if (method.equalsIgnoreCase("post")) {