using webservice from java servlet
Posted: Thu Jun 23, 2011 4:28 am
Hi All
I am a bit dumbfounded as to why this occurs but here goes:
My setup -
ubuntu server hosting latest tera-wurfl with mysql 5 and php 5
clients are on windows tomcat 7 machines using java servlets and jsp's
occasionally I get an empty response string from the webservice. I use this code to access it:
Boolean work = true;
String decode = "";
String ho = "";
try {
ua = request_ua;
URL u = new URL((Config.teraWurfl + "ua=" + ua + "&search=model_name|brand_name|j2me_midp_1_0|j2me_midp_2_0|match&format=json").replaceAll(" ", "%20"));
URLConnection connect = u.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
while((ho = in.readLine()) != null) {
decode += ho;
}
in.close();
if(!decode.isEmpty()) {
JSONParser parser = new JSONParser();
JSONObject orig = (((JSONObject) parser.parse(decode)));
if (orig != null) {
JSONObject obj = ((JSONObject) orig.get("capabilities"));
if (obj != null) {
brand = obj.get("brand_name").toString();
model = obj.get("model_name").toString();
midp1 = (Boolean) obj.get("j2me_midp_1_0");
midp2 = (Boolean) obj.get("j2me_midp_2_0");
match = (Boolean) obj.get("match");
if (brand == null || model == null || midp1 == null || midp2 == null || match == null) {
work = false;
}
} else {
work = false;
}
} else {
work = false;
}
}
else
work = false;
} catch (Exception ex) {
work = false;
ex.printStackTrace();
}
where the ua is passed via method parameter
as of now, whenever this occurs I fall back to java wurfl using the same ua which always works.
Any thoughts, suggestions?
Thank You in advance
Dylan
I am a bit dumbfounded as to why this occurs but here goes:
My setup -
ubuntu server hosting latest tera-wurfl with mysql 5 and php 5
clients are on windows tomcat 7 machines using java servlets and jsp's
occasionally I get an empty response string from the webservice. I use this code to access it:
Boolean work = true;
String decode = "";
String ho = "";
try {
ua = request_ua;
URL u = new URL((Config.teraWurfl + "ua=" + ua + "&search=model_name|brand_name|j2me_midp_1_0|j2me_midp_2_0|match&format=json").replaceAll(" ", "%20"));
URLConnection connect = u.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
while((ho = in.readLine()) != null) {
decode += ho;
}
in.close();
if(!decode.isEmpty()) {
JSONParser parser = new JSONParser();
JSONObject orig = (((JSONObject) parser.parse(decode)));
if (orig != null) {
JSONObject obj = ((JSONObject) orig.get("capabilities"));
if (obj != null) {
brand = obj.get("brand_name").toString();
model = obj.get("model_name").toString();
midp1 = (Boolean) obj.get("j2me_midp_1_0");
midp2 = (Boolean) obj.get("j2me_midp_2_0");
match = (Boolean) obj.get("match");
if (brand == null || model == null || midp1 == null || midp2 == null || match == null) {
work = false;
}
} else {
work = false;
}
} else {
work = false;
}
}
else
work = false;
} catch (Exception ex) {
work = false;
ex.printStackTrace();
}
where the ua is passed via method parameter
as of now, whenever this occurs I fall back to java wurfl using the same ua which always works.
Any thoughts, suggestions?
Thank You in advance
Dylan