public NotTalkingToJenkinsException(URLConnection c) { super("There's no Jenkins running at " + c.getURL().toString()); } }
DownloadUrlConnection(URLConnection connection, IRedirectHandler redirectHandler) { this.connection = connection; this.url = connection.getURL(); this.redirectHandler = redirectHandler; }
/** * Returns the URL. * * @return null if the class file could not be obtained. */ public URL find(String classname) { try { URLConnection con = openClassfile0(classname); InputStream is = con.getInputStream(); if (is != null) { is.close(); return con.getURL(); } } catch (IOException e) {} return null; }
public static String dumpHeaders(URLConnection conn) { StringBuilder sb = new StringBuilder(); Iterator<?> it = conn.getHeaderFields().keySet().iterator(); sb.append('\n'); sb.append("<HEADERS url=\"" + conn.getURL().toString() + "\">"); while (it.hasNext()) { String name = (String) it.next(); sb.append('\n'); sb.append("[" + name + "]:"); sb.append(conn.getHeaderField(name)); } sb.append('\n'); sb.append("</HEADERS>"); return sb.toString(); }
/** * If the server advertises CLI endpoint, returns its location. * @deprecated Specific to {@link Mode#REMOTING}. */ @Deprecated protected CliPort getCliTcpPort(URL url) throws IOException { if (url.getHost()==null || url.getHost().length()==0) { throw new IOException("Invalid URL: "+url); } URLConnection head = url.openConnection(); try { head.connect(); } catch (IOException e) { throw (IOException)new IOException("Failed to connect to "+url).initCause(e); } String h = head.getHeaderField("X-Jenkins-CLI-Host"); if (h==null) h = head.getURL().getHost(); String p1 = head.getHeaderField("X-Jenkins-CLI-Port"); if (p1==null) p1 = head.getHeaderField("X-Hudson-CLI-Port"); // backward compatibility String p2 = head.getHeaderField("X-Jenkins-CLI2-Port"); String identity = head.getHeaderField("X-Instance-Identity"); flushURLConnection(head); if (p1==null && p2==null) { verifyJenkinsConnection(head); throw new IOException("No X-Jenkins-CLI2-Port among " + head.getHeaderFields().keySet()); } if (p2!=null) return new CliPort(new InetSocketAddress(h,Integer.parseInt(p2)),identity,2); else return new CliPort(new InetSocketAddress(h,Integer.parseInt(p1)),identity,1); }
/** * Returns the URL. * * @return null if the class file could not be obtained. */ public URL find(String classname) { try { URLConnection con = openClassfile0(classname); InputStream is = con.getInputStream(); if (is != null) { is.close(); return con.getURL(); } } catch (IOException e) {} return null; }
/** * Returns the URL. * * @return null if the class file could not be obtained. */ @Override public URL find(String classname) { try { URLConnection con = openClassfile0(classname); InputStream is = con.getInputStream(); if (is != null) { is.close(); return con.getURL(); } } catch (IOException e) {} return null; }
/** * Returns the URL. * * @return null if the class file could not be obtained. */ @Override public URL find(String classname) { try { URLConnection con = openClassfile0(classname); InputStream is = con.getInputStream(); if (is != null) { is.close(); return con.getURL(); } } catch (IOException e) {} return null; }
public InputStream progessMonitoredInputStream(URLConnection c, String msg) throws IOException { InputStream in = c.getInputStream(); int length = c.getContentLength(); return wrapGzip(progressMonitoredInputStream(in, length, msg), c.getURL()); }
public URL loadGroovySource(String className) throws MalformedURLException { String filename; for (String extension : getConfig().getScriptExtensions()) { filename = className.replace('.', File.separatorChar) + "." + extension; try { URLConnection dependentScriptConn = rc.getResourceConnection(filename); return dependentScriptConn.getURL(); } catch (ResourceException e) { //TODO: maybe do something here? } } return rl.loadGroovySource(className); } });
/** * Get the class of the scriptName in question, so that you can instantiate * Groovy objects with caching and reloading. * * @param scriptName resource name pointing to the script * @return the loaded scriptName as a compiled class * @throws ResourceException if there is a problem accessing the script * @throws ScriptException if there is a problem parsing the script */ public Class loadScriptByName(String scriptName) throws ResourceException, ScriptException { URLConnection conn = rc.getResourceConnection(scriptName); String path = conn.getURL().toExternalForm(); ScriptCacheEntry entry = scriptCache.get(path); Class clazz = null; if (entry != null) clazz = entry.scriptClass; try { if (isSourceNewer(entry)) { try { String encoding = conn.getContentEncoding() != null ? conn.getContentEncoding() : config.getSourceEncoding(); String content = IOGroovyMethods.getText(conn.getInputStream(), encoding); clazz = groovyLoader.parseClass(content, path); } catch (IOException e) { throw new ResourceException(e); } } } finally { forceClose(conn); } return clazz; }
String finalName = name + "." + ext; URLConnection conn = rc.getResourceConnection(finalName); URL url = conn.getURL(); String path = url.toExternalForm(); ScriptCacheEntry entry = scriptCache.get(path);
try { cache.get(depSourcePath); cu.addSource(getResourceConnection(depSourcePath).getURL()); } catch (ResourceException e) {
String getShareURL(String strURL) { URLConnection conn = null; String redirectedUrl = null; try { URL inputURL = new URL(strURL); conn = inputURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); System.out.println("Redirected URL: " + conn.getURL()); redirectedUrl = conn.getURL().toString(); is.close(); } catch (MalformedURLException e) { Log.d(TAG, "Please input a valid URL"); } catch (IOException ioe) { Log.d(TAG, "Can not connect to the URL"); } return redirectedUrl; }
try (InputStream inputStream = conn.getURL().openStream()) { List<TokenData> siteTokensData = parseTokensData(inputStream); for (TokenData siteData : siteTokensData) {
/** * Convenience method to make it easier to verify connections * * @param connection The connection to match * @return true if this connection should be handled. */ protected boolean matches(URLConnection connection) { return matches(connection.getURL()); }
/** * @param eventType The event type to fire * @param connection the current connection */ protected void fireEvent(final String eventType, final URLConnection connection) { fireEvent(eventType, connection.getURL().toExternalForm(), null); }