Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server now use aks provided by client side (#2132)
- Loading branch information
1 parent
5c963f5
commit 759b7a5
Showing
19 changed files
with
250 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...e_engine/data_load_tools/src/main/java/com/alibaba/maxgraph/dataload/util/HttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.alibaba.maxgraph.dataload.util; | ||
|
||
import org.apache.commons.codec.binary.Base64; | ||
|
||
import java.io.IOException; | ||
import java.net.Authenticator; | ||
import java.net.HttpURLConnection; | ||
import java.net.PasswordAuthentication; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* Simple HTTPClient which refer from <a href="https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/url/auth/HttpClient.java">...</a> | ||
*/ | ||
public class HttpClient { | ||
|
||
private final String user; | ||
private final String password; | ||
|
||
public HttpClient() { | ||
this("", ""); | ||
} | ||
|
||
public HttpClient(String user, String password) { | ||
this.user = user; | ||
this.password = password; | ||
} | ||
|
||
public int sendRequestWithAuthHeader(String url) throws IOException { | ||
HttpURLConnection connection = null; | ||
try { | ||
connection = createConnection(url); | ||
connection.setRequestProperty("Authorization", createBasicAuthHeaderValue()); | ||
return connection.getResponseCode(); | ||
} finally { | ||
if (connection != null) { | ||
connection.disconnect(); | ||
} | ||
} | ||
} | ||
|
||
public int sendRequestWithAuthenticator(String url) throws IOException { | ||
setAuthenticator(); | ||
HttpURLConnection connection = null; | ||
try { | ||
connection = createConnection(url); | ||
return connection.getResponseCode(); | ||
} finally { | ||
if (connection != null) { | ||
connection.disconnect(); | ||
} | ||
} | ||
} | ||
|
||
public HttpURLConnection createConnection(String urlString) throws IOException { | ||
URL url = new URL(urlString); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
return connection; | ||
} | ||
|
||
private String createBasicAuthHeaderValue() { | ||
String auth = user + ":" + password; | ||
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.UTF_8)); | ||
return "Basic " + new String(encodedAuth); | ||
} | ||
|
||
private void setAuthenticator() { | ||
Authenticator.setDefault(new BasicAuthenticator()); | ||
} | ||
|
||
private final class BasicAuthenticator extends Authenticator { | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(user, password.toCharArray()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.