Ask is moving to Stack Overflow and Serverfault.com! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode

0

Opendaylight REST & Parsing

asked 2014-12-02 04:02:47 -0800

anonymous user

Anonymous

Hello, I am trying to get the following code working. The rest call was working with GET command on CLI.Now I want to get the same REST call working through following programe and parse the XML output to get the specific information :

package org.opendaylight.controller.topology; import java.lang.*; import java.io.InputStream; import java.net.URL; import java.net.URLConnection;

import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller;

import org.apache.commons.codec.binary.Base64; import org.opendaylight.controller.sal.reader.FlowOnNode; import org.opendaylight.controller.statistics.northbound.AllFlowStatistics; import org.opendaylight.controller.statistics.northbound.FlowStatistics;

public class JAXBStatisticsClient {

public static void main(String[] args) {

System.out.println("Starting Statistics JAXB client.");

String baseURL = "http://127.0.0.1:8080/controller/nb/v2/statistics"; String containerName = "default"; String user = "admin"; String password = "admin";

URL url; try { url = new java.net.URL(baseURL + "/" + containerName + "/flow");

String authString = user + ":" + password; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); String authStringEnc = new String(authEncBytes); URLConnection connection = url.openConnection(); connection.setRequestProperty("Authorization", "Basic " + authStringEnc);

connection.setRequestProperty("Content-Type", "application/xml"); connection.setRequestProperty("Accept", "application/xml");

connection.connect();

JAXBContext context = JAXBContext.newInstance(AllFlowStatistics.class); Unmarshaller unmarshaller = context.createUnmarshaller();

InputStream inputStream = connection.getInputStream();

AllFlowStatistics result = (AllFlowStatistics) unmarshaller.unmarshal(inputStream);

System.out.println("We have these statistics:");

for (FlowStatistics statistics : result.getFlowStatistics()) { System.out.println(statistics.getNode().getNodeIDString()); System.out.println(statistics.getNode().getType()); for (FlowOnNode flowOnNode : statistics.getFlowStats()) { System.out.println("\t" + flowOnNode.getByteCount()); System.out.println("\t" + flowOnNode.getDurationNanoseconds()); System.out.println("\t" + flowOnNode.getDurationSeconds()); System.out.println("\t" + flowOnNode.getPacketCount()); System.out.println("\t" + flowOnNode.getTableId()); System.out.println("\t" + flowOnNode.getFlow()); } }

} catch (Exception e) { System.out.println(e.getLocalizedMessage()); } } }

But the above programe gives following Error: Exception in thread "main" java.lang.UnsupportedClassVersionError: org/opendaylight/controller/statistics/northbound/AllFlowStatistics : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:643) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) at java.net.URLClassLoader.access$000(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:212) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:323) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:268) at org.opendaylight.controller.topology.JAXBStatisticsClient.main(JAXBStatisticsClient.java:42)

can anyone help ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-02-13 03:07:42 -0800

Tony Tkacik gravatar image

Seems you are using unsupported version of Java. Please use Java 7 or higher, since Opendaylight project does not support Java 6.

http://stackoverflow.com/questions/10382929/unsupported-major-minor-version-51-0

edit flag offensive delete publish link more

Comments

Hi there. Is the above program an external application trying to get details from opendaylight through REST? . If so could you let me know where to get the library 'org.opendaylight.controller'.

Anbu ( 2015-02-18 23:37:18 -0800 )edit
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2014-12-02 04:02:47 -0800

Seen: 294 times

Last updated: Feb 13 '15