public State getState() { if (isNotFound()) return State.NOT_FOUND; if (isNotModified()) return State.UNMODIFIED; if (isOk()) return State.UPDATED; return State.OTHER; }
public HttpRequestException(TaggedData tag) { super(tag.getUrl() + ":" + tag.getResponseCode() + ":" + tag.getTag()); this.responseCode = tag.getResponseCode(); }
public boolean isOk() { return getResponseCode() / 100 == 2; }
@Override public String toString() { return "TaggedData [tag=" + getTag() + ", code=" + getResponseCode() + ", modified=" + new Date(getModified()) + ", url=" + getUrl() + ", state=" + getState() + (message == null ? "" : ", msg=" + message) + "]"; }
public URLConnectionHandler findMatchingHandler(URL url) throws Exception { for (URLConnectionHandler urlh : getURLConnectionHandlers()) { if (urlh.matches(url)) { logger.debug("Decorate {} with handler {}", url, urlh); return urlh; } else logger.debug("No match for {}, handler {}", url, urlh); } return null; }
@Override public void close() throws IOException { IO.close(getInputStream()); } }
public ProxySetup getProxySetup(URL url) throws Exception { init(); for (ProxyHandler ph : getProxyHandlers()) { ProxySetup setup = ph.forURL(url); if (setup != null) { logger.debug("Proxy {}", setup); return setup; } } return null; }
@Override public String toString() { return "TaggedData [tag=" + getTag() + ", code=" + getResponseCode() + ", modified=" + new Date(getModified()) + ", url=" + getUrl() + ", state=" + getState() + (message == null ? "" : ", msg=" + message) + "]"; }
public HttpRequestException(TaggedData tag) { super(tag.getUrl() + ":" + tag.getResponseCode() + ":" + tag.getTag()); this.responseCode = tag.getResponseCode(); }
public State getState() { if (isNotFound()) return State.NOT_FOUND; if (isNotModified()) return State.UNMODIFIED; if (isOk()) return State.UPDATED; return State.OTHER; }
@Override public void close() throws IOException { IO.close(getInputStream()); } }
public boolean isOk() { return getResponseCode() / 100 == 2; }
@Override public void handle(URLConnection connection) throws Exception { for (URLConnectionHandler h : registry.getPlugins(URLConnectionHandler.class)) { h.handle(connection); } }
@Override public InputStream connect(URL url) throws IOException { if (url == null) throw new IOException("Can't connect to null URL"); TaggedData data = connectTagged(url); return data.getInputStream(); }
public void handle(URLConnection connection) throws Exception { for (URLConnectionHandler h : registry.getPlugins(URLConnectionHandler.class)) { h.handle(connection); } }
@Override public void handle(URLConnection connection) throws Exception { for (URLConnectionHandler h : registry.getPlugins(URLConnectionHandler.class)) { h.handle(connection); } }
public void handle(URLConnection connection) throws Exception { for (URLConnectionHandler h : registry.getPlugins(URLConnectionHandler.class)) { h.handle(connection); } }
private URLConnection getProxiedAndConfiguredConnection(URL url, ProxySetup proxy) throws IOException, Exception { final URLConnection urlc = proxy != null ? url.openConnection(proxy.proxy) : url.openConnection(); URLConnectionHandler matching = findMatchingHandler(url); if (matching == null) return urlc; matching.handle(urlc); return urlc; }