@Override protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean isReady; try { isReady = getRecommender().isReady(); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); return; } if (isReady) { response.setStatus(HttpServletResponse.SC_OK); } else { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } }
private boolean isPartitionReady(int partition) throws TasteException { String urlPath = "/ready"; TasteException savedException = null; for (HostAndPort replica : partitions.get(partition)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath, "HEAD"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: return true; case HttpURLConnection.HTTP_UNAVAILABLE: return false; default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }
@Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return; } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); long userID; long itemID; try { userID = Long.parseLong(pathComponents.next()); itemID = Long.parseLong(pathComponents.next()); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } catch (NumberFormatException nfe) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString()); return; } MyrrixRecommender recommender = getRecommender(); try { recommender.removePreference(userID, itemID); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } }
recommender.setPreference(userID, itemID, prefValue); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
@Override protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { MyrrixRecommender recommender = getRecommender(); try { FastIDSet ids = isUserIDs() ? recommender.getAllUserIDs() : recommender.getAllItemIDs(); outputIDs(request, response, ids); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } }
log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) {
recommender.setUserTag(userID, userTag, tagValue); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
recommender.setItemTag(itemTag, itemID, tagValue); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
private void getAllIDsFromPartition(int partition, boolean user, FastIDSet result) throws TasteException { String urlPath = '/' + (user ? "user" : "item") + "/allIDs"; TasteException savedException = null; for (HostAndPort replica : partitions.get(partition)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath, "GET"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: consumeIDs(connection, result); return; case HttpURLConnection.HTTP_UNAVAILABLE: throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }
log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) {
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { MyrrixRecommender recommender = getRecommender(); RescorerProvider rescorerProvider = getRescorerProvider(); try { IDRescorer rescorer = rescorerProvider == null ? null : rescorerProvider.getMostPopularItemsRescorer(recommender, getRescorerParams(request)); output(request, response, recommender.mostPopularItems(getHowMany(request), rescorer)); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } catch (IllegalArgumentException iae) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString()); } }
log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) {
log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) {
log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) {
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } catch (IllegalArgumentException iae) {
@Test public void testNSUException() { // Just make sure this all doesn't, ah, throw an exception TasteException te1 = new NoSuchUserException(); TasteException te4 = new NoSuchUserException(te1.toString()); te4.printStackTrace(new PrintStream(new ByteArrayOutputStream())); te4.printStackTrace(new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()))); }
@Test public void testNSIException() { // Just make sure this all doesn't, ah, throw an exception TasteException te1 = new NoSuchItemException(); TasteException te4 = new NoSuchItemException(te1.toString()); te4.printStackTrace(new PrintStream(new ByteArrayOutputStream())); te4.printStackTrace(new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()))); }
@Test public void testTasteException() { // Just make sure this all doesn't, ah, throw an exception TasteException te1 = new TasteException(); TasteException te2 = new TasteException(te1); TasteException te3 = new TasteException(te2.toString(), te2); TasteException te4 = new TasteException(te3.toString()); te4.printStackTrace(new PrintStream(new ByteArrayOutputStream())); te4.printStackTrace(new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()))); }
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } catch (IllegalArgumentException iae) {