Java Code Examples for javax.net.ssl.HttpsURLConnection#getURL()

The following examples show how to use javax.net.ssl.HttpsURLConnection#getURL() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpResponse.java    From jarling with MIT License 6 votes vote down vote up
public HttpResponse(HttpsURLConnection httpsURLConnection) throws StarlingBankRequestException {
    this.httpsURLConnection = httpsURLConnection;
    try {
        if (httpsURLConnection.getResponseCode() < HttpsURLConnection.HTTP_BAD_REQUEST){
            this.is = httpsURLConnection.getInputStream();
        }else {
            this.is = httpsURLConnection.getErrorStream();
            processStatusCode(httpsURLConnection);
        }
        this.statusCode = httpsURLConnection.getResponseCode();
        this.expiration = httpsURLConnection.getExpiration();
        this.request = httpsURLConnection.getURL();
        this.expiration = httpsURLConnection.getExpiration();
        this.lastModified = httpsURLConnection.getLastModified();
        this.responseHeaders = httpsURLConnection.getHeaderFields();
        this.contentType = httpsURLConnection.getContentType();
        this.contentEncoding = httpsURLConnection.getContentEncoding();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: AopHttpsURLConnection.java    From ArgusAPM with Apache License 2.0 4 votes vote down vote up
public AopHttpsURLConnection(HttpsURLConnection con) {
    super(con.getURL());
    myConnection = con;
}
 
Example 3
Source File: HttpsURLConnectionWrapper.java    From android-perftracking with MIT License 4 votes vote down vote up
public HttpsURLConnectionWrapper(HttpsURLConnection conn) {
  super(conn.getURL());
  _conn = conn;
}
 
Example 4
Source File: HttpDownloader.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Response execute(Request request) throws IOException, ReCaptchaException {
	final String httpMethod = request.httpMethod();
	final String url = request.url();
	final Map<String, List<String>> headers = request.headers();
	final Localization localization = request.localization();

	final HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();

	connection.setConnectTimeout(30 * 1000); // 30s
	connection.setReadTimeout(30 * 1000); // 30s
	connection.setRequestMethod(httpMethod);

	connection.setRequestProperty("User-Agent", USER_AGENT);
	connection.setRequestProperty("Accept-Language", "en");

	for (Map.Entry<String, List<String>> pair : headers.entrySet()) {
		final String headerName = pair.getKey();
		final List<String> headerValueList = pair.getValue();

		if (headerValueList.size() > 1) {
			connection.setRequestProperty(headerName, null);
			for (String headerValue : headerValueList) {
				connection.addRequestProperty(headerName, headerValue);
			}
		} else if (headerValueList.size() == 1) {
			connection.setRequestProperty(headerName, headerValueList.get(0));
		}
	}

	try(OutputStream outputStream = sendOutput(request, connection)) {

		final String response = readResponse(connection);

		final int responseCode = connection.getResponseCode();
		final String responseMessage = connection.getResponseMessage();
		final Map<String, List<String>> responseHeaders = connection.getHeaderFields();
		final URL latestUrl = connection.getURL();
		return new Response(responseCode, responseMessage, responseHeaders, response, latestUrl.toString());
	} catch (Exception e) {
		/*
		 * HTTP 429 == Too Many Request
		 * Receive from Youtube.com = ReCaptcha challenge request
		 * See : https://github.com/rg3/youtube-dl/issues/5138
		 */
		if (connection.getResponseCode() == 429) {
			throw new ReCaptchaException("reCaptcha Challenge requested", url);
		}

		throw new IOException(connection.getResponseCode() + " " + connection.getResponseMessage(), e);
	}
}
 
Example 5
Source File: ApigeeHttpsURLConnection.java    From apigee-android-sdk with Apache License 2.0 4 votes vote down vote up
public ApigeeHttpsURLConnection(HttpsURLConnection connection)
{
	super(connection.getURL());
	realConnection = connection;
}