Java Problems
This was a bigger pain then I realized. The Java web server I am using is Tomcat and I am using struts 2 as the framework to create pages. The version of curl for java is under developed so for what I needed it to do it would not cut so I had to find a different solution. I was thinking that maybe the standard api for java would have something but once again it was also not fully developed. I finally came across Apache Jakarta Project HttpClient package. This saved the day and I got it contacting the remote server through Http Authentication using NTLM and on through https. I would like to note that JBDC owns. Getting my script to connect to a db2 server was a pain in php I had to set up a obdc connection and download a good amount of ibm software. With Java all u need is the jar with the DB2 drivers and the use the jdbc to contact the server.
XML Problems
Another interesting problem was that parsing the xml I would get back from the site. Java has some generic xml packages but I couldn't find any information on how to use them. So I solved this problem with Xerces-J another Apache project that is a package used to parse xml. I used a SAX parser to get the info from the xml.
Current Problem (waiting for ajax response inside a timed interval)
So everything is working fine now but there is a bug that I am trying to solve which is driving me crazy with the ajax. Essentially what I am trying to do is make a function that ask the server if new information is available in a given interval. But if the request takes longer than the interval I want it to wait for it to get the response from the server. Right now it just ask every interval regardless if it gets a response back. So to solve this dilemma, I thought why not make a while loop that checks if the request is running. If it is, continue waiting in the loop. Else, go back to normal operation. So what I came up with is something like:
refresh.periodical(1000ms,this)
function refresh{
stop the timed function calls
make ajax call
while(ajax.running==true){
}
start timed function calls again
}
The only problem with this is that javascript is single threaded so the while loop takes over and doesn't let anything else happen. in fact it caused the browser to freeze up. So i need to figure out a way to resolve this situation. It's a bit annoying that when javascript sends a request it doesn't wait for it to get a response it just continues executing.
No comments:
Post a Comment