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


Java Response.status方法代码示例

本文整理汇总了Java中com.jcabi.http.Response.status方法的典型用法代码示例。如果您正苦于以下问题:Java Response.status方法的具体用法?Java Response.status怎么用?Java Response.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcabi.http.Response的用法示例。


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

示例1: validate

import com.jcabi.http.Response; //导入方法依赖的package包/类
@Override
public ValidationResponse validate(final String html)
    throws IOException {
    final Request req = this.request(html);
    final Response response = req.fetch();
    if (response.status() != HttpURLConnection.HTTP_OK) {
        throw new IOException(
            response.reason()
        );
    }
    return this.build(
        response.as(XmlResponse.class)
            .registerNs("nu", "http://n.validator.nu/messages/")
            .assertXPath("//nu:messages")
            .assertXPath("//nu:source")
            .xml()
    );
}
 
开发者ID:jcabi,项目名称:jcabi-w3c,代码行数:19,代码来源:DefaultHtmlValidator.java

示例2: validateCacheWithServer

import com.jcabi.http.Response; //导入方法依赖的package包/类
/**
 * Check response and update cache or evict from cache if needed.
 * @param req Request
 * @param home URI to fetch
 * @param method HTTP method
 * @param headers Headers
 * @param content HTTP body
 * @param connect The connect timeout
 * @param read The read timeout
 * @return Response obtained
 * @throws IOException if fails
 * @checkstyle ParameterNumber (8 lines)
 */
private Response validateCacheWithServer(
    final Request req, final String home, final String method,
    final Collection<Map.Entry<String, String>> headers,
    final InputStream content, final int connect, final int read
) throws IOException {
    final Response cached = this.cache.get(req);
    final Collection<Map.Entry<String, String>> hdrs = this.enrich(
        headers, cached
    );
    Response result = this.origin.send(
        req, home, method, hdrs, content, connect, read
    );
    if (result.status() == HttpURLConnection.HTTP_NOT_MODIFIED) {
        result = cached;
    } else {
        this.updateCache(req, result);
    }
    return result;
}
 
开发者ID:jcabi,项目名称:jcabi-http,代码行数:33,代码来源:AbstractHeaderBasedCachingWire.java

示例3: send

import com.jcabi.http.Response; //导入方法依赖的package包/类
@Override
public Response send(final Request req, final String home,
    final String method,
    final Collection<Map.Entry<String, String>> headers,
    final InputStream content,
    final int connect,
    final int read) throws IOException {
    Response response = this.origin.send(
        req, home, method, headers, content, connect, read
    );
    int attempt = 1;
    final URI uri = URI.create(home);
    while (attempt < this.max) {
        if (response.status() < HttpURLConnection.HTTP_MULT_CHOICE
            || response.status() >= HttpURLConnection.HTTP_BAD_REQUEST) {
            break;
        }
        final List<String> locations = response.headers().get(
            HttpHeaders.LOCATION
        );
        if (locations == null || locations.size() != 1) {
            break;
        }
        URI location = URI.create(locations.get(0));
        if (!location.isAbsolute()) {
            location = uri.resolve(uri);
        }
        response = this.origin.send(
            req, location.toString(),
            method, headers, content, connect, read
        );
        try {
            TimeUnit.SECONDS.sleep((long) attempt);
        } catch (final InterruptedException ex) {
            throw new IOException(ex);
        }
        ++attempt;
    }
    return response;
}
 
开发者ID:jcabi,项目名称:jcabi-http,代码行数:41,代码来源:AutoRedirectingWire.java

示例4: send

import com.jcabi.http.Response; //导入方法依赖的package包/类
@Override
public Response send(final Request req, final String home,
    final String method,
    final Collection<Map.Entry<String, String>> headers,
    final InputStream content,
    final int connect, final int read) throws IOException {
    int attempt = 0;
    while (true) {
        if (attempt > Tv.THREE) {
            throw new IOException(
                String.format("failed after %d attempts", attempt)
            );
        }
        try {
            final Response rsp = this.origin.send(
                req, home, method, headers, content,
                connect, read
            );
            if (rsp.status() < HttpURLConnection.HTTP_INTERNAL_ERROR) {
                return rsp;
            }
            Logger.warn(
                this, "%s %s returns %d status (attempt #%d)",
                method, home, rsp.status(), attempt + 1
            );
        } catch (final IOException ex) {
            Logger.warn(
                this, "%s: %s",
                ex.getClass().getName(), ex.getLocalizedMessage()
            );
        }
        ++attempt;
    }
}
 
开发者ID:jcabi,项目名称:jcabi-http,代码行数:35,代码来源:RetryWire.java

示例5: updateCache

import com.jcabi.http.Response; //导入方法依赖的package包/类
/**
 * Add, update or evict response in cache.
 * @param req The request to be used as key
 * @param rsp The response to add/update
 */
private void updateCache(final Request req, final Response rsp) {
    if (rsp.headers().containsKey(this.scvh)) {
        this.cache.put(req, rsp);
    } else if (rsp.status() == HttpURLConnection.HTTP_OK) {
        this.cache.remove(req);
    }
}
 
开发者ID:jcabi,项目名称:jcabi-http,代码行数:13,代码来源:AbstractHeaderBasedCachingWire.java

示例6: assertResponse

import com.jcabi.http.Response; //导入方法依赖的package包/类
/**
 * Assert that the response matched the expected.
 *
 * @param restTest
 * @param response
 */
private void assertResponse(RestTest restTest, Response response) {
    int actualStatusCode = response.status();
    try {
        Assert.assertEquals("Unexpected REST response status code.  Status message: " + response.reason(), restTest.getExpectedStatusCode(),
                actualStatusCode);
    } catch (Error e) {
        if (actualStatusCode >= 400) {
            InputStream content = null;
            try {
                String payload = response.body();
                System.out.println("------ START ERROR PAYLOAD ------");
                if (payload.startsWith("{")) {
                    payload = payload.replace("\\r\\n", "\r\n").replace("\\t", "\t");
                }
                System.out.println(payload);
                System.out.println("------ END   ERROR PAYLOAD ------");
            } catch (Exception e1) {
            } finally {
                IOUtils.closeQuietly(content);
            }
        }
        throw e;
    }
    for (Entry<String, String> entry : restTest.getExpectedResponseHeaders().entrySet()) {
        String expectedHeaderName = entry.getKey();
        if (expectedHeaderName.startsWith("X-RestTest-"))
            continue;
        String expectedHeaderValue = entry.getValue();
        List<String> headers = response.headers().get(expectedHeaderName);

        Assert.assertNotNull("Expected header to exist but was not found: " + expectedHeaderName, headers);
        Assert.assertEquals(expectedHeaderValue, headers.get(0));
    }
    List<String> ctValueList = response.headers().get("Content-Type");
    if (ctValueList == null) {
        assertNoPayload(restTest, response);
    } else {
        String ctValueFirst = ctValueList.get(0);
        if (ctValueFirst.startsWith("application/json")) {
            assertJsonPayload(restTest, response);
        } else if (ctValueFirst.startsWith("text/plain") || ctValueFirst.startsWith("text/html")) {
            assertTextPayload(restTest, response);
        } else if (ctValueFirst.startsWith("application/xml") || ctValueFirst.startsWith("application/wsdl+xml")) {
            assertXmlPayload(restTest, response);
        } else {
            Assert.fail("Unsupported response payload type: " + ctValueFirst);
        }
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:56,代码来源:TestPlanRunner.java


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