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


Java ProtocolVersion类代码示例

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


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

示例1: post_whenResponseIsFailure_logsException

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
@Test
public void post_whenResponseIsFailure_logsException() throws IOException {
    ArgumentCaptor<HttpPost> requestCaptor = ArgumentCaptor.forClass(HttpPost.class);
    HttpClient httpClient = mock(HttpClient.class);
    BasicHttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1), 400, ""));
    response.setEntity(new StringEntity("failure reason here"));

    when(httpClient.execute(requestCaptor.capture())).thenReturn(response);

    MsTeamsNotification w = factory.getMsTeamsNotification(httpClient);

    MsTeamsNotificationPayloadContent content = new MsTeamsNotificationPayloadContent();
    content.setBuildDescriptionWithLinkSyntax("http://foo");
    content.setCommits(new ArrayList<Commit>());

    w.setPayload(content);
    w.setEnabled(true);
    w.post();

    assertNotNull(w.getResponse());
    assertFalse(w.getResponse().getOk());
}
 
开发者ID:spyder007,项目名称:teamcity-msteams-notifier,代码行数:23,代码来源:MsTeamsNotificationTest.java

示例2: testOAuthStepTwo

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
@Test
public void testOAuthStepTwo() throws IOException {
    //Create the mock response
    HttpResponse postResponse = new BasicHttpResponse(new ProtocolVersion("TEST", 0, 0), 200, "TEST");
    postResponse.setEntity(new StringEntity(oauthStepTwoTestJSON));

    //Set the call providers mock response
    callProvider.setPostResponse(postResponse);


    //Perform mock oauth step 2
    Credentials credentials = client.oauthStepTwo(null, null);

    //Check null is not returned
    assertNotNull(credentials);

    //Check the info is what it should be
    assertEquals("access_token", credentials.getAccessToken());
    assertEquals("refresh_token", credentials.getRefreshToken());
    assertEquals("1234567890", credentials.getDateGenerated());
}
 
开发者ID:NoahLutz,项目名称:gmusic-java,代码行数:22,代码来源:GMusicClientTest.java

示例3: checkRefreshToken

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
/**
 * Checks to make sure that tokens and dates are refreshed given a valid response from google
 * Gives a mock response from google with "new" access code
 * @throws IOException
 */
@Test
public void checkRefreshToken() throws IOException {
    long dateGenerated = Instant.now().getEpochSecond() - (3600*2);
    credentials = new Credentials(jsonWithoutDate, dateGenerated);

    //Create mock response
    MockCall callProvider = new MockCall();
    HttpResponse postResponse =  new BasicHttpResponse(new ProtocolVersion("TEST", 0, 0), 200, "TEST");
    postResponse.setEntity(new StringEntity("{ \"access_token\":\"new_access_token\", \"expires_in\":3920, \"token_type\":\"Bearer\" }"));
    callProvider.setPostResponse(postResponse);

    //Make assertions
    assertTrue(credentials.refreshToken(null, null, callProvider));
    assertEquals("new_access_token", credentials.getAccessToken());
    assertNotEquals(String.valueOf(dateGenerated), credentials.getDateGenerated());
}
 
开发者ID:NoahLutz,项目名称:gmusic-java,代码行数:22,代码来源:CredentialsTest.java

示例4: bufferLimitTest

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
private static void bufferLimitTest(HeapBufferedAsyncResponseConsumer consumer, int bufferLimit) throws Exception {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    consumer.onResponseReceived(new BasicHttpResponse(statusLine));

    final AtomicReference<Long> contentLength = new AtomicReference<>();
    HttpEntity entity = new StringEntity("", ContentType.APPLICATION_JSON) {
        @Override
        public long getContentLength() {
            return contentLength.get();
        }
    };
    contentLength.set(randomLong(bufferLimit));
    consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);

    contentLength.set(randomLongBetween(bufferLimit + 1, MAX_TEST_BUFFER_SIZE));
    try {
        consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);
    } catch(ContentTooLongException e) {
        assertEquals("entity content is too long [" + entity.getContentLength() +
                "] for the configured buffer limit [" + bufferLimit + "]", e.getMessage());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:HeapBufferedAsyncResponseConsumerTests.java

示例5: BasicRequestLine

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
public BasicRequestLine(final String method,
                        final String uri,
                        final ProtocolVersion version) {
    super();
    if (method == null) {
        throw new IllegalArgumentException
            ("Method must not be null.");
    }
    if (uri == null) {
        throw new IllegalArgumentException
            ("URI must not be null.");
    }
    if (version == null) {
        throw new IllegalArgumentException
            ("Protocol version must not be null.");
    }
    this.method = method;
    this.uri = uri;
    this.protoversion = version;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:BasicRequestLine.java

示例6: parseProtocolVersion

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
public final static
    ProtocolVersion parseProtocolVersion(String value,
                                         LineParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null.");
    }

    if (parser == null)
        parser = BasicLineParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseProtocolVersion(buffer, cursor);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:BasicLineParser.java

示例7: BasicStatusLine

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
/**
 * Creates a new status line with the given version, status, and reason.
 *
 * @param version           the protocol version of the response
 * @param statusCode        the status code of the response
 * @param reasonPhrase      the reason phrase to the status code, or
 *                          <code>null</code>
 */
public BasicStatusLine(final ProtocolVersion version, int statusCode,
                       final String reasonPhrase) {
    super();
    if (version == null) {
        throw new IllegalArgumentException
            ("Protocol version may not be null.");
    }
    if (statusCode < 0) {
        throw new IllegalArgumentException
            ("Status code may not be negative.");
    }
    this.protoVersion = version;
    this.statusCode   = statusCode;
    this.reasonPhrase = reasonPhrase;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:BasicStatusLine.java

示例8: process

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
        // Do not send the expect header if request body is known to be empty
        if (entity != null && entity.getContentLength() != 0) {
            ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
            if (HttpProtocolParams.useExpectContinue(request.getParams())
                    && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
                request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:RequestExpectContinue.java

示例9: testMap

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
@Test
public void testMap() throws Exception {
    assertEquals("Message. 500 reason. Please contact your web hosting service provider for assistance.", new SwiftExceptionMappingService().map(
            new GenericException("message", null, new StatusLine() {
                @Override
                public ProtocolVersion getProtocolVersion() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public int getStatusCode() {
                    return 500;
                }

                @Override
                public String getReasonPhrase() {
                    return "reason";
                }
            })).getDetail());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:21,代码来源:SwiftExceptionMappingServiceTest.java

示例10: toProtocolVersion

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
private ProtocolVersion toProtocolVersion(String httpVersion) {
    switch (httpVersion) {
        case "HTTP/0.9":
        case "0.9":
            return HttpVersion.HTTP_0_9;
        case "HTTP/1.0":
        case "1.0":
            return HttpVersion.HTTP_1_0;
        case "HTTP/1.1":
        case "1.1":
            return HttpVersion.HTTP_1_1;
        default:
            throw new IllegalArgumentException("Invalid HTTP version: " + httpVersion);

    }
}
 
开发者ID:renatoathaydes,项目名称:rawhttp,代码行数:17,代码来源:RawHttpComponentsClient.java

示例11: execute

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) {
    requestExecuted = request;
    StatusLine statusLine = new BasicStatusLine(
            new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
    HttpResponse response = new BasicHttpResponse(statusLine);
    response.setEntity(mResponseEntity);

    return response;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:MockHttpClient.java

示例12: parseProtocol

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
private static ProtocolVersion parseProtocol(final Protocol p) {
    switch (p) {
        case HTTP_1_0:
            return new ProtocolVersion("HTTP", 1, 0);
        case HTTP_1_1:
            return new ProtocolVersion("HTTP", 1, 1);
        case SPDY_3:
            return new ProtocolVersion("SPDY", 3, 1);
        case HTTP_2:
            return new ProtocolVersion("HTTP", 2, 0);
    }

    throw new IllegalAccessError("Unkwown protocol");
}
 
开发者ID:wangzhaosheng,项目名称:publicProject,代码行数:15,代码来源:OkHttpStack.java

示例13: testVerifyCredentialsExpired

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
@Test
public void testVerifyCredentialsExpired() throws IOException {
    //Create the mock response
    HttpResponse postResponse = new BasicHttpResponse(new ProtocolVersion("TEST", 0, 0), 200,"TEST");
    postResponse.setEntity(new StringEntity(verifyCredsTestResponseJSON));
    callProvider.setPostResponse(postResponse);

    //Create credentials with date generated that will cause it to try to refresh the token
    Credentials credentials = new Credentials(verifyCredsTestDefaultJSON, (Instant.now().getEpochSecond() - 3600*2));

    //Verify that credentials should be valid
    assertTrue(client.verifyCredentials(credentials));
}
 
开发者ID:NoahLutz,项目名称:gmusic-java,代码行数:14,代码来源:GMusicClientTest.java

示例14: performRequest

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion,
            connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:43,代码来源:HurlStack.java

示例15: mockResponse

import org.apache.http.ProtocolVersion; //导入依赖的package包/类
private static Response mockResponse() {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    return new Response(requestLine, new HttpHost("localhost", 9200), httpResponse);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:SyncResponseListenerTests.java


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