List of usage examples for java.net HttpURLConnection setAllowUserInteraction
public void setAllowUserInteraction(boolean allowuserinteraction)
From source file:org.openbravo.test.datasource.DatasourceTestUtil.java
static HttpURLConnection createConnection(String url, String wsPart, String method, String cookie) throws Exception { String completeUrl = url + wsPart; log.debug("Create conntection URL: {}, method {}", completeUrl, method); final URL connUrl = new URL(completeUrl); final HttpURLConnection hc = (HttpURLConnection) connUrl.openConnection(); hc.setRequestMethod(method);// w ww .j av a 2 s. com hc.setAllowUserInteraction(false); hc.setDefaultUseCaches(false); hc.setDoOutput(true); hc.setDoInput(true); hc.setInstanceFollowRedirects(true); hc.setUseCaches(false); if (cookie != null) { hc.setRequestProperty("Cookie", cookie); } return hc; }
From source file:fr.ms.tomcat.manager.TomcatManagerUrl.java
public static String appelUrl(final URL url, final String username, final String password, final String charset) { try {//from w w w . j av a 2 s. com final URLConnection urlTomcatConnection = url.openConnection(); final HttpURLConnection connection = (HttpURLConnection) urlTomcatConnection; LOG.debug("url : " + url); connection.setAllowUserInteraction(false); connection.setDoInput(true); connection.setUseCaches(false); connection.setDoOutput(false); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", toAuthorization(username, password)); connection.connect(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { if (connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new TomcatManagerException("Reponse http : " + connection.getResponseMessage() + " - Les droits \"manager\" ne sont pas appliques - utilisateur : \"" + username + "\" password : \"" + password + "\""); } throw new TomcatManagerException("HttpURLConnection.HTTP_UNAUTHORIZED"); } final String response = toString(connection.getInputStream(), charset); LOG.debug("reponse : " + response); return response; } catch (final Exception e) { throw new TomcatManagerException("L'url du manager tomcat est peut etre incorrecte : \"" + url + "\"", e); } }
From source file:Main.java
public static String getHttpText(String urlInfo, String userName, String password) throws MalformedURLException, IOException { URL url = null;/*from w w w . j a v a 2s .c o m*/ String tempStr = null; url = new URL(urlInfo); HttpURLConnection huc = null; String credit = userName + ":" + password; String encoding = new sun.misc.BASE64Encoder().encode(credit.getBytes()); StringBuffer sb = new StringBuffer(); huc = (HttpURLConnection) url.openConnection(); huc.setAllowUserInteraction(false); huc.setRequestProperty("Authorization", "Basic " + encoding); BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream(), "utf-8")); String line = null; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } tempStr = sb.toString(); return tempStr; }
From source file:connector.ISConnector.java
public static JSONObject processRequest(String servlet, byte[] query) { JSONObject response = null;//from w w w . j ava 2 s .c o m if (servlet != null && !servlet.startsWith("/")) servlet = "/" + servlet; try { // Establish HTTP connection with Identity Service URL url = new URL(CONTEXT_PATH + servlet); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); //Create the form content try (OutputStream out = conn.getOutputStream()) { out.write(query); out.close(); } // Buffer the result into a string BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); conn.disconnect(); response = (JSONObject) new JSONParser().parse(sb.toString()); } catch (Exception e) { e.printStackTrace(); } return response; }
From source file:com.blogspot.ryanfx.auth.GoogleUtil.java
/** * Sends the auth token to google and gets the json result. * @param token auth token// ww w.j ava 2 s. c o m * @return json result if valid request, null if invalid. * @throws IOException * @throws LoginException */ private static String issueTokenGetRequest(String token) throws IOException, LoginException { int timeout = 2000; URL u = new URL("https://www.googleapis.com/oauth2/v2/userinfo"); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); c.setRequestProperty("Content-length", "0"); c.setRequestProperty("Authorization", "OAuth " + token); c.setUseCaches(false); c.setAllowUserInteraction(false); c.setConnectTimeout(timeout); c.setReadTimeout(timeout); c.connect(); int status = c.getResponseCode(); if (status == HttpServletResponse.SC_OK) { BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line + "\n"); } br.close(); return sb.toString(); } else if (status == HttpServletResponse.SC_UNAUTHORIZED) { Logger.getLogger(GoogleUtil.class.getName()).severe("Invalid token request: " + token); } return null; }
From source file:mashberry.com500px.util.Api_Parser.java
/******************************************************************************* * /* ww w. jav a2s .c om*/ * ( ) * *******************************************************************************/ public static String get_first_detail(final String url_feature, final int url_image_size, final String url_category, final int url_page, int image_no) { String returnStr = "success"; String urlStr = DB.Get_Photo_Url + "?feature=" + url_feature + "&image_size=" + url_image_size + "&only=" + getCategoryName(url_category) + "&page=" + url_page + "&consumer_key=" + Var.consumer_key + "&rpp=" + image_no; try { URL url = new URL(urlStr); URLConnection uc = url.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) uc; httpConn.setAllowUserInteraction(false); httpConn.setInstanceFollowRedirects(true); httpConn.setConnectTimeout(10000); httpConn.setRequestMethod("GET"); httpConn.connect(); int response = httpConn.getResponseCode(); Main.progressBar_process(50); if (response == HttpURLConnection.HTTP_OK) { InputStream in = httpConn.getInputStream(); String smallImageOpt = "3"; // (8 1/8 ) String largeImageOpt = "0"; String userPictureOpt = "8"; String result = convertStreamToString(in); JSONObject jObject = new JSONObject(result); JSONArray jsonArray = jObject.getJSONArray("photos"); Main.progressBar_process(75); if (jsonArray.length() == 0) { returnStr = "no results"; } else { for (int i = 0; i < jsonArray.length(); i++) { Var.categoryArr.add(jsonArray.getJSONObject(i).getString("category")); Var.idArr.add(jsonArray.getJSONObject(i).getString("id")); String smallImage = jsonArray.getJSONObject(i).getString("image_url"); String largeImage = largeImageOpt + smallImage.substring(0, smallImage.lastIndexOf(".jpg") - 1) + "4.jpg"; Var.imageSmall_urlArr.add(smallImageOpt + smallImage); Var.imageLarge_urlArr.add(largeImage); Var.nameArr.add(jsonArray.getJSONObject(i).getString("name")); Var.ratingArr.add(jsonArray.getJSONObject(i).getString("rating")); JSONObject jsonuser = jsonArray.getJSONObject(i).getJSONObject("user"); Var.user_firstnameArr.add(jsonuser.getString("firstname")); Var.user_fullnameArr.add(jsonuser.getString("fullname")); Var.user_lastnameArr.add(jsonuser.getString("lastname")); Var.user_upgrade_statusArr.add(jsonuser.getString("upgrade_status")); Var.user_usernameArr.add(jsonuser.getString("username")); Var.user_userpic_urlArr.add(userPictureOpt + jsonuser.getString("userpic_url")); Main.progressBar_process(75 + (15 * i / jsonArray.length())); } } // Log.i("Main", "urlStr " +urlStr); // Log.i("Main", "url_feature " +url_feature); // Log.i("Main", "categoryArr " +Var.categoryArr); // Log.i("Main", "idArr " +Var.idArr); // Log.i("Main", "imageLarge_urlArr " +Var.imageLarge_urlArr); // Log.i("Main", "nameArr " +Var.nameArr); // Log.i("Main", "ratingArr " +Var.ratingArr); // Log.i("Main", "user_firstnameArr " +Var.user_firstnameArr); // Log.i("Main", "user_fullnameArr " +Var.user_fullnameArr); // Log.i("Main", "user_lastnameArr " +Var.user_lastnameArr); // Log.i("Main", "user_upgrade_statusArr " +Var.user_upgrade_statusArr); // Log.i("Main", "user_usernameArr " +Var.user_usernameArr); // Log.i("Main", "user_userpic_urlArr " +Var.user_userpic_urlArr); } else { returnStr = "not response"; return returnStr; } } catch (Exception e) { e.printStackTrace(); returnStr = "not response"; return returnStr; } return returnStr; }
From source file:mashberry.com500px.util.Api_Parser.java
/******************************************************************************* * //from w ww. j ava2 s .c o m * ( ) * *******************************************************************************/ public static String get_second_detail(final int position, final String string, final int url_image_size, final int comments, final int comments_page) { String returnStr = "success"; String urlStr = DB.Get_Photo_Url + "/" + string + "?image_size=" + url_image_size /*+ "&comments=" + comments + "&comments_page=" + comments_page*/ + "&consumer_key=" + Var.consumer_key; try { URL url = new URL(urlStr); URLConnection uc = url.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) uc; httpConn.setAllowUserInteraction(false); httpConn.setInstanceFollowRedirects(true); httpConn.setRequestMethod("GET"); httpConn.connect(); httpConn.setConnectTimeout(10000); int response = httpConn.getResponseCode(); if (response == HttpURLConnection.HTTP_OK) { InputStream in = httpConn.getInputStream(); String userPictureOpt = "8"; String result = convertStreamToString(in); JSONObject jObject = new JSONObject(result); JSONObject jsonObject = jObject.getJSONObject("photo"); // Log.i(TAG, "jsonObject " + jsonObject); Var.detail_nameMap.put(position, jsonObject.getString("name")); Var.detail_locationMap.put(position, jsonObject.getString("location")); Var.detail_ratingMap.put(position, jsonObject.getString("rating")); Var.detail_times_viewedMap.put(position, jsonObject.getString("times_viewed")); Var.detail_votesMap.put(position, jsonObject.getString("votes_count")); Var.detail_favoritesMap.put(position, jsonObject.getString("favorites_count")); Var.detail_descriptionMap.put(position, jsonObject.getString("description")); Var.detail_cameraMap.put(position, jsonObject.getString("camera")); Var.detail_lensMap.put(position, jsonObject.getString("lens")); Var.detail_focal_lengthMap.put(position, jsonObject.getString("focal_length")); Var.detail_isoMap.put(position, jsonObject.getString("iso")); Var.detail_shutter_speedMap.put(position, jsonObject.getString("shutter_speed")); Var.detail_apertureMap.put(position, jsonObject.getString("aperture")); Var.detail_categoryMap.put(position, jsonObject.getString("category")); Var.detail_uploadedMap.put(position, jsonObject.getString("hi_res_uploaded")); Var.detail_takenMap.put(position, jsonObject.getString("taken_at")); Var.detail_licenseTypeMap.put(position, jsonObject.getString("license_type")); JSONObject jsonuser = jsonObject.getJSONObject("user"); Var.detail_user_nameMap.put(position, jsonuser.getString("fullname")); Var.detail_userpicMap.put(position, userPictureOpt + jsonuser.getString("userpic_url")); // ( . .) /*JSONArray jsonArray = jObject.getJSONArray("comments"); for(int i=0 ; i<jsonArray.length() ; i++){ Var.comment_user_id.add(jsonArray.getJSONObject(i).getString("user_id")); Var.comment_body.add(jsonArray.getJSONObject(i).getString("body")); JSONObject jsonuser = jsonArray.getJSONObject(i).getJSONObject("user"); Var.comment_fullname.add(jsonuser.getString("fullname")); Var.comment_userpic_url.add(jsonuser.getString("userpic_url")); }*/ /* Log.i("Main", "feature " +feature); Log.i("Main", "filters " +filters); Log.i("Main", "categoryArr " +Var.categoryArr); Log.i("Main", "idArr " +Var.idArr); Log.i("Main", "image_urlArr " +Var.image_urlArr); Log.i("Main", "nameArr " +Var.nameArr); Log.i("Main", "ratingArr " +Var.ratingArr); Log.i("Main", "user_firstnameArr " +Var.user_firstnameArr); Log.i("Main", "user_fullnameArr " +Var.user_fullnameArr); Log.i("Main", "user_lastnameArr " +Var.user_lastnameArr); Log.i("Main", "user_upgrade_statusArr " +Var.user_upgrade_statusArr); Log.i("Main", "user_usernameArr " +Var.user_usernameArr); Log.i("Main", "user_userpic_urlArr " +Var.user_userpic_urlArr);*/ } else { returnStr = "not response"; return returnStr; } } catch (Exception e) { e.printStackTrace(); returnStr = "not response"; return returnStr; } return returnStr; }
From source file:org.overlord.rtgov.tests.platforms.jbossas.servicedependency.JBossASServiceDependencyServiceTest.java
public static String getServiceOverview() throws Exception { URL getUrl = new URL("http://localhost:8080/overlord-rtgov/service/dependency/overview"); HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true);/*from w w w. j a va 2s . c o m*/ connection.setDoInput(true); connection.setUseCaches(false); connection.setAllowUserInteraction(false); connection.setRequestProperty("Content-Type", "application/json"); initAuth(connection); java.io.InputStream is = connection.getInputStream(); byte[] b = new byte[is.available()]; is.read(b); String result = new String(b); is.close(); return (result); }
From source file:com.adr.raspberryleds.HTTPUtils.java
public static JSONObject execPOST(String address, JSONObject params) throws IOException { BufferedReader readerin = null; Writer writerout = null;/* w w w .jav a 2 s . c o m*/ try { URL url = new URL(address); String query = params.toString(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setReadTimeout(10000 /* milliseconds */); connection.setConnectTimeout(15000 /* milliseconds */); connection.setRequestMethod("POST"); connection.setAllowUserInteraction(false); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); connection.addRequestProperty("Content-Type", "application/json,encoding=UTF-8"); connection.addRequestProperty("Content-length", String.valueOf(query.length())); writerout = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); writerout.write(query); writerout.flush(); writerout.close(); writerout = null; int responsecode = connection.getResponseCode(); if (responsecode == HttpURLConnection.HTTP_OK) { StringBuilder text = new StringBuilder(); readerin = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); String line = null; while ((line = readerin.readLine()) != null) { text.append(line); text.append(System.getProperty("line.separator")); } JSONObject result = new JSONObject(text.toString()); if (result.has("exception")) { throw new IOException( MessageFormat.format("Remote exception: {0}.", result.getString("exception"))); } else { return result; } } else { throw new IOException(MessageFormat.format("HTTP response error: {0}. {1}", Integer.toString(responsecode), connection.getResponseMessage())); } } catch (JSONException ex) { throw new IOException(MessageFormat.format("Parse exception: {0}.", ex.getMessage())); } finally { if (writerout != null) { writerout.close(); writerout = null; } if (readerin != null) { readerin.close(); readerin = null; } } }
From source file:core.RESTCalls.RESTPost.java
public static String httpPost(String urlStr, String[] paramName, String[] paramVal) throws Exception { URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true);//w w w . j a va 2 s . c o m conn.setDoInput(true); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream out = conn.getOutputStream(); Writer writer = new OutputStreamWriter(out, "UTF-8"); for (int i = 0; i < paramName.length; i++) { writer.write(paramName[i]); writer.write("="); writer.write(URLEncoder.encode(paramVal[i], "UTF-8")); writer.write("&"); } writer.close(); out.close(); if (conn.getResponseCode() != 200) throw new IOException(conn.getResponseMessage()); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) sb.append(line + "\n"); rd.close(); conn.disconnect(); return sb.toString(); }