Hi,
I am trying to integrate Indeed using mashape api. I am getting response for first time but second time call is getting stuck and not responding. Below are the code, this works fine when i=0 in for loop, it stuck in api call when i=1:
private static final String INDEED_API_URL = “https://indeed-indeed.p.mashape.com/apisearch?publisher=<indeed_key>&q=%s&l=%s&”
+ “sort=date&radius=&st=&jt=&start=&limit=20&fromage=1&filter=&latlong=%s&co=%s&chnl=&userip=%s&useragent=%s&v=2&format=xml”;
private static final String INDEED_DETAILS_API_URL = “https://indeed-indeed.p.mashape.com/apigetjobs?publisher=<indeed_key>&jobkeys=%s&v=2&format=xml”;
public static void main(String args[]) throws Exception {
String url = null;
HttpResponse<InputStream> jsonResponse = null;
SAXReader reader = null;
Document profileData = null;
try {
String[] skill = {"java","html", "hibernate"};
for (int i = 0; i < 3; i++) {
url = String.format(INDEED_API_URL, skill[i],"Bangalore","12.975275,77.5989","in","1.2.3.4","Mozilla/5.0");
jsonResponse = Unirest.get(url).header("X-Mashape-Authorization", "W7dRtgxCBckCIuTE1oFYvEdXwmkHTK60").asBinary();
reader = new SAXReader();
profileData = null;
profileData = reader.read(jsonResponse.getBody());
writetofile1(profileData.asXML(), i+"indeed.xml");
List<Element> list = profileData.selectNodes("//jobkey");
StringBuffer key = new StringBuffer();
for (Element element : list) {
String jobkey = element.getTextTrim();
key.append(jobkey);
key.append(",");
}
url = String.format(INDEED_DETAILS_API_URL, key);
jsonResponse = null;
System.out.println("BEFORE CALL");
jsonResponse = Unirest.get(url).header("X-Mashape-Authorization", "W7dRtgxCBckCIuTE1oFYvEdXwmkHTK60").asBinary();
System.out.println("AFTER CALL");
reader = new SAXReader();
profileData = null;
profileData = reader.read(jsonResponse.getBody());
//writetofile1(profileData.asXML(), i+"detail.xml");
}
} catch (Exception e) {
throw new ApplicationException(Constant.STATUS_FAILURE, Constant.STATUS_CODE_SERVICE_FAILED, Constant.MESSAGE_SERVICE_DATABASE_FAILED);
}
}
Can you please help me here.
Thanks
Join in the discussion - add comment below:
I got this to work using unirest-java’s async feature. Please see a similar issue and solution here - https://www.mashape.com/worldtimeengine/worldtime-io-developer#!issues?id=2
Thanks. This is working with asyn call
I tried multiple options, i think it is always causing same issue when i make 3rd api call in a row. Please try that.
pankajgoyal, could you share the code you used to get it it work? thanks!