Das HttpFacadeProtocol bietet erweiterte Möglichkeiten der Steuerung der Java HttpURLConnection.

Anwendung#

Das Protokoll wird mit der ProtocolFactory installiert. Beim Öffnen einer Connection wird eine HttpUrlConnectionFacade zurückgegeben (vorher HttpURLConnection).

Beispiel#

	Authenticator.setDefault(new Authenticator() {
		@Override
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication("<username>", "<password>".toCharArray());
		}
	});
	
	ProtocolFactory.register(new HttpFacadeProtocol());
	
	URL url = new URL("http://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat-jasper/7.0.27/tomcat-jasper-7.0.27.pom");
	HttpUrlConnectionFacade connection = (HttpUrlConnectionFacade)url.openConnection(new SomeProxy());
	connection.setTransparentNtlm(false);
	IOUtils.copy(connection.getInputStream(), System.out);

Erklärung: In dem Beispiel wird eine Connection über "SomeProxy" geöffnet. Die Authentication über NTML wird abgeschaltet (Methode setTransparentNtml), sodass Benutzername und Passwort abgefragt wird.