List of usage examples for java.net HttpURLConnection HTTP_VERSION
int HTTP_VERSION
To view the source code for java.net HttpURLConnection HTTP_VERSION.
Click Source Link
From source file:eionet.cr.util.URLUtil.java
/** * Connect to the URL and check if it exists at the remote end. Local identifiers are removed (the part after the '#') before * connecting. The method returns true (i.e. URL is considered as "not existing") if the given URL is malformed, or its * connection throws a {@link UnknownHostException} or sends a HTTP code that is 501 or 505 or anything in the range of 400 * to 499. The latter range, however, is ignored if the given boolean input is is true (meaning a client error is OK). * * @param urlStr the URL to check.//from www. java2s .c o m * @param clientErrorOk If true, then a response code in the range of 400 to 499 is considered OK. * @return As described above. */ public static boolean isNotExisting(String urlStr, boolean clientErrorOk) { int responseCode = -1; IOException ioe = null; URLConnection urlConnection = null; try { URL url = new URL(StringUtils.substringBefore(urlStr, "#")); urlConnection = escapeIRI(url).openConnection(); urlConnection.setRequestProperty("Connection", "close"); responseCode = ((HttpURLConnection) urlConnection).getResponseCode(); } catch (IOException e) { ioe = e; } finally { URLUtil.disconnect(urlConnection); } return ioe instanceof MalformedURLException || ioe instanceof UnknownHostException || (!clientErrorOk && isClientError(responseCode)) || responseCode == HttpURLConnection.HTTP_NOT_IMPLEMENTED || responseCode == HttpURLConnection.HTTP_VERSION; }
From source file:org.hyperic.hq.plugin.netservices.HTTPCollector.java
private double getAvail(int code) { // There are too many options to list everything that is // successful. So, instead we are going to call out the // things that should be considered failure, everything else // is OK.//from w w w . j a v a2 s . com switch (code) { case HttpURLConnection.HTTP_BAD_REQUEST: case HttpURLConnection.HTTP_FORBIDDEN: case HttpURLConnection.HTTP_NOT_FOUND: case HttpURLConnection.HTTP_BAD_METHOD: case HttpURLConnection.HTTP_CLIENT_TIMEOUT: case HttpURLConnection.HTTP_CONFLICT: case HttpURLConnection.HTTP_PRECON_FAILED: case HttpURLConnection.HTTP_ENTITY_TOO_LARGE: case HttpURLConnection.HTTP_REQ_TOO_LONG: case HttpURLConnection.HTTP_INTERNAL_ERROR: case HttpURLConnection.HTTP_NOT_IMPLEMENTED: case HttpURLConnection.HTTP_UNAVAILABLE: case HttpURLConnection.HTTP_VERSION: case HttpURLConnection.HTTP_BAD_GATEWAY: case HttpURLConnection.HTTP_GATEWAY_TIMEOUT: return Metric.AVAIL_DOWN; default: } if (hasCredentials()) { if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { return Metric.AVAIL_DOWN; } } return Metric.AVAIL_UP; }