public synchronized OutputStream getOutputStream() throws IOException { OutputStream os; String savedMethod = method; // see if the method supports output if (method.equals("PUT") || method.equals("POST") || method.equals("NOTIFY")) { // fake the method so the superclass method sets its instance variables method = "PUT"; } else { // use any method that doesn't support output, an exception will be // raised by the superclass method = "GET"; } os = super.getOutputStream(); method = savedMethod; return os; }
@Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { HttpURLConnection connection = (HttpURLConnection) super.openConnection(url, proxy); connection.setRequestMethod(this.httpMethod); if (resourceDetails.isAcceptsAuthorizationHeader()) { String authHeader = support.getAuthorizationHeader(resourceDetails, accessToken, url, httpMethod, additionalParameters); connection.setRequestProperty("Authorization", authHeader); } return connection; }
AuthenticationUtil.pathKerberosLogin = prefs.get("kerberosLoginConf", ""); AuthCacheValue.setAuthCache(new AuthCacheImpl());
public class URLStreamHandlerFactory implements java.net.URLStreamHandlerFactory { public URLStreamHandlerFactory() {} public URLStreamHandler createURLStreamHandler(String protocol) { if(protocol.equals("http")) { return new sun.net.www.protocol.http.Handler(); } else if(protocol.equals("https")) { return new sun.net.www.protocol.https.Handler(); } return null; } }
URLStreamHandler handler = new sun.net.www.protocol.http.Handler(); //standard http handler URL url = null; try { url = new URL(null, wsdlUrl, handler); //forced this http handler here ws = ServiceUtilityWS.create(url, qName); } catch (MalformedURLException e) { }
Exception in thread "main" java.io.FileNotFoundException: http://dl.dropbox.com/u/34206572/version.txt at sun.net.www.protocol.http.HttpURLConnection.getInputStream( HttpURLConnection.java:1610)
sun.net.www.protocol.http.HttpURLConnection.doTunneling()
protected InputStream getResponseStream(URLConnection pURLConnection) throws IOException { sun.net.www.protocol.http.HttpURLConnection conn1 = null; if (pURLConnection instanceof sun.net.www.protocol.http.HttpURLConnection) { conn1 = (sun.net.www.protocol.http.HttpURLConnection) pURLConnection; } if (mResponseCode == HttpURLConnection.HTTP_BAD_METHOD || mResponseCode == HttpURLConnection.HTTP_BAD_REQUEST || mResponseCode == HttpURLConnection.HTTP_NOT_FOUND || mResponseCode == HttpURLConnection.HTTP_BAD_GATEWAY || mResponseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) { if (null != conn1) { return conn1.getErrorStream(); } else { return pURLConnection.getInputStream(); } } else { return pURLConnection.getInputStream(); } }
try { InputStream in = new URL(myUrl).openConnection().getInputStream(); } catch (IllegalArgumentException iae) { in = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(new URL(myUrl).openConnection()); }
AuthCacheValue.setAuthCache(new AuthCacheImpl());
private URLConnection defaultConnection(URL url) throws IOException { return super.openConnection(url); } }
new URL(null, "http://...", new sun.net.www.protocol.http.Handler());
public synchronized OutputStream getOutputStream() throws IOException { OutputStream os; String savedMethod = method; // see if the method supports output if (method.equals("PUT") || method.equals("POST") || method.equals("NOTIFY")) { // fake the method so the superclass method sets its instance variables method = "PUT"; } else { // use any method that doesn't support output, an exception will be // raised by the superclass method = "GET"; } os = super.getOutputStream(); method = savedMethod; return os; }
/** * Sets this class as the default authenticator in the current JVM */ @SuppressWarnings({ "restriction", "unused" }) public static void setAsDefault() { Authenticator.setDefault(singleton); try { // this block is written for suppressing a bug in sun implementation // In Sun Impl client doesn't authenticate user for each connection // , uses cached credentials instead Class<?> cacheValClass = Class .forName("sun.net.www.protocol.http.AuthCacheValue"); sun.net.www.protocol.http.AuthCacheValue .setAuthCache(new sun.net.www.protocol.http.AuthCacheImpl()); } catch (Exception e) { } }
@Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { HttpURLConnection connection = (HttpURLConnection) super.openConnection(url, proxy); connection.setRequestMethod(this.httpMethod); if (resourceDetails.isAcceptsAuthorizationHeader()) { String authHeader = support.getAuthorizationHeader(resourceDetails, accessToken, url, httpMethod, additionalParameters); connection.setRequestProperty("Authorization", authHeader); } return connection; }
final URL url = new URL(null, urlString, new sun.net.www.protocol.http.Handler());
URL url = new URL(null, urlstr, new sun.net.www.protocol.http.Handler());
sun.net.www.protocol.http.Handler handler = new sun.net.www.protocol.http.Handler(); URL url = new URL(null, "http://" + host + ":" + port + "/", handler);
URL url = new URL(null, "http://...", new sun.net.www.protocol.http.Handler()); HttpURLConnection cxn = (HttpURLConnection) url.openConnection();
url = new URL(null, address, new sun.net.www.protocol.http.Handler()); // use Sun's handler