当前位置: 首页>>代码示例>>Java>>正文


Java HttpRetryException类代码示例

本文整理汇总了Java中java.net.HttpRetryException的典型用法代码示例。如果您正苦于以下问题:Java HttpRetryException类的具体用法?Java HttpRetryException怎么用?Java HttpRetryException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpRetryException类属于java.net包,在下文中一共展示了HttpRetryException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRewind

import java.net.HttpRetryException; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testRewind() throws Exception {
    // Post preserving redirect should fail.
    URL url = new URL(NativeTestServer.getRedirectToEchoBody());
    HttpURLConnection connection =
            (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setFixedLengthStreamingMode(TestUtil.UPLOAD_DATA.length);
    try {
        OutputStream out = connection.getOutputStream();
        out.write(TestUtil.UPLOAD_DATA);
    } catch (HttpRetryException e) {
        assertEquals("Cannot retry streamed Http body", e.getMessage());
    }
    connection.disconnect();
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:20,代码来源:CronetFixedModeOutputStreamTest.java

示例2: sendResponseMessage

import java.net.HttpRetryException; //导入依赖的package包/类
@Override
void sendResponseMessage(HttpURLConnection connection) {
	InputStream response = null;
	byte[] responseBody = null;
	try {
		int statusCode = connection.getResponseCode();
		if(statusCode >= 300) {
			response = connection.getErrorStream();
			if(response != null) responseBody = Util.inputStreamToByteArray(response);
			sendFailMessage(new HttpRetryException(connection.getResponseMessage(), statusCode), 
					responseBody);		
		} else {
			response = connection.getInputStream();
			if(response != null) responseBody = Util.inputStreamToByteArray(response);
			sendSuccessMessage(statusCode, responseBody);
		}
	} catch(IOException e) {
		sendFailMessage(e, (byte[])null);
	} finally {
		if(response != null) Util.closeQuietly(response);
	}
}
 
开发者ID:leonardoxh,项目名称:AsyncOkHttpClient,代码行数:23,代码来源:ByteAsyncHttpResponse.java

示例3: sendResponseMessage

import java.net.HttpRetryException; //导入依赖的package包/类
/**
    * Perform the connection with the given client
    * and return the response to the relative callback
    * @param connection the connection to execute and collect the informations
    */
void sendResponseMessage(HttpURLConnection connection) {
	String responseBody = null;
	InputStream response = null;
	try {
		int responseCode = connection.getResponseCode();
		if(responseCode >= 300) {
			response = connection.getErrorStream();
			if(response != null) responseBody = Util.inputStreamToString(response);
               sendFailMessage(new HttpRetryException(connection.getResponseMessage(),
                       responseCode), responseBody);
		} else {
			response = connection.getInputStream();
			if(response != null) responseBody = Util.inputStreamToString(response);
			sendSuccessMessage(responseCode, responseBody);
		}
	} catch(IOException e) {
		sendFailMessage(e, (String)null);
	} finally {
		if(response != null) Util.closeQuietly(response);
	}
}
 
开发者ID:leonardoxh,项目名称:AsyncOkHttpClient,代码行数:27,代码来源:AsyncHttpResponse.java

示例4: testAuthenticateWithStreamingPost

import java.net.HttpRetryException; //导入依赖的package包/类
private void testAuthenticateWithStreamingPost(StreamingMode streamingMode) throws Exception {
  MockResponse pleaseAuthenticate = new MockResponse().setResponseCode(401)
      .addHeader("WWW-Authenticate: Basic realm=\"protected area\"")
      .setBody("Please authenticate.");
  server.enqueue(pleaseAuthenticate);

  Authenticator.setDefault(new RecordingAuthenticator());
  urlFactory.setClient(urlFactory.client().newBuilder()
      .authenticator(new JavaNetAuthenticator())
      .build());
  connection = urlFactory.open(server.url("/").url());
  connection.setDoOutput(true);
  byte[] requestBody = {'A', 'B', 'C', 'D'};
  if (streamingMode == StreamingMode.FIXED_LENGTH) {
    connection.setFixedLengthStreamingMode(requestBody.length);
  } else if (streamingMode == StreamingMode.CHUNKED) {
    connection.setChunkedStreamingMode(0);
  }
  OutputStream outputStream = connection.getOutputStream();
  outputStream.write(requestBody);
  outputStream.close();
  try {
    connection.getInputStream();
    fail();
  } catch (HttpRetryException expected) {
  }

  // no authorization header for the request...
  RecordedRequest request = server.takeRequest();
  assertNull(request.getHeader("Authorization"));
  assertEquals("ABCD", request.getBody().readUtf8());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:URLConnectionTest.java

示例5: getResponse

import java.net.HttpRetryException; //导入依赖的package包/类
private HttpEngine getResponse() throws IOException {
    initHttpEngine();
    if (this.httpEngine.hasResponse()) {
        return this.httpEngine;
    }
    while (true) {
        if (execute(true)) {
            Response response = this.httpEngine.getResponse();
            Request followUp = this.httpEngine.followUpRequest();
            if (followUp == null) {
                this.httpEngine.releaseStreamAllocation();
                return this.httpEngine;
            }
            int i = this.followUpCount + 1;
            this.followUpCount = i;
            if (i > 20) {
                throw new ProtocolException("Too many follow-up requests: " + this
                        .followUpCount);
            }
            this.url = followUp.url();
            this.requestHeaders = followUp.headers().newBuilder();
            Sink requestBody = this.httpEngine.getRequestBody();
            if (!followUp.method().equals(this.method)) {
                requestBody = null;
            }
            if (requestBody == null || (requestBody instanceof RetryableSink)) {
                StreamAllocation streamAllocation = this.httpEngine.close();
                if (!this.httpEngine.sameConnection(followUp.httpUrl())) {
                    streamAllocation.release();
                    streamAllocation = null;
                }
                this.httpEngine = newHttpEngine(followUp.method(), streamAllocation,
                        (RetryableSink) requestBody, response);
            } else {
                throw new HttpRetryException("Cannot retry streamed HTTP body", this
                        .responseCode);
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:41,代码来源:HttpURLConnectionImpl.java

示例6: assertDeserialized

import java.net.HttpRetryException; //导入依赖的package包/类
public void assertDeserialized(Serializable reference, Serializable test) {

            HttpRetryException ref = (HttpRetryException) reference;
            HttpRetryException tst = (HttpRetryException) test;

            assertEquals("getLocation", ref.getLocation(), tst.getLocation());
            assertEquals("responseCode", ref.responseCode(), tst.responseCode());
            assertEquals("getReason", ref.getReason(), tst.getReason());
            assertEquals("getMessage", ref.getMessage(), tst.getMessage());
        }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:11,代码来源:HttpRetryExceptionTest.java

示例7: testAuthenticateWithStreamingPost

import java.net.HttpRetryException; //导入依赖的package包/类
private void testAuthenticateWithStreamingPost(StreamingMode streamingMode) throws Exception {
    MockResponse pleaseAuthenticate = new MockResponse()
            .setResponseCode(401)
            .addHeader("WWW-Authenticate: Basic realm=\"protected area\"")
            .setBody("Please authenticate.");
    server.enqueue(pleaseAuthenticate);
    server.play();

    Authenticator.setDefault(SIMPLE_AUTHENTICATOR);
    HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
    connection.setDoOutput(true);
    byte[] requestBody = { 'A', 'B', 'C', 'D' };
    if (streamingMode == StreamingMode.FIXED_LENGTH) {
        connection.setFixedLengthStreamingMode(requestBody.length);
    } else if (streamingMode == StreamingMode.CHUNKED) {
        connection.setChunkedStreamingMode(0);
    }
    OutputStream outputStream = connection.getOutputStream();
    outputStream.write(requestBody);
    outputStream.close();
    try {
        connection.getInputStream();
        fail();
    } catch (HttpRetryException expected) {
    }

    // no authorization header for the request...
    RecordedRequest request = server.takeRequest();
    assertContainsNoneMatching(request.getHeaders(), "Authorization: Basic .*");
    assertEquals(Arrays.toString(requestBody), Arrays.toString(request.getBody()));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:32,代码来源:URLConnectionTest.java

示例8: test_ConstructorLStringI

import java.net.HttpRetryException; //导入依赖的package包/类
public void test_ConstructorLStringI() {
    String [] message = {"Test message", "", "Message", "[email protected]#$% &*(", null};
    int [] codes = {400, 404, 200, 500, 0};

    for(int i = 0; i < message.length; i++) {
        HttpRetryException hre = new HttpRetryException(message[i],
                codes[i]);
        assertEquals(message[i], hre.getReason());
        assertTrue("responseCode is incorrect: " + hre.responseCode(),
                hre.responseCode() == codes[i]);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:13,代码来源:OldHttpRetryExceptionTest.java

示例9: test_ConstructorLStringILString

import java.net.HttpRetryException; //导入依赖的package包/类
public void test_ConstructorLStringILString() {
    String [] message = {"Test message", "", "Message", "[email protected]#$% &*(", null};
    int [] codes = {400, -1, Integer.MAX_VALUE, Integer.MIN_VALUE, 0};
    String [] locations = {"file:\\error.txt", "http:\\localhost",
            "", null, ""};

    for(int i = 0; i < message.length; i++) {
        HttpRetryException hre = new HttpRetryException(message[i],
                codes[i], locations[i]);
        assertEquals(message[i], hre.getReason());
        assertTrue("responseCode is incorrect: " + hre.responseCode(),
                hre.responseCode() == codes[i]);
        assertEquals(locations[i], hre.getLocation());
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:16,代码来源:OldHttpRetryExceptionTest.java

示例10: testAuthenticateWithStreamingPost

import java.net.HttpRetryException; //导入依赖的package包/类
private void testAuthenticateWithStreamingPost(StreamingMode streamingMode) throws Exception {
  MockResponse pleaseAuthenticate = new MockResponse().setResponseCode(401)
      .addHeader("WWW-Authenticate: Basic realm=\"protected area\"")
      .setBody("Please authenticate.");
  server.enqueue(pleaseAuthenticate);
  server.play();

  Authenticator.setDefault(new RecordingAuthenticator());
  connection = client.open(server.getUrl("/"));
  connection.setDoOutput(true);
  byte[] requestBody = { 'A', 'B', 'C', 'D' };
  if (streamingMode == StreamingMode.FIXED_LENGTH) {
    connection.setFixedLengthStreamingMode(requestBody.length);
  } else if (streamingMode == StreamingMode.CHUNKED) {
    connection.setChunkedStreamingMode(0);
  }
  OutputStream outputStream = connection.getOutputStream();
  outputStream.write(requestBody);
  outputStream.close();
  try {
    connection.getInputStream();
    fail();
  } catch (HttpRetryException expected) {
  }

  // no authorization header for the request...
  RecordedRequest request = server.takeRequest();
  assertContainsNoneMatching(request.getHeaders(), "Authorization: Basic .*");
  assertEquals(Arrays.toString(requestBody), Arrays.toString(request.getBody()));
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:31,代码来源:URLConnectionTest.java

示例11: testAuthenticateWithStreamingPost

import java.net.HttpRetryException; //导入依赖的package包/类
private void testAuthenticateWithStreamingPost(StreamingMode streamingMode) throws Exception {
  MockResponse pleaseAuthenticate = new MockResponse().setResponseCode(401)
      .addHeader("WWW-Authenticate: Basic realm=\"protected area\"")
      .setBody("Please authenticate.");
  server.enqueue(pleaseAuthenticate);
  server.play();

  Authenticator.setDefault(new RecordingAuthenticator());
  HttpURLConnection connection = client.open(server.getUrl("/"));
  connection.setDoOutput(true);
  byte[] requestBody = { 'A', 'B', 'C', 'D' };
  if (streamingMode == StreamingMode.FIXED_LENGTH) {
    connection.setFixedLengthStreamingMode(requestBody.length);
  } else if (streamingMode == StreamingMode.CHUNKED) {
    connection.setChunkedStreamingMode(0);
  }
  OutputStream outputStream = connection.getOutputStream();
  outputStream.write(requestBody);
  outputStream.close();
  try {
    connection.getInputStream();
    fail();
  } catch (HttpRetryException expected) {
  }

  // no authorization header for the request...
  RecordedRequest request = server.takeRequest();
  assertContainsNoneMatching(request.getHeaders(), "Authorization: Basic .*");
  assertEquals(Arrays.toString(requestBody), Arrays.toString(request.getBody()));
}
 
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:31,代码来源:URLConnectionTest.java

示例12: rewind

import java.net.HttpRetryException; //导入依赖的package包/类
@Override
public void rewind(UploadDataSink uploadDataSink) {
    uploadDataSink.onRewindError(
            new HttpRetryException("Cannot retry streamed Http body", -1));
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:6,代码来源:CronetFixedModeOutputStream.java

示例13: getResponse

import java.net.HttpRetryException; //导入依赖的package包/类
/**
 * Aggressively tries to get the final HTTP response, potentially making
 * many HTTP requests in the process in order to cope with redirects and
 * authentication.
 */
private HttpEngine getResponse() throws IOException {
  initHttpEngine();

  if (httpEngine.hasResponse()) {
    return httpEngine;
  }

  while (true) {
    if (!execute(true)) {
      continue;
    }

    Retry retry = processResponseHeaders();
    if (retry == Retry.NONE) {
      httpEngine.automaticallyReleaseConnectionToPool();
      return httpEngine;
    }

    // The first request was insufficient. Prepare for another...
    String retryMethod = method;
    OutputStream requestBody = httpEngine.getRequestBody();

    // Although RFC 2616 10.3.2 specifies that a HTTP_MOVED_PERM
    // redirect should keep the same method, Chrome, Firefox and the
    // RI all issue GETs when following any redirect.
    int responseCode = httpEngine.getResponseCode();
    if (responseCode == HTTP_MULT_CHOICE
        || responseCode == HTTP_MOVED_PERM
        || responseCode == HTTP_MOVED_TEMP
        || responseCode == HTTP_SEE_OTHER) {
      retryMethod = "GET";
      requestBody = null;
    }

    if (requestBody != null && !(requestBody instanceof RetryableOutputStream)) {
      throw new HttpRetryException("Cannot retry streamed HTTP body", responseCode);
    }

    if (retry == Retry.DIFFERENT_CONNECTION) {
      httpEngine.automaticallyReleaseConnectionToPool();
    }

    httpEngine.release(false);

    httpEngine = newHttpEngine(retryMethod, rawRequestHeaders, httpEngine.getConnection(),
        (RetryableOutputStream) requestBody);

    if (requestBody == null) {
      // Drop the Content-Length header when redirected from POST to GET.
      httpEngine.getRequestHeaders().removeContentLength();
    }
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:59,代码来源:HttpURLConnectionImpl.java

示例14: getResponse

import java.net.HttpRetryException; //导入依赖的package包/类
/**
 * Aggressively tries to get the final HTTP response, potentially making many HTTP requests in the
 * process in order to cope with redirects and authentication.
 */
private HttpEngine getResponse() throws IOException {
  initHttpEngine();

  if (httpEngine.hasResponse()) {
    return httpEngine;
  }

  while (true) {
    if (!execute(true)) {
      continue;
    }

    Response response = httpEngine.getResponse();
    Request followUp = httpEngine.followUpRequest();

    if (followUp == null) {
      httpEngine.releaseStreamAllocation();
      return httpEngine;
    }

    if (++followUpCount > HttpEngine.MAX_FOLLOW_UPS) {
      throw new ProtocolException("Too many follow-up requests: " + followUpCount);
    }

    // The first request was insufficient. Prepare for another...
    url = followUp.url().url();
    requestHeaders = followUp.headers().newBuilder();

    // Although RFC 2616 10.3.2 specifies that a HTTP_MOVED_PERM redirect
    // should keep the same method, Chrome, Firefox and the RI all issue GETs
    // when following any redirect.
    Sink requestBody = httpEngine.getRequestBody();
    if (!followUp.method().equals(method)) {
      requestBody = null;
    }

    if (requestBody != null && !(requestBody instanceof RetryableSink)) {
      throw new HttpRetryException("Cannot retry streamed HTTP body", responseCode);
    }

    StreamAllocation streamAllocation = httpEngine.close();
    if (!httpEngine.sameConnection(followUp.url())) {
      streamAllocation.release();
      streamAllocation = null;
    }

    httpEngine = newHttpEngine(followUp.method(), streamAllocation, (RetryableSink) requestBody,
        response);
  }
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:55,代码来源:HttpURLConnectionImpl.java

示例15: checkErrorsAndUpdateStatus

import java.net.HttpRetryException; //导入依赖的package包/类
/**
 *  Checks for errors from standard read/write requests and performs
 *  occasional status checks.
 *
 *  @param line the response from the server to analyze
 *  @param caller what we tried to do
 *  @throws CredentialNotFoundException if permission denied
 *  @throws AccountLockedException if the user is blocked
 *  @throws HttpRetryException if the database is locked or action was
 *  throttled and a retry failed
 *  @throws AssertionError if assertions fail
 *  @throws UnknownError in the case of a MediaWiki bug
 *  @since 0.18
 */
protected void checkErrorsAndUpdateStatus(String line, String caller) throws IOException, LoginException
{
    // perform various status checks every 100 or so edits
    if (statuscounter > statusinterval)
    {
        // purge user rights in case of desysop or loss of other priviliges
        user.getUserInfo();
        if ((assertion & ASSERT_SYSOP) == ASSERT_SYSOP && !user.isA("sysop"))
            // assert user.isA("sysop") : "Sysop privileges missing or revoked, or session expired";
            throw new AssertionError("Sysop privileges missing or revoked, or session expired");
        // check for new messages
        if ((assertion & ASSERT_NO_MESSAGES) == ASSERT_NO_MESSAGES && hasNewMessages())
            // assert !hasNewMessages() : "User has new messages";
            throw new AssertionError("User has new messages");
        statuscounter = 0;
    }
    else
        statuscounter++;

    // successful
    if (line.contains("result=\"Success\""))
        return;
    // empty response from server
    if (line.isEmpty())
        throw new UnknownError("Received empty response from server!");
    // assertions
    if ((assertion & ASSERT_BOT) == ASSERT_BOT && line.contains("error code=\"assertbotfailed\""))
        // assert !line.contains("error code=\"assertbotfailed\"") : "Bot privileges missing or revoked, or session expired.";
        throw new AssertionError("Bot privileges missing or revoked, or session expired.");
    if ((assertion & ASSERT_USER) == ASSERT_USER && line.contains("error code=\"assertuserfailed\""))
        // assert !line.contains("error code=\"assertuserfailed\"") : "Session expired.";
        throw new AssertionError("Session expired.");
    if (line.contains("error code=\"permissiondenied\""))
        throw new CredentialNotFoundException("Permission denied."); // session expired or stupidity
    // rate limit (automatic retry), though might be a long one (e.g. email)
    if (line.contains("error code=\"ratelimited\""))
    {
        log(Level.WARNING, caller, "Server-side throttle hit.");
        throw new HttpRetryException("Action throttled.", 503);
    }
    // blocked! (note here the \" in blocked is deliberately missing for emailUser()
    if (line.contains("error code=\"blocked") || line.contains("error code=\"autoblocked\""))
    {
        log(Level.SEVERE, caller, "Cannot " + caller + " - user is blocked!.");
        throw new AccountLockedException("Current user is blocked!");
    }
    // database lock (automatic retry)
    if (line.contains("error code=\"readonly\""))
    {
        log(Level.WARNING, caller, "Database locked!");
        throw new HttpRetryException("Database locked!", 503);
    }
    // unknown error
    if (line.contains("error code=\"unknownerror\""))
        throw new UnknownError("Unknown MediaWiki API error, response was " + line);
    // generic (automatic retry)
    throw new IOException("MediaWiki error, response was " + line);
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:73,代码来源:Wiki.java


注:本文中的java.net.HttpRetryException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。