OpenDaylight Rest API with Java -


Before posting this question, I'm sure how to ask.

I am trying to connect to the Open Daylight Controller with Java, I am trying to connect by consuming the rest of the services provided by the controller. My problem is, when I send an HTTP request, I can not get more than the entry, I'm not sure that this is possible. Instead of getting topology or other answers from the controller, I'm getting the HTML of the entry form.

Besides, I'm not sure that I should be connected in this way.

Any help / guidance is highly appreciated :)

My code is for making connections:

  public string getContent (string url) IOException throws {String cont = ""; CloseableHttpClient httpclient = HttpClients.createDefault (); Http post http post = new HTTP post (url); List & lt; NameValuePair & gt; Nvps = new arreelist & lt; NamevaluePair & gt; (); Nvps.add (new binarynamewallpayer ("j_username", "username")); nvps.add (new binarynamewallpayer ("j_password", "password")); httpPost.setEntity (new UrlEncodedFormEntity (nvps)); CloseableHttpResponse response2 = httpclient.execute (httpPost); try {system.out.println (response2.getStatusLine ()); HttpEntity entity2 = response2.getEntity (); BufferedReader Reader = New BufferedReader (New InputStreamReader (entity2.getContent ())); String line = ""; While ((line = reader. Readline ()) = null) {cont + = line + "\ n"; }} Finally {response2.close (); } For return; }   

When I run the code, this is what is printed:

HTTP / 1.1 200 OK

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Title & gt; Open Daylight - Login & lt; / Title & gt; & Lt; script src = "/ js / bootstrap.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; Less = {env: "production"}; & Lt; / Script & gt; & Lt; script src = "/ js / less-1.3.3.min.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form action = "j_security_check; jsessionid = LONGID" id = "form" method = "post" & gt; & Lt; Div class = "container" & gt; & Lt; Div class = "content" & gt; & Lt; Div class = "login-form" & gt; & Lt; Div id = "logo" & gt; & Lt; / Div & gt; & Lt; Fieldset & gt; & Lt; Div class = "control-group" & gt; & Lt; Input type = "text" name = "j_username" placeholder = "user name" & gt; & Lt; / Div & gt; & Lt; Div class = "control-group" & gt; & Lt; Input type = "password" name = "j_password" placeholder = "password" & gt; & Lt; / Div & gt; & Lt; Button class = "btn btn-primary" type = "submit" value = "sign in" & gt; & Lt; div class = "icon-login" & gt; & Lt; / Div & gt; Sign in & lt; / Button & gt; & Lt; / Fieldset & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt; The problem authentication seems to be encoded with username and password in Base64.   

You can download the Commons-Codec Library

  from java.io.buffferedReader; Import java.io.InputStream; Import java.io.InputStreamReader; Import java.net.HttpURLConnection; Import java.net.URL; Import org.apache.commons.codec.binary.Base64; Public class OpenDayLightUtils {public static zero getFlowDetails () {string user = "admin"; String password = "admin"; String baseURL = "http://192.168.100.1:8080/controller/nb/v2/flowprogrammer"; String container name = "default"; Try {// URL = Base URL + Container URL URL = Create new URL (Bersur + "/" + "ContainerName); // Create a certification string and base 64 string authStr = user + ":" + password; String encoded and STR = base64.exodebase 64 string (authStr.getBytes ()); // Create HTTP Connection HttpURL Connection Connection = (HttpURLConnection) url.openConnection (); // Set connection properties connection.setRequestMethod ("GET"); connection.setRequestProperty ("authorization", "basic" + encoded STR); connection.setRequestProperty ("Accept", "App / JS"); // Receive feedback from inputStream InputStream content of connection = (InputStream) connection.getInputStream (); BufferedReader = New in BufferedReader (New InputStreamReader (Content)); String line = ""; While ((line = r. rummy ()) = null) {System.out.println (line); }} Hold (exception e) {e.printStackTrace (); }}}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -