2 * Copyright 2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.aai.esr.externalservice.aai;
18 import java.io.IOException;
19 import java.io.StringReader;
20 import com.sun.jersey.api.client.ClientResponse;
21 import javax.xml.parsers.DocumentBuilder;
22 import javax.xml.parsers.DocumentBuilderFactory;
23 import javax.xml.parsers.ParserConfigurationException;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Node;
27 import org.w3c.dom.NodeList;
28 import org.xml.sax.InputSource;
29 import org.xml.sax.SAXException;
31 public class AaiCommon {
33 private static String AAI_AUTHENTICATION_USER = "AAI";
34 private static String AAI_AUTHENTICATION_PAASWORD = "AAI";
35 private static String RESOURCE_VERSION_PARAM = "resource-version";
37 // public String getAuthenticationCredentials() {
38 // String usernameAndPassword = AAI_AUTHENTICATION_USER + ":"
39 // + AAI_AUTHENTICATION_PAASWORD;
40 // return "Basic " + java.util.Base64.getEncoder().encodeToString("AAI:AAI".getBytes());
43 public String getResourceVersion(ClientResponse response)
44 throws ParserConfigurationException, SAXException, IOException {
45 String respData = response.getEntity(String.class);
47 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
48 DocumentBuilder builder = factory.newDocumentBuilder();
49 InputSource is = new InputSource(new StringReader(respData));
50 Document doc = builder.parse(is);
52 NodeList nodeList = doc.getDocumentElement().getChildNodes();
53 for (int i = 0; i < nodeList.getLength(); i++) {
54 Node currentNode = nodeList.item(i);
55 if (currentNode.getNodeName().equals(RESOURCE_VERSION_PARAM)) {
56 return currentNode.getTextContent();