Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The above command returns a list of all the pnfs 

PoC code:

Write code to show that it is possible to retrieve the current list of xNF functionsThe below is Proof Of Concept code and it is not production ready. With this code, we are able to retrieve list of network functions from A&AI.

Code Block
languagejava
themeEclipse
firstline1
titlePOC code for Inventory Retriever
linenumberstrue
collapsetrue
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.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.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class InventoryRetriever {

    private String getAaiServiceUrlHttps() {
        final String version = "v23";
        return "https://aai:8443/aai/" + version + "/network/pnfs";
    }

    public String getXnfsFromAai() throws NoSuchAlgorithmException, KeyManagementException {

        final TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new ArrayList<X509Certificate>().toArray(new X509Certificate[0]);
            }

            public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
            }

            public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
            }
        }
        };

        final SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        final HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(final String hostname, final SSLSession session) {
                return true;
            }
        };

        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
        String nfData = "";
        final String aaiNetworkEndPoint = getAaiServiceUrlHttps();
        final URL url;
        try {
            url = new URL(aaiNetworkEndPoint);
            final HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
            conn.setRequestProperty("Authorization", "Basic QUFJOkFBSQ==");
            conn.setRequestProperty("accept", "application/json");
            conn.setRequestProperty("conntent-type", "application/json");
            conn.setRequestProperty("x-fromappid", "cps-ncmp");
            conn.setRequestProperty("X-TransactionId", "get_aai_subscr");
            conn.connect();
            nfData = responseReader(conn);

        } catch (final IOException e) {
            e.printStackTrace();
        }
        return nfData;
    }
    
    private String responseReader(final HttpsURLConnection conn) {
        BufferedReader in = null;
        final StringBuilder response = new StringBuilder();
        try {
            in = new BufferedReader(new InputStreamReader(
                    conn.getInputStream(), StandardCharsets.UTF_8));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
        } catch (final IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (final IOException e) {
                throw new RuntimeException(e);
            }
        }
        return response.toString();
    }
    
}

What to do next?

To write production ready code, the following things will need to be done.

1) User Story to implement One way SSL communication needed to make Https calls.

 - Currently the project is not set up to make HTTPS calls. For the POC the following code was added to workaround this issue.

Code Block
languagejava
themeEclipse
firstline1
titleWorkaround Code for making HTTPS calls
linenumberstrue
collapsetrue
        final TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new ArrayList<X509Certificate>().toArray(new X509Certificate[0]);
            }

            public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
            }

            public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
            }
        }
        };

        final SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        final HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(final String hostname, final SSLSession session) {
                return true;
            }
        };


2) User story to implement retrieving of the current list of xNF functions