2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.sxp_ise_adapter.impl.util;
11 import com.sun.jersey.api.client.ClientResponse;
12 import com.sun.jersey.api.client.WebResource;
13 import java.io.StringReader;
14 import java.util.Iterator;
15 import javax.xml.XMLConstants;
16 import javax.xml.namespace.NamespaceContext;
17 import javax.xml.xpath.XPath;
18 import javax.xml.xpath.XPathFactory;
19 import org.xml.sax.InputSource;
22 * Purpose: provide common functionality upon ise reply message
24 public class IseReplyUtil {
26 public static final String EXPRESSION_SGT_ALL_LINK_HREFS = "/ns3:searchResult/ns3:resources/ns5:resource/link/@href";
27 public static final String EXPRESSION_SGT_DETAIL = "./ns4:sgt";
28 public static final String EXPRESSION_SGT_NAME_ATTR = "./@name";
29 public static final String EXPRESSION_SGT_VALUE = "./value/text()";
31 private IseReplyUtil() {
32 throw new IllegalAccessError("util class - no instances supported");
36 public static String deliverResponse(final WebResource.Builder requestBuilder) {
37 return requestBuilder.get(ClientResponse.class).getEntity(String.class);
41 * @return initiated xpath with ise namespace context injected
43 public static XPath setupXpath() {
44 final NamespaceContext nsContext = new NamespaceContext() {
45 public String getNamespaceURI(String prefix) {
48 throw new NullPointerException("Null prefix");
51 if ("ns5".equals(prefix)) {
52 outcome = "ers.ise.cisco.com";
53 } else if ("ns3".equals(prefix)) {
54 outcome = "v2.ers.ise.cisco.com";
55 } else if ("ns4".equals(prefix)) {
56 outcome = "trustsec.ers.ise.cisco.com";
58 outcome = XMLConstants.NULL_NS_URI;
63 // This method isn't necessary for XPath processing.
64 public String getPrefix(String uri) {
65 throw new UnsupportedOperationException();
68 // This method isn't necessary for XPath processing either.
69 public Iterator getPrefixes(String uri) {
70 throw new UnsupportedOperationException();
74 XPath xpath = XPathFactory.newInstance().newXPath();
75 xpath.setNamespaceContext(nsContext);
79 public static InputSource createInputSource(final String rawSgtDetail) {
80 return new InputSource(new StringReader(rawSgtDetail));