Ask Your Question

Opendaylight REST & Parsing

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

anonymous user


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; import; import;

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 = ""; String containerName = "default"; String user = "admin"; String password = "admin";

URL url; try { url = new + "/" + 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");


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( at at at$000( at$ at Method) at at java.lang.ClassLoader.loadClass( at sun.misc.Launcher$AppClassLoader.loadClass( at java.lang.ClassLoader.loadClass( at org.opendaylight.controller.topology.JAXBStatisticsClient.main(

can anyone help ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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

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.

edit flag offensive delete publish link more


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 -0700 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower


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

Seen: 290 times

Last updated: Feb 13 '15