public HttpDownload(String userAgent, URL src, InputStreamWrapper dest) { super(true); setUserAgent(userAgent); if (src == null) throw new IllegalArgumentException("source URL cannot be null"); if (dest == null) throw new IllegalArgumentException("destination wrapper cannot be null"); this.remoteURL = src; this.wrapper = dest; }
/** * Constructor. If the user agent string is not supplied, a default value will be generated. * <p> * The src URL cannot be null. If the protocol is https, this class will get the current Subject from * the AccessControlContext and use the Certificate(s) and PrivateKey(s) found there to set up an * SSLSocketFactory. This is required if ther server requests that the client authenticate itself. * </p> * <p> * The dest output stream cannot be null. * </p> * * @param userAgent user-agent string to report in HTTP headers * @param src URL to read * @param dest output stream to write to */ public HttpDownload(String userAgent, URL src, OutputStream dest) { super(true); setUserAgent(userAgent); if (src == null) throw new IllegalArgumentException("source URL cannot be null"); if (dest == null) throw new IllegalArgumentException("destination stream cannot be null"); this.remoteURL = src; this.destStream = dest; }
setUserAgent(userAgent);
public ExecutionPhase getPhase(String jobID) throws JobNotFoundException, JobPersistenceException { try { URL u = new URL(baseURL.toExternalForm() + "/" + jobID); ByteArrayOutputStream out = new ByteArrayOutputStream(); HttpDownload get = new HttpDownload(u, out); get.setUserAgent(this.getClass().getName()); get.run(); if (get.getThrowable() != null) { if (get.getThrowable().getMessage().contains("not found")) throw new JobNotFoundException("not found: " + jobID); throw new JobPersistenceException("failed to get " + jobID, get.getThrowable()); } String phase = out.toString().trim(); log.debug("phase: " + phase); ExecutionPhase ret = ExecutionPhase.toValue(phase); return ret; } catch(MalformedURLException bug) { throw new RuntimeException("BUG - failed to create valid URL", bug); } }