You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2024/01/29 10:23:51 UTC

(ofbiz-plugins) branch trunk updated: Improved: URL constructor is deprecated in Java 20 (OFBIZ-12881)

This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 43e74a70a Improved: URL constructor is deprecated in Java 20 (OFBIZ-12881)
43e74a70a is described below

commit 43e74a70a503d26765e2411d59878853b879f40b
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Mon Jan 29 11:22:50 2024 +0100

    Improved: URL constructor is deprecated in Java 20 (OFBIZ-12881)
    
    Explanation: https://inside.java/2023/02/15/quality-heads-up/
---
 ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java              | 4 ++--
 ebay/src/main/java/org/apache/ofbiz/ebay/ProductsExportToEbay.java    | 4 ++--
 ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java     | 2 +-
 .../main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java   | 3 ++-
 .../java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java | 3 ++-
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java b/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java
index a1ce2c3e1..9cc5fbd51 100644
--- a/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java
+++ b/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java
@@ -26,7 +26,6 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.math.BigDecimal;
 import java.net.HttpURLConnection;
-import java.net.URL;
 import java.sql.Timestamp;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
@@ -41,6 +40,7 @@ import java.util.Map;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilMisc;
 import org.apache.ofbiz.base.util.UtilProperties;
+import org.apache.ofbiz.base.util.UtilURL;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.base.util.UtilXml;
 import org.apache.ofbiz.entity.Delegator;
@@ -110,7 +110,7 @@ public class EbayHelper {
         if (Debug.verboseOn()) {
             Debug.logVerbose("Request of " + callName + " To eBay:\n" + generatedXmlData.toString(), MODULE);
         }
-        HttpURLConnection connection = (HttpURLConnection) (new URL(postItemsUrl)).openConnection();
+        HttpURLConnection connection = (HttpURLConnection) (UtilURL.fromUrlString(postItemsUrl)).openConnection();
         connection.setDoInput(true);
         connection.setDoOutput(true);
         connection.setRequestMethod("POST");
diff --git a/ebay/src/main/java/org/apache/ofbiz/ebay/ProductsExportToEbay.java b/ebay/src/main/java/org/apache/ofbiz/ebay/ProductsExportToEbay.java
index aa9140167..f571c256b 100755
--- a/ebay/src/main/java/org/apache/ofbiz/ebay/ProductsExportToEbay.java
+++ b/ebay/src/main/java/org/apache/ofbiz/ebay/ProductsExportToEbay.java
@@ -24,7 +24,6 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
-import java.net.URL;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -37,6 +36,7 @@ import org.apache.ofbiz.base.util.UtilCodec;
 import org.apache.ofbiz.base.util.UtilGenerics;
 import org.apache.ofbiz.base.util.UtilMisc;
 import org.apache.ofbiz.base.util.UtilProperties;
+import org.apache.ofbiz.base.util.UtilURL;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.base.util.UtilXml;
 import org.apache.ofbiz.entity.Delegator;
@@ -141,7 +141,7 @@ public class ProductsExportToEbay {
         if (Debug.verboseOn()) {
             Debug.logVerbose("Request of " + callName + " To eBay:\n" + dataItems.toString(), MODULE);
         }
-        HttpURLConnection connection = (HttpURLConnection) (new URL(postItemsUrl)).openConnection();
+        HttpURLConnection connection = (HttpURLConnection) (UtilURL.fromUrlString(postItemsUrl)).openConnection();
         connection.setDoInput(true);
         connection.setDoOutput(true);
         connection.setRequestMethod("POST");
diff --git a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java
index 74ea5b34c..d84b8d2ef 100644
--- a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java
+++ b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java
@@ -168,7 +168,7 @@ public class EbayStore {
         if (Debug.verboseOn()) {
             Debug.logVerbose("Request of " + callName + " To eBay:\n" + dataItems.toString(), MODULE);
         }
-        HttpURLConnection connection = (HttpURLConnection) (new URL(postItemsUrl)).openConnection();
+        HttpURLConnection connection = (HttpURLConnection) (UtilURL.fromUrlString(postItemsUrl)).openConnection();
         connection.setDoInput(true);
         connection.setDoOutput(true);
         connection.setRequestMethod("POST");
diff --git a/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java b/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java
index fc381705b..a579fe7b7 100644
--- a/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java
+++ b/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java
@@ -44,6 +44,7 @@ import javax.xml.xpath.XPathFactory;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilHttp;
 import org.apache.ofbiz.base.util.UtilProperties;
+import org.apache.ofbiz.base.util.UtilURL;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.base.util.UtilXml;
 import org.apache.ofbiz.entity.Delegator;
@@ -194,7 +195,7 @@ public class JanrainHelper {
         }
         String data = sb.toString();
         try {
-            URL url = new URL(baseUrl + "/api/v2/" + methodName);
+            URL url = UtilURL.fromUrlString(baseUrl + "/api/v2/" + methodName);
             HttpURLConnection conn = (HttpURLConnection) url.openConnection();
             conn.setRequestMethod("POST");
             conn.setDoOutput(true);
diff --git a/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java b/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java
index 8e327b59e..c93d3307b 100644
--- a/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java
+++ b/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java
@@ -33,6 +33,7 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.ofbiz.base.util.UtilURL;
 import org.apache.ofbiz.base.util.UtilXml;
 import org.apache.ofbiz.ldap.commons.AbstractOFBizAuthenticationHandler;
 import org.apache.ofbiz.ldap.commons.InterfaceOFBizAuthenticationHandler;
@@ -77,7 +78,7 @@ public final class OFBizCasAuthenticationHandler extends AbstractOFBizAuthentica
             response.sendRedirect(casUrl + loginUri + "?" + PARAM_SERVICE + "=" + url);
         } else {
             // there's a ticket, we should validate the ticket
-            URL validateURL = new URL(casUrl + validateUri + "?" + PARAM_TICKET + "=" + ticket + "&" + PARAM_SERVICE + "=" + url);
+            URL validateURL = UtilURL.fromUrlString(casUrl + validateUri + "?" + PARAM_TICKET + "=" + ticket + "&" + PARAM_SERVICE + "=" + url);
             URLConnection conn = validateURL.openConnection();
             try (InputStreamReader result = new InputStreamReader(conn.getInputStream(), "UTF-8");
                      BufferedReader reader = new BufferedReader(result)) {