@Override public int status() { return this.response.status(); } @Override
@Override public final int status() { return this.response.status(); }
@Override public boolean matches(final Object resp) { return Response.class.cast(resp).status() == this.status; } }
/** * 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); } }
/** * Check if response from W3C contains some bad status. * @param response Response from W3c. * @return Response passed as parameter. * @throws IOException when has some bad status. */ private static Response correct(final Response response) throws IOException { final List<Integer> statuses = Arrays.asList( HttpURLConnection.HTTP_INTERNAL_ERROR, HttpURLConnection.HTTP_NOT_IMPLEMENTED, HttpURLConnection.HTTP_BAD_GATEWAY, HttpURLConnection.HTTP_UNAVAILABLE, HttpURLConnection.HTTP_GATEWAY_TIMEOUT, HttpURLConnection.HTTP_VERSION ); if (statuses.contains(response.status())) { throw new IOException( String.format( "Bad status from W3C server: %1d", response.status() ) ); } return response; }
/** * Fetch response from server. * @param stream The content to send. * @return The obtained response * @throws IOException If an IO exception occurs. */ private Response fetchResponse(final InputStream stream) throws IOException { final long start = System.currentTimeMillis(); final Response response = this.wire.send( this, this.home, this.mtd, this.hdrs, stream, this.connect, this.read ); final URI uri = URI.create(this.home); Logger.info( this, "#fetch(%s %s%s %s): [%d %s] in %[ms]s", this.mtd, uri.getHost(), // @checkstyle AvoidInlineConditionalsCheck (1 line) uri.getPort() > 0 ? String.format(":%d", uri.getPort()) : "", uri.getPath(), response.status(), response.reason(), System.currentTimeMillis() - start ); return response; }
req, home, method, hdrs, content, connect, read ); if (result.status() == HttpURLConnection.HTTP_NOT_MODIFIED) { result = cached; } else {
rsp.binary() ), rsp.status(), rsp.reason() );
throws IOException { final JsonObjectBuilder json = Json.createObjectBuilder(); json.add("status", response.status()); json.add("reason", response.reason()); final JsonObjectBuilder headers = Json.createObjectBuilder();
rsp.binary() ), rsp.status(), rsp.reason() );
int actualStatusCode = response.status(); try { Assert.assertEquals("Unexpected REST response status code. Status message: " + response.reason(), restTest.getExpectedStatusCode(),
@Override public boolean unlock(final String label) throws IOException { final long start = System.currentTimeMillis(); final Response rsp = this.front("unlock") .uri().queryParam("label", label) .queryParam("name", this.lck).back() .method(Request.GET) .fetch(); final boolean unlocked = rsp.status() == HttpURLConnection.HTTP_SEE_OTHER; Logger.info( this, "unlock of \"%s\" is %B in %[ms]s", this.lck, unlocked, System.currentTimeMillis() - start ); return unlocked; }
@Override public boolean lock(final String label) throws IOException { final long start = System.currentTimeMillis(); final Response rsp = this.front("lock") .body().formParam("label", label) .formParam("name", this.lck).back() .method(Request.POST) .fetch(); final boolean locked = rsp.status() == HttpURLConnection.HTTP_SEE_OTHER; Logger.info( this, "lock of \"%s\" is %B in %[ms]s: %s", this.lck, locked, System.currentTimeMillis() - start, rsp.body() ); return locked; }
@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() ); }