Skip to content

Commit e58e274

Browse files
committed
javadoc added
1 parent 90258de commit e58e274

26 files changed

+2194
-1136
lines changed

core/src/main/java/com/otc/sdk/core/auth/signer/Signer.java

Lines changed: 398 additions & 249 deletions
Large diffs are not rendered by default.

core/src/main/java/com/otc/sdk/core/auth/signer/SigningAlgorithm.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
package com.otc.sdk.core.auth.signer;
1717

18+
/**
19+
* Enum representing the signing algorithms used in the SDK.
20+
* This enum includes HmacSHA256 and HmacSM3 as supported signing algorithms.
21+
*/
1822
public enum SigningAlgorithm {
1923
HmacSHA256,
2024
HmacSM3;

core/src/main/java/com/otc/sdk/core/auth/vo/SignResult.java

Lines changed: 82 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,87 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23+
/**
24+
* SignResult class represents the result of a signing operation.
25+
* It contains headers, URL, parameters, and an input stream associated with the
26+
* signed request.
27+
*/
2328
public class SignResult {
24-
private Map<String, String> headers = new HashMap<>();
25-
private URL url;
26-
private Map<String, String> parameters = new HashMap<>();
27-
private InputStream inputStream;
28-
29-
public Map<String, String> getHeaders() {
30-
return this.headers;
31-
}
32-
33-
public void setHeaders(Map<String, String> headers) {
34-
this.headers = headers;
35-
}
36-
37-
public URL getUrl() {
38-
return this.url;
39-
}
40-
41-
public void setUrl(URL url) {
42-
this.url = url;
43-
}
44-
45-
public Map<String, String> getParameters() {
46-
return this.parameters;
47-
}
48-
49-
public void setParameters(Map<String, String> parameters) {
50-
this.parameters = parameters;
51-
}
52-
53-
public InputStream getInputStream() {
54-
return this.inputStream;
55-
}
56-
57-
public void setInputStream(InputStream inputStream) {
58-
this.inputStream = inputStream;
59-
}
29+
private Map<String, String> headers = new HashMap<>();
30+
private URL url;
31+
private Map<String, String> parameters = new HashMap<>();
32+
private InputStream inputStream;
33+
34+
/**
35+
* Gets the headers of the signed request.
36+
*
37+
* @return The headers of the signed request
38+
*/
39+
public Map<String, String> getHeaders() {
40+
return this.headers;
41+
}
42+
43+
/**
44+
* Sets the headers for the signed request.
45+
*
46+
* @param headers The headers to set
47+
*/
48+
public void setHeaders(Map<String, String> headers) {
49+
this.headers = headers;
50+
}
51+
52+
/**
53+
* Gets the URL of the signed request.
54+
*
55+
* @return The URL of the signed request
56+
*/
57+
public URL getUrl() {
58+
return this.url;
59+
}
60+
61+
/**
62+
* Sets the URL for the signed request.
63+
*
64+
* @param url The URL to set
65+
*/
66+
public void setUrl(URL url) {
67+
this.url = url;
68+
}
69+
70+
/**
71+
* Gets the parameters of the signed request.
72+
*
73+
* @return The parameters of the signed request
74+
*/
75+
public Map<String, String> getParameters() {
76+
return this.parameters;
77+
}
78+
79+
/**
80+
* Sets the parameters for the signed request.
81+
*
82+
* @param parameters The parameters to set
83+
*/
84+
public void setParameters(Map<String, String> parameters) {
85+
this.parameters = parameters;
86+
}
87+
88+
/**
89+
* Gets the input stream associated with the signed request.
90+
*
91+
* @return The input stream of the signed request
92+
*/
93+
public InputStream getInputStream() {
94+
return this.inputStream;
95+
}
96+
97+
/**
98+
* Sets the input stream for the signed request.
99+
*
100+
* @param inputStream The input stream to set
101+
*/
102+
public void setInputStream(InputStream inputStream) {
103+
this.inputStream = inputStream;
104+
}
105+
60106
}

core/src/main/java/com/otc/sdk/core/http/HttpMethodName.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515

1616
package com.otc.sdk.core.http;
1717

18+
/**
19+
* Enum representing the HTTP method names used in requests.
20+
* This enum includes common HTTP methods such as GET, POST, PUT, DELETE, HEAD,
21+
* PATCH, and OPTIONS.
22+
*/
1823
public enum HttpMethodName {
19-
GET,
20-
POST,
21-
PUT,
22-
DELETE,
23-
HEAD,
24-
PATCH,
25-
OPTIONS;
24+
GET,
25+
POST,
26+
PUT,
27+
DELETE,
28+
HEAD,
29+
PATCH,
30+
OPTIONS;
2631
}

core/src/main/java/com/otc/sdk/core/util/BinaryUtils.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,38 @@
1717

1818
import java.util.Locale;
1919

20+
/**
21+
* Utility class for binary operations, specifically for converting byte arrays
22+
* to hexadecimal strings.
23+
* This class provides a method to convert a byte array into a hexadecimal
24+
* string representation.
25+
*/
2026
public class BinaryUtils {
21-
public static String toHex(byte[] data) {
22-
StringBuffer sbuff = new StringBuffer(data.length * 2);
23-
byte[] var2 = data;
24-
int var3 = data.length;
2527

26-
for(int var4 = 0; var4 < var3; ++var4) {
27-
byte bye = var2[var4];
28-
String hexStr = Integer.toHexString(bye);
29-
if (hexStr.length() == 1) {
30-
sbuff.append("0");
31-
} else if (hexStr.length() == 8) {
32-
hexStr = hexStr.substring(6);
33-
}
28+
/**
29+
* Converts a byte array to a hexadecimal string.
30+
* Each byte is represented by two hexadecimal characters.
31+
*
32+
* @param data The byte array to convert
33+
* @return A string representing the hexadecimal values of the byte array
34+
*/
35+
public static String toHex(byte[] data) {
36+
StringBuffer sbuff = new StringBuffer(data.length * 2);
37+
byte[] var2 = data;
38+
int var3 = data.length;
3439

35-
sbuff.append(hexStr);
40+
for (int var4 = 0; var4 < var3; ++var4) {
41+
byte bye = var2[var4];
42+
String hexStr = Integer.toHexString(bye);
43+
if (hexStr.length() == 1) {
44+
sbuff.append("0");
45+
} else if (hexStr.length() == 8) {
46+
hexStr = hexStr.substring(6);
3647
}
3748

38-
return sbuff.toString().toLowerCase(Locale.getDefault());
39-
}
49+
sbuff.append(hexStr);
50+
}
51+
52+
return sbuff.toString().toLowerCase(Locale.getDefault());
53+
}
4054
}

core/src/main/java/com/otc/sdk/core/util/Constant.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
package com.otc.sdk.core.util;
1717

18+
/**
19+
* Constant class that holds various constants used throughout the SDK.
20+
* It includes settings for SSL verification, protocol names, signature algorithms,
21+
* cipher suites, and secure random algorithms.
22+
*/
1823
public final class Constant {
1924
// verify ssl certificate (true) or do not verify (false)
2025
public static final boolean DO_VERIFY = false;

core/src/main/java/com/otc/sdk/core/util/HostName.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,28 @@
1515

1616
package com.otc.sdk.core.util;
1717

18+
/**
19+
* HostName utility class to manage and validate host names.
20+
* It provides methods to set a URL host name and check if a given SSL host name
21+
* matches the set URL host name.
22+
*/
1823
public class HostName {
19-
private static String urlHostName;
24+
private static String urlHostName;
2025

21-
public static void setUrlHostName(String hostName) {
22-
urlHostName = hostName;
23-
}
26+
/**
27+
* Sets the URL host name.
28+
*/
29+
public static void setUrlHostName(String hostName) {
30+
urlHostName = hostName;
31+
}
2432

25-
public static boolean checkHostName(String SSLHostName) {
26-
return urlHostName.equals(SSLHostName);
27-
}
33+
/**
34+
* Checks if the provided SSL host name matches the set URL host name.
35+
*
36+
* @param SSLHostName The SSL host name to check
37+
* @return true if the SSL host name matches the URL host name, false otherwise
38+
*/
39+
public static boolean checkHostName(String SSLHostName) {
40+
return urlHostName.equals(SSLHostName);
41+
}
2842
}

core/src/main/java/com/otc/sdk/core/util/HttpUtils.java

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,63 @@
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424

25+
/**
26+
* HttpUtils class provides utility methods for handling HTTP-related tasks,
27+
* such as URL encoding.
28+
* It includes methods to encode URLs and handle specific character
29+
* replacements.
30+
*/
2531
public class HttpUtils {
26-
private static final String DEFAULT_ENCODING = "UTF-8";
27-
private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtils.class);
28-
private static final Pattern ENCODED_CHARACTERS_PATTERN;
32+
private static final String DEFAULT_ENCODING = "UTF-8";
33+
private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtils.class);
34+
private static final Pattern ENCODED_CHARACTERS_PATTERN;
2935

30-
public static String urlEncode(String rawValue, boolean path) throws UnsupportedEncodingException {
31-
if (rawValue == null) {
32-
return "";
33-
} else {
34-
try {
35-
String encoded = URLEncoder.encode(rawValue, DEFAULT_ENCODING);
36-
Matcher match = ENCODED_CHARACTERS_PATTERN.matcher(encoded);
36+
/**
37+
* Encodes a raw value for use in a URL, replacing specific characters as
38+
* needed.
39+
*
40+
* @param rawValue The raw value to encode
41+
* @param path If true, special handling for path segments is applied
42+
* @return The encoded string
43+
* @throws UnsupportedEncodingException If the encoding is not supported
44+
*/
45+
public static String urlEncode(String rawValue, boolean path) throws UnsupportedEncodingException {
46+
if (rawValue == null) {
47+
return "";
48+
} else {
49+
try {
50+
String encoded = URLEncoder.encode(rawValue, DEFAULT_ENCODING);
51+
Matcher match = ENCODED_CHARACTERS_PATTERN.matcher(encoded);
3752

38-
StringBuffer buffer;
39-
String replacementTemp;
40-
for(buffer = new StringBuffer(encoded.length()); match.find(); match.appendReplacement(buffer, replacementTemp)) {
41-
replacementTemp = match.group(0);
42-
if ("+".equals(replacementTemp)) {
43-
replacementTemp = "%20";
44-
} else if ("*".equals(replacementTemp)) {
45-
replacementTemp = "%2A";
46-
} else if ("%7E".equals(replacementTemp)) {
47-
replacementTemp = "~";
48-
} else if (path && "%2F".equals(replacementTemp)) {
49-
replacementTemp = "/";
50-
}
51-
}
53+
StringBuffer buffer;
54+
String replacementTemp;
55+
for (buffer = new StringBuffer(encoded.length()); match.find(); match.appendReplacement(buffer,
56+
replacementTemp)) {
57+
replacementTemp = match.group(0);
58+
if ("+".equals(replacementTemp)) {
59+
replacementTemp = "%20";
60+
} else if ("*".equals(replacementTemp)) {
61+
replacementTemp = "%2A";
62+
} else if ("%7E".equals(replacementTemp)) {
63+
replacementTemp = "~";
64+
} else if (path && "%2F".equals(replacementTemp)) {
65+
replacementTemp = "/";
66+
}
67+
}
5268

53-
match.appendTail(buffer);
54-
return buffer.toString();
55-
} catch (UnsupportedEncodingException var6) {
56-
LOGGER.info("fail to encode url: ", var6.getMessage());
57-
throw var6;
58-
}
69+
match.appendTail(buffer);
70+
return buffer.toString();
71+
} catch (UnsupportedEncodingException var6) {
72+
LOGGER.info("fail to encode url: ", var6.getMessage());
73+
throw var6;
5974
}
60-
}
75+
}
76+
}
6177

62-
static {
63-
StringBuilder pattern = new StringBuilder();
64-
pattern.append(Pattern.quote("+")).append("|").append(Pattern.quote("*")).append("|").append(Pattern.quote("%7E")).append("|").append(Pattern.quote("%2F"));
65-
ENCODED_CHARACTERS_PATTERN = Pattern.compile(pattern.toString());
66-
}
78+
static {
79+
StringBuilder pattern = new StringBuilder();
80+
pattern.append(Pattern.quote("+")).append("|").append(Pattern.quote("*")).append("|").append(Pattern.quote("%7E"))
81+
.append("|").append(Pattern.quote("%2F"));
82+
ENCODED_CHARACTERS_PATTERN = Pattern.compile(pattern.toString());
83+
}
6784
}

0 commit comments

Comments
 (0)