Skip to content

Commit d3c67db

Browse files
committed
some improvements in Connectors and Debugger (sync with assist-server)
1 parent 5319871 commit d3c67db

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

src/main/java/net/b07z/sepia/server/core/tools/Connectors.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,19 @@ public static HttpClientResult httpGetSelfSignedSSL(String url) throws IOExcepti
189189
}
190190

191191
/**
192-
* HTTP GET method for JSON string. Check with {@code httpSuccess(...)} for status.
192+
* Make HTTP GET request to URL and get JSON response. Check with {@code httpSuccess(...)} for status.
193193
* @param url - URL address to call including all parameters
194-
* @return JSONObject response of URL call - Note: if response is not JSON it will be placed e.g. as "STRING" field in the result.
194+
* @return JSONObject response of URL call - Note:<br>
195+
* if response is not JSON it will be placed e.g. as "STRING" field in the result or "JSONARRAY" if it's an array.
195196
*/
196197
public static JSONObject httpGET(String url) {
197198
return httpGET(url, new String[0]);
198199
}
199200
/**
200-
* HTTP GET method for JSON string. Check with {@code httpSuccess(...)} for status.
201+
* Make HTTP GET request to URL and get JSON response. Check with {@code httpSuccess(...)} for status.
201202
* @param url - URL address to call including none or only some parameters
202203
* @param params - additional parameters added to URL (use e.g. "?q=search_term" or "&type=json" etc.)
203-
* @return JSONObject response of URL call - Note: if response is not JSON it will be placed e.g. as "STRING" field in the result.
204+
* @return JSONObject response of URL call - Note: if response is not JSON it will be placed e.g. as "STRING" field in the result or "JSONARRAY" if it's an array.
204205
*/
205206
public static JSONObject httpGET(String url, String[] params) {
206207
int responseCode = -1;
@@ -274,7 +275,7 @@ public static JSONObject httpGET(String url, String[] params) {
274275
*/
275276
public static JSONObject httpFormPOST(String targetURL, String urlParameters) {
276277

277-
HashMap<String, String> headers = new HashMap<>();
278+
Map<String, String> headers = new HashMap<>();
278279
headers.put("Content-Type", "application/x-www-form-urlencoded");
279280
headers.put("Content-Length", Integer.toString(urlParameters.getBytes().length));
280281
headers.put("Content-Language", "en-US");
@@ -288,7 +289,7 @@ public static JSONObject httpFormPOST(String targetURL, String urlParameters) {
288289
* @param headers - HashMap with request properties (keys) and values. If null uses 'application/json' as default.
289290
* @return JSONObject with response
290291
*/
291-
public static JSONObject httpPOST(String targetURL, String data, HashMap<String, String> headers) {
292+
public static JSONObject httpPOST(String targetURL, String data, Map<String, String> headers) {
292293
URL url;
293294
HttpURLConnection connection = null;
294295
int responseCode = -1;
@@ -384,7 +385,7 @@ public static JSONObject httpPOST(String targetURL, String data, HashMap<String,
384385
* @param headers - HashMap with request properties (keys) and values.
385386
* @return JSONObject with response
386387
*/
387-
public static JSONObject httpPUT(String targetURL, String data, HashMap<String, String> headers) {
388+
public static JSONObject httpPUT(String targetURL, String data, Map<String, String> headers) {
388389
URL url;
389390
HttpURLConnection connection = null;
390391
int responseCode = -1;
@@ -469,9 +470,8 @@ public static JSONObject httpPUT(String targetURL, String data, HashMap<String,
469470
//-------------DELETE--------------
470471

471472
/**
472-
* HTTP GET method for JSON string. Use {@code httpSuccess(...)} for status.
473-
* @param url - URL address to call including none or only some parameters
474-
* @param params - additional parameters added to URL (use e.g. "?q=search_term" or "&type=json" etc.)
473+
* Make HTTP DELETE request to URL and get JSON response.. Use {@code httpSuccess(...)} for status.
474+
* @param url - URL address to call including none or only some parameters/paths
475475
* @return
476476
*/
477477
public static JSONObject httpDELETE(String url) {
@@ -563,7 +563,7 @@ private static JSONObject build(String res, String successTag){
563563
//System.out.println(res); //debug
564564
if (Is.notNullOrEmpty(res)){
565565
res = (res.charAt(0) == '\uFEFF')? res.substring(1) : res;
566-
res = res.replaceAll("^(\\r+|\\n+|\\t+)", "").trim();
566+
res = res.replaceAll("^(\\r+|\\n+|\\t+)", "").trim(); //NOTE: this might have consequences for text formatting
567567
}
568568
//debug:
569569
/*

src/main/java/net/b07z/sepia/server/core/tools/Debugger.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Arrays;
44
import java.util.List;
55
import java.util.Map;
6+
import java.util.Map.Entry;
67

78
/**
89
* Used to debug code and log info.<br><br>
@@ -75,34 +76,18 @@ public static void sleep(long duration){
7576
}
7677

7778
/**
78-
* Print out a HashMap (String, String).
79+
* Print out a Map (String, any).
7980
*/
80-
public static void printMap_SS(Map<String, String> hm){
81-
for (Map.Entry<String, String> entry : hm.entrySet()) {
82-
System.out.println(entry.getKey() + " = " + entry.getValue());
83-
}
84-
}
85-
/**
86-
* Print out a HashMap (String, Long).
87-
*/
88-
public static void printMap_SL(Map<String, Long> hm){
89-
for (Map.Entry<String, Long> entry : hm.entrySet()) {
90-
System.out.println(entry.getKey() + " = " + entry.getValue());
91-
}
92-
}
93-
/**
94-
* Print out a HashMap (String, Object).
95-
*/
96-
public static void printMap_SO(Map<String, Object> hm){
97-
for (Map.Entry<String, Object> entry : hm.entrySet()) {
81+
public static void printMap(Map<String, ?> hm){
82+
for (Entry<String, ?> entry : hm.entrySet()) {
9883
System.out.println(entry.getKey() + " = " + entry.getValue());
9984
}
10085
}
10186
/**
10287
* Print out an ArrayList (String).
10388
*/
104-
public static void printList_S(List<String> list){
105-
for (String e : list){
89+
public static void printList(List<?> list){
90+
for (Object e : list){
10691
System.out.println("List element: " + e);
10792
}
10893
}

0 commit comments

Comments
 (0)