@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { long now = System.currentTimeMillis(); if (cachedString != null && (now - cachedFrom) < CACHE_FOR) { resp.getWriter().write(cachedString); log.info("Returning XML content from cache."); return; } HttpRequest trendReq = requestFactory.buildGetRequest(new GenericUrl("http://www.trendingtopics.org/pages.xml?page=1")); cachedString = SploutClient.asString(trendReq.execute().getContent()); log.info("Got XML content from trendingtopics: " + cachedString); cachedFrom = System.currentTimeMillis(); resp.getWriter().write(cachedString); } }
public DeployInfo deploy(final DeployRequest... requests) throws IOException { try { String strCont = JSONSerDe.ser(new ArrayList<DeployRequest>(Arrays.asList(requests))); HttpContent content = new StringHttpContent(strCont); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/deploy"), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), DeployInfo.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
public QueryStatus query(String tablespace, String key, String query, String partition) throws IOException { URI uri; try { uri = new URI("http", qNodesNoProtocol[(int) (Math.random() * qNodes.length)], "/api/query/" + tablespace, "&sql=" + query + (key != null ? "&key=" + key : "") + (partition != null ? "&partition=" + partition : ""), null); HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri.toASCIIString())); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch(JSONSerDeException e) { throw new IOException(e); } } catch(URISyntaxException e) { throw new IllegalArgumentException(e); } }
public QueryStatus query(String tablespace, String key, String query, String partition) throws IOException { URI uri; try { uri = new URI("http", qNodesNoProtocol[(int) (Math.random() * qNodes.length)], "/api/query/" + tablespace, "&sql=" + query + (key != null ? "&key=" + key : "") + (partition != null ? "&partition=" + partition : "") , null); HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri.toASCIIString())); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch (JSONSerDeException e) { throw new IOException(e); } } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
public QNodeStatus overview() throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/overview")); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), QNodeStatus.class); } catch(JSONSerDeException e) { throw new IOException(e); } }
public Tablespace tablespace(String tablespace) throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/tablespace/" + tablespace)); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), Tablespace.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
@SuppressWarnings("unchecked") public List<String> dNodeList() throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/dnodelist")); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), ArrayList.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
public DeployInfo deploy(final DeployRequest... requests) throws IOException { try { String strCont = JSONSerDe.ser(new ArrayList<DeployRequest>(Arrays.asList(requests))); HttpContent content = new StringHttpContent(strCont); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/deploy"), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), DeployInfo.class); } catch(JSONSerDeException e) { throw new IOException(e); } }
public Tablespace tablespace(String tablespace) throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/tablespace/" + tablespace)); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), Tablespace.class); } catch(JSONSerDeException e) { throw new IOException(e); } }
@SuppressWarnings("unchecked") public List<String> dNodeList() throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/dnodelist")); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), ArrayList.class); } catch(JSONSerDeException e) { throw new IOException(e); } }
public StatusMessage cancelDeploy(long version) throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/canceldeployment?version=" + version)); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), StatusMessage.class); } catch (JSONSerDeException e) { throw new IOException(e); } } }
public QNodeStatus overview() throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/overview")); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), QNodeStatus.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
public QueryStatus queryPost(String tablespace, String key, String query, String partition) throws IOException { Map<String, Object> params = new HashMap<String, Object>(); params.put("sql", query); params.put("key", new String[]{key}); params.put("partition", partition); try { HttpContent content = new StringHttpContent(JSONSerDe.ser(params)); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/query/" + tablespace), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
public QueryStatus queryPost(String tablespace, String key, String query, String partition) throws IOException { Map<String, Object> params = new HashMap<String, Object>(); params.put("sql", query); params.put("key", new String[] { key }); params.put("partition", partition); try { HttpContent content = new StringHttpContent(JSONSerDe.ser(params)); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/query/" + tablespace), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch(JSONSerDeException e) { throw new IOException(e); } } }