1

I'm trying to use Java to use the Restful API at https://www.routexl.nl to get optimised travelling routes for some locations. At the moment I'm just using the example stuff on website but my lack of knowledge in Rest HTTP stuff is really holding me back. I had opted to use JavaLite but saw UniRest. Happy to use these or other Rest/HTTP clients.

Ideally I'm looking for some code which will send off an array of objects that have lat/longs and description information and return a sorted list of these objects using the shortest driving route but happy to get the code below working, which uses the example from the website.

This is why I've got so far:-

    //import com.mashape.unirest.http.HttpResponse;
//import com.mashape.unirest.http.JsonNode;
//import com.mashape.unirest.http.Unirest;
//import com.mashape.unirest.http.exceptions.UnirestException;
import org.javalite.http.Get;
import org.javalite.http.Http;
import org.javalite.http.Post;

public class RestClient {

  public static void main(String[] args)  {    
    Post post = Http.post("https://api.routexl.nl/tour", "locations=[{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.05429\",\"lng\":\"4.248618\"},{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.076892\",\"lng\":\"4.26975\"},{\"address\":\"Uden, The Netherlands\",\"lat\":\"51.669946\",\"lng\":\"5.61852\"},{\"address\":\"Sint-Oedenrode, The Netherlands\",\"lat\":\"51.589548\",\"lng\":\"5.432482\"}]")
             .header("Accept", "application/json")
             .header("Content-Type", "application/json")            
             .basic("USERNAME", "PASSWORD");
     System.out.println(post.text());
     System.out.println(post.responseMessage());                         
  }
}

And this is the output I get:-

No input found: 
Conflict

EDIT:- Got it working by removing the two headers. Anyone have any idea why that would be? EDIT2:- That makes sense RouteXL. OK here is another go which seems to work.

Post post2 = Http.post("https://api.routexl.nl/tour") .param("locations","[{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.05429\",\"lng\":\"4.248618\"},{\"address\":\"The Hague, The Netherlands\",\"lat\":\"52.076892\",\"lng\":\"4.26975\"},{\"address\":\"Uden, The Netherlands\",\"lat\":\"51.669946\",\"lng\":\"5.61852\"},{\"address\":\"Sint-Oedenrode, The Netherlands\",\"lat\":\"51.589548\",\"lng\":\"5.432482\"}]") .basic("USERNAME", "PASSWORD"); System.out.println(post2.text()); System.out.println(post2.responseMessage());

OutsideCoder
  • 346
  • 3
  • 16
  • This is probably a question for people running https://www.routexl.nl/, since JavaLite HTTP has no magic. For debugging, you also want to see the headers of the response next time you have an issue like that. – ipolevoy May 12 '17 at 07:20
  • Thanks for the response. Aye I tried to add routexl.nl to the question but I don't have enough reputation to add it. If you can feel free:) – OutsideCoder May 12 '17 at 08:40
  • Not a Java developer either, but you seem to have copied code from http://javalite.io/http#post-json-content while you are not posting JSON. Our API expects a regular post but the value of the locations parameter should be JSON encoded. Hope this explains... – RouteXL May 12 '17 at 18:36
  • That makes sense @RouteXL. I've done another solution which also works. Thanks. – OutsideCoder May 12 '17 at 19:34

0 Answers0