...
Code Block |
---|
title | Example curl command |
---|
|
curl 'httphttps://aai:8443/aai/v23/network/pnfs' |
...
Write code to show that it is possible to retrieve the current list of xNF functions.
Code Block |
---|
language | java |
---|
theme | Eclipse |
---|
title | PoC POC code |
---|
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI.URL;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import javax.net.ssl.net.http.HttpClientHostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javajavax.net.httpssl.HttpRequestTrustManager;
import javajavax.net.http.HttpResponse;
.ssl.X509TrustManager;
import lombok.Generated;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class InventoryRetriever {
private String getAaiServiceUrlHttps() {
final String version = "v23";
return "https://aai:8443/aai/" + version + "/network/pnfs";
public void}
/**
* get nfs from aai.
* @return []
*/
@Generated
public String getXnfsFromAai() throws NoSuchAlgorithmException, KeyManagementException {
final TrustManager[] trustAllCerts = new TrustManager[] {new String nfData;
X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() try{
HttpClient clientreturn =new HttpClientArrayList<X509Certificate>().newHttpClient(toArray(new X509Certificate[0]);
}
public void checkClientTrusted(final X509Certificate[] certs, final String aaiNetworkEndPoint = getAaiServiceUrl();
authType) {
}
public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
}
}
};
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
var request = HttpRequestHttpsURLConnection.newBuildersetDefaultSSLSocketFactory(URI.create(aaiNetworkEndPoint))
sc.getSocketFactory());
final HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
HttpsURLConnection.headers("Authorization", "Basic QUFJOkFBSQ==", "accept", "application/json",setDefaultHostnameVerifier(allHostsValid);
String nfData = "";
final String aaiNetworkEndPoint = getAaiServiceUrlHttps();
final URL url;
try {
url = new URL(aaiNetworkEndPoint);
final HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
"content-typeconn.setRequestProperty("Authorization", "Basic QUFJOkFBSQ==");
conn.setRequestProperty("accept", "application/json", "x-fromappid);
conn.setRequestProperty("conntent-type", "cps-ncmp",application/json");
conn.setRequestProperty("x-fromappid", "cps-ncmp");
conn.setRequestProperty("X-TransactionId", "get_aai_subscr");
log.info("Reader info before connn ");
conn.buildconnect();
log.info("Reader info after connn {}", conn.getResponseCode());
var response = clientlog.send(requestinfo("response message {}", HttpResponseconn.BodyHandlers.ofStringgetResponseMessage());
if (response.statusCode() == 200){nfData = responseReader(conn);
} catch (final IOException e) {
e.printStackTrace();
log.info("Reader info ERROR: in IR class ");
}
return nfData;
}
private String responseReader(final HttpsURLConnection conn) {
BufferedReader in = null;
final StringBuilder response = new StringBuilder();
try {
in = new BufferedReader(new InputStreamReader(
nfData = responseconn.bodygetInputStream(), StandardCharsets.UTF_8));
String inputLine;
while ((inputLine = System.out.println(nfDatain.readLine()) != null) {
response.append(inputLine);
}
in.close();
} catch (final IOException | InterruptedException e) {
e.printStackTrace();
} finally {
}
try {
if (in != null) {
in.close();
}
private} Stringcatch getAaiServiceUrl(final IOException e) {
String versionthrow = "v23"new RuntimeException(e);
return "http://aai:8443/aai/"+ version + "/network/pnfs"; }
}
return response.toString();
}
} |