List of usage examples for org.apache.commons.httpclient.protocol Protocol getProtocol
public static Protocol getProtocol(String paramString) throws IllegalStateException
From source file:GetMethodExample.java
public static void main(String args[]) { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "Test Client"); client.getParams().setParameter("http.connection.timeout", new Integer(5000)); GetMethod method = new GetMethod(); FileOutputStream fos = null;//w w w .java2 s. co m try { method.setURI(new URI("http://www.google.com", true)); int returnCode = client.executeMethod(method); if (returnCode != HttpStatus.SC_OK) { System.err.println("Unable to fetch default page, status code: " + returnCode); } System.err.println(method.getResponseBodyAsString()); method.setURI(new URI("http://www.google.com/images/logo.gif", true)); returnCode = client.executeMethod(method); if (returnCode != HttpStatus.SC_OK) { System.err.println("Unable to fetch image, status code: " + returnCode); } byte[] imageData = method.getResponseBody(); fos = new FileOutputStream(new File("google.gif")); fos.write(imageData); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost("www.yahoo.com", null, 80, Protocol.getProtocol("http")); method.setURI(new URI("/", true)); client.executeMethod(hostConfig, method); System.err.println(method.getResponseBodyAsString()); } catch (HttpException he) { System.err.println(he); } catch (IOException ie) { System.err.println(ie); } finally { method.releaseConnection(); if (fos != null) try { fos.close(); } catch (Exception fe) { } } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.support.UntrustedSSLProtocolSocketFactory.java
private static boolean isRegistered() { Protocol https = Protocol.getProtocol("https"); boolean isRegistered = https.getSocketFactory() instanceof UntrustedSSLProtocolSocketFactory; if (!isRegistered) { defaultSSL = https;/*from www.j a va 2 s. c o m*/ } return isRegistered; }
From source file:com.owncloud.android.oc_framework.network.NetworkUtils.java
/** * Registers or unregisters the proper components for advanced SSL handling. * @throws IOException //from w w w . jav a 2s. c o m */ public static void registerAdvancedSslContext(boolean register, Context context) throws GeneralSecurityException, IOException { Protocol pr = null; try { pr = Protocol.getProtocol("https"); if (pr != null && mDefaultHttpsProtocol == null) { mDefaultHttpsProtocol = pr; } } catch (IllegalStateException e) { // nothing to do here; really } boolean isRegistered = (pr != null && pr.getSocketFactory() instanceof AdvancedSslSocketFactory); if (register && !isRegistered) { Protocol.registerProtocol("https", new Protocol("https", getAdvancedSslSocketFactory(context), 443)); } else if (!register && isRegistered) { if (mDefaultHttpsProtocol != null) { Protocol.registerProtocol("https", mDefaultHttpsProtocol); } } }
From source file:com.owncloud.android.lib.test_project.test.SingleSessionManagerTest.java
public SingleSessionManagerTest() { super();// www .j a v a2 s .c o m Protocol pr = Protocol.getProtocol("https"); if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { try { ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); Protocol.registerProtocol("https", new Protocol("https", psf, 443)); } catch (GeneralSecurityException e) { throw new AssertionFailedError("Self-signed confident SSL context could not be loaded"); } } }
From source file:com.owncloud.android.lib.test_project.test.SimpleFactoryManagerTest.java
public SimpleFactoryManagerTest() { super();/*from ww w .ja v a 2 s . c om*/ Protocol pr = Protocol.getProtocol("https"); if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { try { ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); Protocol.registerProtocol("https", new Protocol("https", psf, 443)); } catch (GeneralSecurityException e) { throw new AssertionFailedError("Self-signed confident SSL context could not be loaded"); } } }
From source file:com.cerema.cloud2.lib.common.network.NetworkUtils.java
/** * Registers or unregisters the proper components for advanced SSL handling. * @throws IOException // w w w. j a v a 2 s . c o m */ @SuppressWarnings("deprecation") public static void registerAdvancedSslContext(boolean register, Context context) throws GeneralSecurityException, IOException { Protocol pr = null; try { pr = Protocol.getProtocol("https"); if (pr != null && mDefaultHttpsProtocol == null) { mDefaultHttpsProtocol = pr; } } catch (IllegalStateException e) { // nothing to do here; really } boolean isRegistered = (pr != null && pr.getSocketFactory() instanceof AdvancedSslSocketFactory); if (register && !isRegistered) { Protocol.registerProtocol("https", new Protocol("https", getAdvancedSslSocketFactory(context), 443)); } else if (!register && isRegistered) { if (mDefaultHttpsProtocol != null) { Protocol.registerProtocol("https", mDefaultHttpsProtocol); } } }
From source file:com.owncloud.android.lib.test_project.test.GetCapabilitiesTest.java
public GetCapabilitiesTest() { super();/* w w w . j a v a 2s . c o m*/ Protocol pr = Protocol.getProtocol("https"); if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { try { ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); Protocol.registerProtocol("https", new Protocol("https", psf, 443)); } catch (GeneralSecurityException e) { throw new AssertionFailedError("Self-signed confident SSL context could not be loaded"); } } }
From source file:com.fatwire.dta.sscrawler.domain.HostConfig.java
/** * @param protocol the protocol to set//w w w . jav a 2s . c o m */ @SuppressWarnings("deprecation") public void setProtocol(String protocol) { if (protocol.equalsIgnoreCase("https")) { this.protocol = new Protocol("https", new EasySSLProtocolSocketFactory(), 443); } else { this.protocol = Protocol.getProtocol(protocol); } }
From source file:au.edu.monash.merc.capture.util.httpclient.ssl.HostConfigurationWithHostFactory.java
public void setHost(String host) { setHost(host, Protocol.getProtocol(DEFAULT_SCHEME).getDefaultPort()); }
From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java
public OwnCloudClientTest() { super();/* www . j a v a2 s. co m*/ Protocol pr = Protocol.getProtocol("https"); if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { try { ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); Protocol.registerProtocol("https", new Protocol("https", psf, 443)); } catch (GeneralSecurityException e) { throw new AssertionFailedError("Self-signed confident SSL context could not be loaded"); } } }