i am trying to hit bgp ranking url but am getting html page as output , i want to get the json data in that hmtl page. how can we get the json data.
This is the controller and below that i have given the service implementation. can any body find out the issue
this is the BGP Ranking Url :https://bgp.he.net
Controller
@RestController
@RequestMapping(value = "/api/bgp")
public class BGPController {
@Autowired
BGPService bgpService;
@RequestMapping(value = "/getInfoById/{query}", method = RequestMethod.POST)
protected @ResponseBody Map<String, Object> getAllJobs(@PathVariable(value = "query") String query) {
Map<String, Object> dataMap = new HashMap<String, Object>();
try {
dataMap.put("status", true);
dataMap.put("result", bgpService.getRanking(query));
} catch (Exception e) {
dataMap.put("status", false);
dataMap.put("reason", e.getMessage());
System.err.println("exception at bgp: ");
e.printStackTrace();
}
System.out.println("dataMap: " + dataMap.toString());
return dataMap;
}
}
Service Implementation
@Service
@Component
public class BGPServiceImpl implements BGPService {
static CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet getRequest = null;
CloseableHttpResponse response = null;
BufferedReader br = null;
String stringJson = null;
StringEntity stringEntity = null;
String output = null;
String URL = "https://bgp.he.net/";
@Override
public Map<String, Object> getRanking(String query) {
Map<String, Object> dataMap = new HashMap<>();
try {
getRequest = new HttpGet(URL + query);
response = httpClient.execute(getRequest);
br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
String responseContent = "";
while ((output = br.readLine()) != null) {
responseContent += output;
}
if (response.getStatusLine().getStatusCode() == 200) {
dataMap.put("status", "success");
dataMap.put("rawData", responseContent);
} else {
dataMap.put("status", "failure");
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("dataMap: " + dataMap);
return dataMap;
}
}