From a666b5f9741ef9b21f547d3b2141752a0383c70c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 20 九月 2022 17:07:38 +0800 Subject: [PATCH] 1、修改登录页面 2、修改阿里代码规范问题 --- src/java/org/apereo/cas/web/landtool/utils/HttpUtils.java | 74 ++++++++++++++++++++++++++---------- 1 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/java/org/apereo/cas/web/landtool/utils/HttpUtils.java b/src/java/org/apereo/cas/web/landtool/utils/HttpUtils.java index 5586e53..2ed8feb 100644 --- a/src/java/org/apereo/cas/web/landtool/utils/HttpUtils.java +++ b/src/java/org/apereo/cas/web/landtool/utils/HttpUtils.java @@ -33,10 +33,31 @@ public class HttpUtils { private static final String TAG = "HttpUtils"; - private static final int mReadTimeOut = 1000 * 10; // 10绉� - private static final int mConnectTimeOut = 1000 * 5; // 5绉� + + /** + * 10绉� + */ + private static final int READ_TIME_OUT = 1000 * 10; + + /** + * 5绉� + */ + private static final int CONNECT_TIME_OUT = 1000 * 5; + private static final String CHAR_SET = "UTF-8"; - private static final int mRetry = 2; // 榛樿灏濊瘯璁块棶娆℃暟 + + /** + * 榛樿灏濊瘯璁块棶娆℃暟 + */ + private static final int RETRY = 2; + + private static String mQ1="?"; + + private static char mQ2='?'; + + private static char mAnd='&'; + + private static String mHttps="https"; public static String get(String url) throws Exception { return get(url, null); @@ -53,11 +74,11 @@ } if (params != null && params.size() > 0) { - if (!url.contains("?")) { + if (!url.contains(mQ1)) { url += "?"; } - if (url.charAt(url.length() - 1) != '?') { + if (url.charAt(url.length() - 1) != mQ2) { url += "&"; } @@ -74,12 +95,12 @@ StringBuilder builder = new StringBuilder(); for (Map.Entry<String, ? extends Object> entry : params.entrySet()) { - if (entry.getKey() != null && entry.getValue() != null) - builder.append(entry.getKey().trim()).append("=") - .append(URLEncoder.encode(entry.getValue().toString(), CHAR_SET)).append("&"); + if (entry.getKey() != null && entry.getValue() != null) { + builder.append(entry.getKey().trim()).append("=").append(URLEncoder.encode(entry.getValue().toString(), CHAR_SET)).append("&"); + } } - if (builder.charAt(builder.length() - 1) == '&') { + if (builder.charAt(builder.length() - 1) == mAnd) { builder.deleteCharAt(builder.length() - 1); } @@ -89,19 +110,22 @@ private static String tryToGet(String url, Map<String, String> headers) throws Exception { int tryTime = 0; Exception ex = null; - while (tryTime < mRetry) { + while (tryTime < RETRY) { try { return doGet(url, headers); } catch (Exception e) { - if (e != null) + if (e != null) { ex = e; + } tryTime++; } } - if (ex != null) + if (ex != null) { throw ex; - else + } + else { throw new Exception("鏈煡缃戠粶閿欒 "); + } } private static String doGet(String strUrl, Map<String, String> headers) throws Exception { @@ -169,19 +193,22 @@ private static String tryToPost(String url, String postContent, Map<String, String> headers) throws Exception { int tryTime = 0; Exception ex = null; - while (tryTime < mRetry) { + while (tryTime < RETRY) { try { return doPost(url, postContent, headers); } catch (Exception e) { - if (e != null) + if (e != null) { ex = e; + } tryTime++; } } - if (ex != null) + if (ex != null) { throw ex; - else + } + else { throw new Exception("鏈煡缃戠粶閿欒 "); + } } private static String doPost(String strUrl, String postContent, Map<String, String> headers) throws Exception { @@ -229,10 +256,11 @@ } private static void configConnection(HttpURLConnection connection) { - if (connection == null) + if (connection == null) { return; - connection.setReadTimeout(mReadTimeOut); - connection.setConnectTimeout(mConnectTimeOut); + } + connection.setReadTimeout(READ_TIME_OUT); + connection.setConnectTimeout(CONNECT_TIME_OUT); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("User-Agent", @@ -243,7 +271,7 @@ if (strUrl == null) { return null; } - if (strUrl.toLowerCase().startsWith("https")) { + if (strUrl.toLowerCase().startsWith(mHttps)) { return getHttpsConnection(strUrl); } else { return getHttpConnection(strUrl); @@ -272,18 +300,22 @@ } private static X509TrustManager xtm = new X509TrustManager() { + @Override public void checkClientTrusted(X509Certificate[] chain, String authType) { } + @Override public void checkServerTrusted(X509Certificate[] chain, String authType) { } + @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; private static HostnameVerifier hnv = new HostnameVerifier() { + @Override public boolean verify(String hostname, SSLSession session) { return true; } -- Gitblit v1.9.3