Skip to content

Commit

Permalink
made results handling more fault tolerant
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Nov 15, 2012
1 parent 332dbee commit 9c5c7a6
Showing 1 changed file with 50 additions and 37 deletions.
Expand Up @@ -99,32 +99,17 @@ protected InputStream getContentXML(String viewId) throws Exception {
root.appendChild(cookieEl);

// INFO: Get user interests and clickstream
Iterable<String> userInterests;
Iterable<String> clickStream;
try {
userInterests = getUserInterests(service, cookieVal, boost_domain, api_key);
clickStream = getClickstream(service, cookieVal, boost_domain, api_key);
} catch(ServiceException e) {
// No interests or clickstream
log.error(e, e);

Element exceptionEl = doc.createElementNS(NAMESPACE, "exception");
exceptionEl.appendChild(doc.createTextNode(e.getMessage()));
root.appendChild(exceptionEl);

Element errEl = doc.createElementNS(NAMESPACE, "no-profile");
root.appendChild(errEl);
return XMLHelper.getInputStream(doc, false, false, null);
}

// INFO: Add all interests to user profile
Element interestsEl = doc.createElementNS(NAMESPACE, "interests");
for(String interest : userInterests) {
Element interestEl = doc.createElementNS(NAMESPACE, "interest");
interestEl.appendChild(doc.createTextNode(interest));
interestsEl.appendChild(interestEl);
}
root.appendChild(interestsEl);
Iterable<String> userInterests = getUserInterests(service, cookieVal, boost_domain, api_key);

// INFO: Add all interests to user profile
Element interestsEl = doc.createElementNS(NAMESPACE, "interests");
for(String interest : userInterests) {
Element interestEl = doc.createElementNS(NAMESPACE, "interest");
interestEl.appendChild(doc.createTextNode(interest));
interestsEl.appendChild(interestEl);
}
root.appendChild(interestsEl);

// INFO: Search for related content in data repository of this realm
Element resultsEl = doc.createElementNS(NAMESPACE, "search-results");
Expand Down Expand Up @@ -159,20 +144,48 @@ protected InputStream getContentXML(String viewId) throws Exception {
res_node.appendChild(res_time);
}
}
root.appendChild(resultsEl);

// INFO: Add clickstream to user profile
Element clickstreamEl = doc.createElementNS(NAMESPACE, "clickstream");
for(String url : clickStream) {
Element urlEl = doc.createElementNS(NAMESPACE, "url");
urlEl.appendChild(doc.createTextNode(url));
if (clickstreamEl.hasChildNodes()) {
clickstreamEl.insertBefore(urlEl, clickstreamEl.getFirstChild());
} else {
clickstreamEl.appendChild(urlEl);
root.appendChild(resultsEl);
} catch(ServiceException e) {
// Something wrong with retrieving interests...
log.error(e, e);

Element exceptionEl = doc.createElementNS(NAMESPACE, "exception");
exceptionEl.appendChild(doc.createTextNode(e.getMessage()));
root.appendChild(exceptionEl);

Element errEl = doc.createElementNS(NAMESPACE, "no-profile");
root.appendChild(errEl);
//return XMLHelper.getInputStream(doc, false, false, null);
}

try {
Iterable<String> clickStream = getClickstream(service, cookieVal, boost_domain, api_key);

// INFO: Add clickstream to user profile
Element clickstreamEl = doc.createElementNS(NAMESPACE, "clickstream");
for(String url : clickStream) {
Element urlEl = doc.createElementNS(NAMESPACE, "url");
urlEl.appendChild(doc.createTextNode(url));
if (clickstreamEl.hasChildNodes()) {
clickstreamEl.insertBefore(urlEl, clickstreamEl.getFirstChild());
} else {
clickstreamEl.appendChild(urlEl);
}
}
root.appendChild(clickstreamEl);
} catch(ServiceException e) {
// Something wrong with retrieving clickstream...
log.error(e, e);

Element exceptionEl = doc.createElementNS(NAMESPACE, "exception");
exceptionEl.appendChild(doc.createTextNode(e.getMessage()));
root.appendChild(exceptionEl);

Element errEl = doc.createElementNS(NAMESPACE, "no-clickstream");
root.appendChild(errEl);
//return XMLHelper.getInputStream(doc, false, false, null);
}
root.appendChild(clickstreamEl);


return XMLHelper.getInputStream(doc, false, false, null);
}
Expand Down

0 comments on commit 9c5c7a6

Please sign in to comment.