Question

Yesterday from one Play (1.2.x) controller I was able to get the JSON from another Play app on the same system as follows:

HttpResponse res = WS.url("http://localhost:9006/preferredRoute/pastThirtyDays")
        .setParameter("origin333", divergenceStation.station333.trim())
        .setParameter("originSt", divergenceStation.state)
        .setParameter("dest333", convergenceStation.station333.trim())
        .setParameter("destSt", convergenceStation.state)
        .post();

JsonElement json = res.getJson();

In the meantime I've changed the port, route and parameters names but have been accessing it via get in my browser all day long as follows:

http://localhost:9029/routes/historical/thirtydays?origin333=HOLLIDAY&originSt=KS&dest333=EMPORIA&destSt=KS&excludeStns=TOPEKA,KS

(Bear in mind "routes" is an overloaded term for us that has meaning in a business context) However when I try to access it similar to yesterday as follows:

HttpResponse res = WS.url("http://localhost:9029/routes/historical/thirtydays")
        .setParameter("origin333", origin333)
        .setParameter("originSt", originSt)
        .setParameter("dest333", dest333)
        .setParameter("destSt", destSt)
        .setParameter("viaStations", viaStations)
        .setParameter("excludeStns", excludeStns)
        .post();

JsonElement json = res.getJson();

The call to getJson() causes an error because its the 404 "route not found" HTML. I'm not understanding why the route not found only manifests when called in this manner and not directly using get in the browser.

Was it helpful?

Solution

How is your route defined?

As you said, your browser is going to be making the request via a GET but in your code you are calling WS.post(). If your route is expecting a GET then that's why you're getting a 404.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top