% /** * @author DC Dalton davidcdalton.com * @version 1.5 * Revised 9-18 to add timeouts to connection and exception handling for a timeout * Unless you are fluent in Java and JSP You should NOT touch any code between this comment and the comment box below! */ String pageID = (request.getParameter("PageID") != null && request.getParameter("PageID").trim().length() != 0) ? request.getParameter("PageID").trim() : ""; String action = (request.getParameter("Action") != null && request.getParameter("Action").trim().length() != 0) ? request.getParameter("Action").trim() : ""; String pageNumber = (request.getParameter("page") != null && request.getParameter("page").trim().length() != 0) ? request.getParameter("page").trim() : ""; boolean blnComplete = (request.getParameter("blnComplete") != null && request.getParameter("blnComplete").trim().length() != 0) ? true : false; String cDomain = request.getServerName(); cDomain = cDomain.replaceAll("www.", ""); String cParm = "?domain=" + cDomain; cParm += "&agent=" + java.net.URLEncoder.encode(request.getHeader("User-Agent"), "UTF-8"); cParm += "&referer=" + request.getHeader("referer"); cParm += "&address=" + request.getRemoteAddr(); cParm += "&query=" + request.getQueryString(); cParm += "&blnComplete=" + blnComplete; cParm += "&page=" + pageNumber; cParm += "&url" + request.getRequestURI(); cParm += "&cScript=jsp"; cParm += "&Action=" + action; /* get the meta tags for the page */ String address = (pageID.trim().length() !=0) ? "http://www.mysearchexchange.com/ArticleMeta.asp" + cParm + "&PageID=" + pageID : "http://www.mysearchexchange.com/ArticleMeta.asp" + cParm; /* connect to their server to get the meta data */ String metaData = ""; boolean timed_out = false; try { java.net.URL blackwood = new java.net.URL(address); java.net.URLConnection blackwoodConnection = blackwood.openConnection(); blackwoodConnection.setConnectTimeout(6000); // set timeout to 6 seconds java.io.DataInputStream dis = new java.io.DataInputStream(blackwoodConnection.getInputStream()); String inputLine; while ((inputLine = dis.readLine()) != null) { metaData += inputLine; } dis.close(); // close the input stream (releases memory) } catch (java.net.MalformedURLException me) { // someone has messed around with the url code above out.println("MalformedURLException: the url you are sending to the feed server is incorrect in some way."); } catch (java.net.SocketTimeoutException toe) { timed_out = true; // don't print anything out to the page } catch (java.io.IOException ioe) { // any IO error, a 404 (not found) a major league time out etc etc out.println("
An error has occured in the streaming code, please review your settings. If your settings appear to be correct the error may be because the feed server is temporarly down.
"); } /* the returning meta data is delimited by ~, split it into an array */ String [] metaInfo = metaData.split("~"); /* if they are on any page except page 1 we add the page number to the site title */ String siteTitle = (pageNumber.trim().length() !=0) ? metaInfo[0].trim() + " - " + pageNumber : metaInfo[0].trim(); /* get the actual page content */ address = (pageID.trim().length() != 0) ? "http://www.mysearchexchange.com/Article.asp" + cParm + "&PageID=" + pageID : "http://www.mysearchexchange.com/Article.asp" + cParm; /** * End do not touch code */ if (!timed_out) { %>|
<%
/**
* Unless you are fluent in Java and JSP You should NOT touch any code between this comment and the comment box below!
* also do not alter the JSP code between the title tags, the description meta tag or the keywords meta tag
*/
try {
java.net.URL blackwood = new java.net.URL(address);
java.net.URLConnection blackwoodConnection = blackwood.openConnection();
java.io.DataInputStream dis = new java.io.DataInputStream(blackwoodConnection.getInputStream());
String inputLine;
while ((inputLine = dis.readLine()) != null) {
out.print(inputLine + "\n"); // we have to print out one line at a time or the returned js for google ads will screw up!
}
dis.close(); // close the input stream (releases memory)
}
catch (java.net.MalformedURLException me) { // someone has messed around with the url code above
out.println(" MalformedURLException: the url you are sending to the feed server is incorrect in some way. "); } catch (java.io.IOException ioe) { // any IO error, a 404 (not found) a major league time out etc etc out.println("An error has occured in the streaming code, please review your settings. If your settings appear to be correct the error may be because the feed server is temporarly down. "); } /** * End do not touch code */ %> |