List of usage examples for javax.net.ssl HttpsURLConnection getResponseCode
public int getResponseCode() throws IOException
From source file:com.cloudbees.tftwoway.Client.java
public static void main(String[] args) throws Exception { URL url = new URL(SERVER_ADDRESS); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); SSLContext sslContext = createSSLContext(); connection.setSSLSocketFactory(sslContext.getSocketFactory()); connection.connect();// w ww .j a v a2s . co m int responseCode = connection.getResponseCode(); String response = IOUtils.toString(connection.getInputStream(), connection.getContentEncoding()); System.out.println(responseCode); System.out.println(response); }
From source file:org.liberty.android.fantastischmemo.downloader.google.WorksheetFactory.java
public static List<Worksheet> getWorksheets(Spreadsheet spreadsheet, String authToken) throws XmlPullParserException, IOException { String worksheetAddress = "https://spreadsheets.google.com/feeds/worksheets/" + spreadsheet.getId() + "/private/full?access_token=" + authToken; URL url = new URL(worksheetAddress); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); if (conn.getResponseCode() / 100 >= 3) { String s = new String(IOUtils.toByteArray(conn.getErrorStream())); throw new RuntimeException(s); }// w w w . j a va2 s. c o m List<Worksheet> worksheetList = EntryFactory.getEntries(Worksheet.class, conn.getInputStream()); return worksheetList; }
From source file:org.liberty.android.fantastischmemo.downloader.google.SpreadsheetFactory.java
public static List<Spreadsheet> getSpreadsheets(String authToken) throws XmlPullParserException, IOException { URL url = new URL( "https://spreadsheets.google.com/feeds/spreadsheets/private/full?access_token=" + authToken); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); //conn.addRequestProperty("Authorization", "GoogleLogin auth=" + authToken); if (conn.getResponseCode() / 100 >= 3) { String s = new String(IOUtils.toByteArray(conn.getErrorStream())); throw new IOException(s); }// w w w. j ava 2 s. co m List<Spreadsheet> spreadsheetList = EntryFactory.getEntries(Spreadsheet.class, conn.getInputStream()); return spreadsheetList; }
From source file:org.liberty.android.fantastischmemo.downloader.google.DocumentFactory.java
public static List<Document> findDocuments(String title, String authToken) throws Exception { URL url = new URL("https://www.googleapis.com/drive/v2/files?q=" + URLEncoder.encode("title = '" + title + "'", "UTF-8")); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Bearer " + authToken); if (conn.getResponseCode() >= 300) { String s = new String(IOUtils.toByteArray(conn.getErrorStream())); throw new RuntimeException(s); }//w w w .j a va 2 s . com List<Document> documentList = EntryFactory.getEntriesFromDriveApi(Document.class, conn.getInputStream()); return documentList; }
From source file:org.liberty.android.fantastischmemo.downloader.google.CellsFactory.java
public static Cells getCells(Spreadsheet spreadsheet, Worksheet worksheet, String authToken) throws XmlPullParserException, IOException { URL url = new URL("https://spreadsheets.google.com/feeds/cells/" + spreadsheet.getId() + "/" + worksheet.getId() + "/private/full?access_token=" + authToken); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); if (conn.getResponseCode() / 100 >= 3) { String s = new String(IOUtils.toByteArray(conn.getErrorStream())); throw new RuntimeException(s); }//from w w w . ja v a2 s .c o m XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(new BufferedReader(new InputStreamReader(conn.getInputStream()))); int eventType = xpp.getEventType(); List<Row> rowList = new ArrayList<Row>(100); Row row = null; String lastTag = ""; int currentRow = 1; int currentCol = 1; Cells cells = new Cells(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_DOCUMENT) { } else if (eventType == XmlPullParser.START_TAG) { lastTag = xpp.getName(); if (xpp.getName().equals("cell")) { currentRow = Integer.valueOf(xpp.getAttributeValue(null, "row")); currentCol = Integer.valueOf(xpp.getAttributeValue(null, "col")); } } else if (eventType == XmlPullParser.END_TAG) { if (xpp.getName().equals("entry")) { rowList.add(row); row = null; } } else if (eventType == XmlPullParser.TEXT) { if (lastTag.equals("cell")) { cells.addCell(currentRow, currentCol, xpp.getText()); } if (lastTag.equals("title") && Strings.isNullOrEmpty(cells.getWorksheetName())) { cells.setWorksheetName(xpp.getText()); } } eventType = xpp.next(); } return cells; }
From source file:org.liberty.android.fantastischmemo.downloader.google.FolderFactory.java
public static List<Folder> getFolders(String authToken) throws XmlPullParserException, IOException { URL url = new URL("https://www.googleapis.com/drive/v2/files?q=" + URLEncoder.encode("mimeType = 'application/vnd.google-apps.folder'", "UTF-8")); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Bearer " + authToken); if (conn.getResponseCode() / 100 >= 3) { String s = new String(IOUtils.toByteArray(conn.getErrorStream())); throw new IOException(s); }// w ww .j av a2 s. c o m List<Folder> folderList = EntryFactory.getEntriesFromDriveApi(Folder.class, conn.getInputStream()); return folderList; }
From source file:org.liberty.android.fantastischmemo.downloader.google.DocumentFactory.java
public static void deleteDocument(Document document, String authToken) throws IOException { URL url = new URL("https://www.googleapis.com/drive/v2/files/" + document.getId()); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Bearer " + authToken); conn.setRequestMethod("DELETE"); if (conn.getResponseCode() / 100 >= 3) { String s = new String(IOUtils.toByteArray(conn.getErrorStream())); throw new RuntimeException(s); }//from w ww . jav a2s.c o m }
From source file:org.liberty.android.fantastischmemo.downloader.google.WorksheetFactory.java
public static void deleteWorksheet(Spreadsheet spreadsheet, Worksheet worksheet, String authToken) throws Exception { String requestUrl = "https://spreadsheets.google.com/feeds/worksheets/" + spreadsheet.getId() + "/private/full/" + worksheet.getId() + "/0" + "?access_token=" + authToken; URL url = new URL(requestUrl); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestMethod("DELETE"); conn.addRequestProperty("If-Match", "*"); if (conn.getResponseCode() / 100 >= 3) { String s = new String(IOUtils.toByteArray(conn.getErrorStream())); throw new Exception(s); }// w w w . ja va 2s .com }
From source file:com.clearcenter.mobile_demo.mdRest.java
static private StringBuffer ProcessRequest(HttpsURLConnection http) throws IOException { http.connect();//from ww w . j ava 2 s . c om Log.d(TAG, "Result code: " + http.getResponseCode() + ", content type: " + http.getContentType() + ", content length: " + http.getContentLength()); // Read response, 8K buffer BufferedReader buffer = new BufferedReader(new InputStreamReader(http.getInputStream()), 8192); String data; StringBuffer response = new StringBuffer(); while ((data = buffer.readLine()) != null) response.append(data); Log.d(TAG, "Response buffer length: " + response.length()); buffer.close(); http.disconnect(); return response; }
From source file:com.msopentech.thali.utilities.universal.test.ThaliTestUrlConnection.java
public static void TestThaliUrlConnection(String host, char[] passPhrase, CreateClientBuilder createClientBuilder, Context context) throws InterruptedException, UnrecoverableEntryException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException { ThaliTestUtilities.configuringLoggingApacheClient(); ThaliListener thaliTestServer = new ThaliListener(); File keyStore = ThaliCryptoUtilities.getThaliKeyStoreFileObject(context.getFilesDir()); // We want to start with a clean state if (keyStore.exists()) { keyStore.delete();// w ww. j av a2s . co m } // We use a random port (e.g. port 0) both because it's good hygiene and because it keeps us from conflicting // with the 'real' Thali Device Hub if it's running. thaliTestServer.startServer(context, 0); int port = thaliTestServer.getSocketStatus().getPort(); CouchDbInstance couchDbInstance = ThaliClientToDeviceHubUtilities .GetLocalCouchDbInstance(context.getFilesDir(), createClientBuilder, host, port, passPhrase); couchDbInstance.deleteDatabase(ThaliTestUtilities.TestDatabaseName); couchDbInstance.createDatabase(ThaliTestUtilities.TestDatabaseName); KeyStore clientKeyStore = ThaliCryptoUtilities.validateThaliKeyStore(context.getFilesDir()); org.apache.http.client.HttpClient httpClientNoServerValidation = createClientBuilder .CreateApacheClient(host, port, null, clientKeyStore, passPhrase); PublicKey serverPublicKey = ThaliClientToDeviceHubUtilities .getServersRootPublicKey(httpClientNoServerValidation); String httpsURL = "https://" + host + ":" + port + "/" + ThaliTestUtilities.TestDatabaseName + "/"; HttpsURLConnection httpsURLConnection = ThaliUrlConnection.getThaliUrlConnection(httpsURL, serverPublicKey, clientKeyStore, passPhrase); httpsURLConnection.setRequestMethod("GET"); int responseCode = httpsURLConnection.getResponseCode(); if (responseCode != 200) { throw new RuntimeException(); } }