@Override public void success(Response s, Response response) { new JSONObject(new String(((TypedByteArray) response.getBody()).getBytes())) }
/** * Build a Cookie from the specified parameters. * @return The Cookie */ public Cookie build() { return new Cookie(name, value, comment, expiryDate, domain, path, secured, httpOnly, version, maxAge); } }
private static String toString(Headers headers) { if (!headers.exist()) { return ""; } final StringBuilder builder = new StringBuilder(); for (Header header : headers) { builder.append(header.getName()).append(HEADER_NAME_AND_VALUE_SEPARATOR).append(header.getValue()).append("\n"); } builder.deleteCharAt(builder.length() - 1); return builder.toString(); }
public T ifError() { if (response.statusCode() >= 400) { return logResponse(LogDetail.ALL); } return (T) this; }
final StringBuilder builder = new StringBuilder(); if (logDetail == ALL || logDetail == STATUS) { builder.append(responseOptions.statusLine()); final Headers headers = responseOptions.headers(); if (headers.exist()) { appendNewLineIfAll(logDetail, builder).append(toString(headers)); final Cookies cookies = responseOptions.detailedCookies(); if (cookies.exist()) { appendNewLineIfAll(logDetail, builder).append(cookies.toString()); responseBodyToAppend = new Prettifier().getPrettifiedBodyIfPossible(responseOptions, responseBody); } else { responseBodyToAppend = responseBody.asString();
Connection.Response response = null; try { response = Jsoup.connect(bad_url) .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5") .timeout(100000) .ignoreHttpErrors(true) .execute(); } catch (IOException e) { System.out.println("io - "+e); } System.out.println("Status code = " + response.statusCode()); System.out.println("Status msg = " + response.statusMessage());
public Matcher<?> matcher(Response response) { return containsString(response.<String>path(path)); } };
/** * Set a specific header * * @return The builder */ public ResponseBuilder setHeader(String name, String value) { notNull(name, "Header name"); notNull(value, "Header value"); List<Header> newHeaders = new ArrayList<Header>(restAssuredResponse.headers().asList()); newHeaders.add(new Header(name, value)); restAssuredResponse.setResponseHeaders(new Headers(newHeaders)); if (trim(name).equalsIgnoreCase(CONTENT_TYPE)) { restAssuredResponse.setContentType(value); } return this; }
public boolean hasSameNameAs(Header header) { AssertParameter.notNull(header, Header.class); return this.name.equalsIgnoreCase(header.getName()); }
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { long start = System.currentTimeMillis(); Response response = ctx.next(requestSpec, responseSpec); if (shouldConsumeStream && response instanceof RestAssuredResponseImpl && ((RestAssuredResponseImpl) response).isInputStream()) { // Consume the body of the request (important if measure time also should include downloading of body) response.asByteArray(); } long end = System.currentTimeMillis(); long responseTime = end - start; ctx.setValue(RESPONSE_TIME_MILLISECONDS, responseTime); return response; }
private boolean requestHasSessionIdDefined(FilterableRequestSpecification requestSpec) { return requestSpec.getCookies().hasCookieWithName(requestSpec.getConfig().getSessionConfig().sessionIdName()); }
public T ifStatusCodeIsEqualTo(int statusCode) { if (response.statusCode() == statusCode) { return logResponse(LogDetail.ALL); } return (T) this; }
public void success(Response response, Response ignored) { TypedInput body = response.getBody(); try { BufferedReader reader = new BufferedReader(new InputStreamReader(body.in())); StringBuilder out = new StringBuilder(); String newLine = System.getProperty("line.separator"); String line; while ((line = reader.readLine()) != null) { out.append(line); out.append(newLine); } // Prints the correct String representation of body. System.out.println(out); } catch (IOException e) { e.printStackTrace(); } }
public Matcher<?> matcher(Response response) { return equalTo(response.path(path)); } };
Connection.Response response = Jsoup.connect(sitemapPath) .userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21") .timeout(10000) .execute(); int statusCode = response.statusCode(); if(statusCode == 200) { Document doc = connection.get(); Elements element = doc.select("loc"); for (Element urls : element) { System.out.println(urls.text()); } } else { System.out.println("received error code : " + statusCode); }
Response response = api.getData() InputStream is = response.getBody().in(); // stream your data directly from the InputStream!
public Matcher<?> matcher(Response response) { return endsWith(response.<String>path(path)); } };
public T ifStatusCodeMatches(Matcher<Integer> matcher) { notNull(matcher, "Matcher"); if (matcher.matches(response.statusCode())) { return logResponse(LogDetail.ALL); } return (T) this; }
RestClient restClient; // create your restClient Response response = restClient.getYourJson(); Gson gson = new Gson(); String json = response.getBody().toString(); if (checkResponseMessage(json)) { Pojo1 pojo1 = gson.fromJson(json, Pojo1.class); } else { Pojo2 pojo2 = gson.fromJson(json, Pojo2.class); }
public Matcher<?> matcher(Response response) { return startsWith(response.<String>path(path)); } };