use of javax.net.ssl.HttpsURLConnection in project collect by opendatakit.
the class SNITest method urlConnectionSupportsSNI.
@Test
public void urlConnectionSupportsSNI() throws IOException {
HttpsURLConnection conn = (HttpsURLConnection) SNI_URI.toURL().openConnection();
assertHttpSuccess(conn.getResponseCode());
assertPageContent(conn.getInputStream());
}
use of javax.net.ssl.HttpsURLConnection in project java-google-speech-api by goxr3plus.
the class GSpeechDuplex method openHttpsPostConnection.
/**
* Opens a chunked HTTPS post connection and returns a Scanner with incoming data from Google Server Used for to get UPStream Chunked HTTPS
* ensures unlimited file size.
*
* @param urlStr
* The String for the URL
* @param data
* The data you want to send the server
* @param sampleRate
* The sample rate of the flac file.
* @return A Scanner to access the server response. (Probably will never be used)
*/
private Scanner openHttpsPostConnection(String urlStr, byte[][] data, int sampleRate) {
byte[][] mextrad = data;
int resCode = -1;
OutputStream out = null;
// int http_status;
try {
URL url = new URL(urlStr);
HttpsURLConnection httpConn = getHttpsURLConnection(sampleRate, url);
// this opens a connection, then sends POST & headers.
out = httpConn.getOutputStream();
// Note : if the audio is more than 15 seconds
// dont write it to UrlConnInputStream all in one block as this sample does.
// Rather, segment the byteArray and on intermittently, sleeping thread
// supply bytes to the urlConn Stream at a rate that approaches
// the bitrate ( =30K per sec. in this instance ).
System.out.println("Starting to write");
for (byte[] dataArray : mextrad) {
// one big block supplied instantly to the underlying chunker wont work for duration > 15 s.
out.write(dataArray);
try {
// Delays the Audio so Google thinks its a mic.
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
out.write(FINAL_CHUNK);
System.out.println("IO WRITE DONE");
// do you need the trailer?
// NOW you can look at the status.
resCode = httpConn.getResponseCode();
if (resCode / 100 != 2) {
System.out.println("ERROR");
}
if (resCode == HttpsURLConnection.HTTP_OK) {
return new Scanner(httpConn.getInputStream(), "UTF-8");
} else {
System.out.println("HELP: " + resCode);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of javax.net.ssl.HttpsURLConnection in project Gargoyle by callakrsos.
the class RequestUtil method requestSSL.
public static <T> T requestSSL(URL url, ResponseHandler<T> response, boolean autoClose) throws Exception {
// SSLContext ctx = SSLContext.getInstance("TLS");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
InputStream is = null;
T result = null;
try {
conn.setDefaultUseCaches(true);
conn.setUseCaches(true);
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0");
conn.setRequestProperty("Accept-Encoding", "UTF-8");
// conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Accept", "text/html");
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setRequestProperty("Accept-Encoding", "UTF-8");
conn.setRequestProperty("Accept-Language", "KR");
// conn.setRequestProperty("Cache-Control", "no-store");
// conn.setRequestProperty("Pragma", "no-cache");
conn.setHostnameVerifier(hostnameVerifier);
conn.setConnectTimeout(6000);
conn.connect();
is = conn.getInputStream();
String contentEncoding = conn.getContentEncoding();
LOGGER.debug("code : [{}] [{}] URL : {} , ", conn.getResponseCode(), contentEncoding, url.toString());
response.setContentEncoding(contentEncoding);
response.setResponseCode(conn.getResponseCode());
Map<String, List<String>> headerFields = conn.getHeaderFields();
response.setHeaderFields(headerFields);
result = response.apply(is, conn.getResponseCode());
} finally {
if (autoClose) {
if (is != null)
is.close();
if (conn != null)
conn.disconnect();
}
}
return result;
}
use of javax.net.ssl.HttpsURLConnection in project oxTrust by GluuFederation.
the class StatusCheckerTimer method setCertificateExpiryAttributes.
private void setCertificateExpiryAttributes(GluuAppliance appliance) {
try {
URL destinationURL = new URL(appConfiguration.getApplianceUrl());
HttpsURLConnection conn = (HttpsURLConnection) destinationURL.openConnection();
conn.connect();
Certificate[] certs = conn.getServerCertificates();
if (certs.length > 0) {
if (certs[0] instanceof X509Certificate) {
X509Certificate x509Certificate = (X509Certificate) certs[0];
Date expirationDate = x509Certificate.getNotAfter();
long expiresAfter = TimeUnit.MILLISECONDS.toDays(expirationDate.getTime() - new Date().getTime());
appliance.setSslExpiry(toIntString(expiresAfter));
}
}
} catch (IOException e) {
log.error("Can not download ssl certificate", e);
}
}
use of javax.net.ssl.HttpsURLConnection in project android_frameworks_base by crdroidandroid.
the class TestUtils method assertUrlConnectionFails.
public static void assertUrlConnectionFails(SSLContext context, String host, int port) throws Exception {
URL url = new URL("https://" + host + ":" + port);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(context.getSocketFactory());
try {
connection.getInputStream();
fail("Connection to " + host + ":" + port + " expected to fail");
} catch (SSLHandshakeException expected) {
// ignored.
}
}
Aggregations