URI uri = getMethod.getURI(); String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort()); if (getMethod.getStatusCode() >= 300) { LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode()); continue;
try { getMethod = completionService.take().get(); if (getMethod.getStatusCode() >= 300) { ++errors; Assert.assertEquals(getMethod.getResponseBodyAsString(), ERROR_MSG);
httpClient.executeMethod(get); if (get.getStatusCode() != 200 && get.getStatusCode() != 201) { logger.error("Connect failed with error code " + get.getStatusCode() + " and message:\n" + get.getResponseBodyAsString()); throw new ConnectionException("Connect failed, error code " + get.getStatusCode() + " and message: " + get.getResponseBodyAsString());
if (getMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(getMethod); getMethod.releaseConnection();
@Override public byte[] extractResult(GetMethod method) throws IOException { //TODO: remove SC_NO_CONTENT if it depends on Swift versions if (method.getStatusCode() == SC_NOT_FOUND || method.getStatusCode() == SC_FORBIDDEN || method.getStatusCode() == SC_NO_CONTENT || method.getResponseBodyAsStream() == null) { return null; } final InputStream responseBodyAsStream = method.getResponseBodyAsStream(); final byte[] locationData = new byte[1024]; return responseBodyAsStream.read(locationData) > 0 ? locationData : null; }
public boolean exists(EntityReference reference) throws Exception { GetMethod getMethod = executeGet(reference); getMethod.releaseConnection(); return getMethod.getStatusCode() == Status.OK.getStatusCode(); }
@Override public byte[] extractResult(GetMethod method) throws IOException { if (method.getStatusCode() == SC_NOT_FOUND) { //no result throw new FileNotFoundException("Not found " + method.getURI()); } return method.getResponseBody(); }
@Override public byte[] extractResult(GetMethod method) throws IOException { if (method.getStatusCode() == SC_NOT_FOUND) { //no result throw new FileNotFoundException("Not found " + method.getURI()); } return method.getResponseBody(); }
public boolean hasPlugin(String pluginKey) { String uri = MARKETPLACE_BROWSE + pluginKey; GetMethod method = createGetMethod(uri); executeMethodIgnoreOutput(method); return (method.getStatusCode() != HttpServletResponse.SC_NOT_FOUND); } }
public BintrayPackage getPackageMetadata(String owner, String repo, String name){ String url = String.format("https://api.bintray.com/packages/%s/%s/%s", owner, repo, name); GetMethod get = new GetMethod(url); try { new HttpClient().executeMethod(get); if (get.getStatusLine() == null || get.getStatusCode() != 200) { throw new IOException(get.getStatusLine().toString()); } JsonParser parser = new JsonFactory().createParser(get.getResponseBodyAsStream()); parser.setCodec(new ObjectMapper()); return parser.readValueAs(BintrayPackage.class); } catch (IOException e) { if(get.getStatusLine() != null && get.getStatusCode() == 404){ return null; } else throw new RuntimeException(e); } }
public List<BintrayFile> getPackageFiles(String owner, String repo, String name, String version){ String url = String.format("https://api.bintray.com/packages/%s/%s/%s/versions/%s/files", owner, repo, name, version); GetMethod get = new GetMethod(url); try { new HttpClient().executeMethod(get); if (get.getStatusLine() == null || get.getStatusCode() != 200) { throw new IOException(get.getStatusLine().toString()); } ObjectMapper mapper = new ObjectMapper(); CollectionType fileListType = mapper.getTypeFactory().constructCollectionType(List.class, BintrayFile.class); List<BintrayFile> bintrayFiles = mapper.readValue(get.getResponseBodyAsStream(), fileListType); return bintrayFiles; } catch (IOException e) { if(get.getStatusLine() != null && get.getStatusCode() == 404){ throw new RuntimeException("Bintray package not found!", e); } else throw new RuntimeException(e); } }
public List<BintrayId> getAvailablePackages(String owner, String repo){ String url = String.format("https://api.bintray.com/repos/%s/%s/packages", owner, repo); GetMethod get = new GetMethod(url); try { new HttpClient().executeMethod(get); if (get.getStatusLine() == null || get.getStatusCode() != 200) { throw new IOException(get.getStatusLine().toString()); } ObjectMapper mapper = new ObjectMapper(); CollectionType idListType = mapper.getTypeFactory().constructCollectionType(List.class, BintrayId.class); List<BintrayId> owaIds = mapper.readValue(get.getResponseBodyAsStream(), idListType); return owaIds; } catch (IOException e) { //avoid NPE if(get.getStatusLine() != null && get.getStatusCode() == 404){ throw new RuntimeException("Bintray repository not found!", e); } else throw new RuntimeException(e); } }
/** * Get media resource as input stream. */ @Override public InputStream getAsStream() throws BlogClientException { final HttpClient httpClient = new HttpClient(); final GetMethod method = new GetMethod(permalink); try { httpClient.executeMethod(method); } catch (final Exception e) { throw new BlogClientException("ERROR: error reading file", e); } if (method.getStatusCode() != 200) { throw new BlogClientException("ERROR HTTP status=" + method.getStatusCode()); } try { return method.getResponseBodyAsStream(); } catch (final Exception e) { throw new BlogClientException("ERROR: error reading file", e); } }
HttpClient httpClient = new HttpClient() GetMethod get = new GetMethod(adviceGetURL); get.addRequestHeader("Content-Type", "application/json"); try { httpClient.executeMethod(get); assertEquals(HttpStatus.SC_OK, get.getStatusCode()); String response = get.getResponseBodyAsString(); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
private String executeGetMethod(GetMethod get) { LOGGER.debug("Making HTTP request to fetch OpenMRS Atom Feed: " + httpClient.getHostConfiguration().getHostURL() + get.getPath() + get.getQueryString()); try { int responseCode = httpClient.executeMethod(get); if (responseCode == HttpStatus.SC_OK) { LOGGER.debug("Successfully made HTTP request to OpenMRS"); return get.getResponseBodyAsString(); } else { LOGGER.warn("OpenMRS Atom Feed module returned non 200 status: " + get.getStatusCode()); return ""; } } catch (IOException e) { LOGGER.error("Motech OpenMRS Atom Feed module could not communicate with the OpenMRS"); throw new MotechException(e.getMessage(), e); } }
private String fetchData(String uri) { try { GetMethod method = new GetMethod(uri); client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { return method.getResponseBodyAsString(); } else { String msg = method.getStatusCode() + " " + method.getStatusText(); l.debug("Exception executing " + method.getName() + " on " + method.getPath() + ": " + msg); throw new HttpMethodException(msg); } } catch (HttpException e) { l.debug("Error invoking Facebook REST API.", e); throw new HttpMethodException("Error invoking Facebook REST API.", e); } catch (IOException e) { l.debug("Error invoking GoodData REST API.", e); throw new HttpMethodException("Error invoking Facebook REST API.", e); } }
private InputStream getResourceAsStream() throws ProponoException { if (getEditURI() == null) { throw new ProponoException("ERROR: not yet saved to server"); } final GetMethod method = new GetMethod(((Content) getContents()).getSrc()); try { getCollection().getHttpClient().executeMethod(method); if (method.getStatusCode() != 200) { throw new ProponoException("ERROR HTTP status=" + method.getStatusCode()); } return method.getResponseBodyAsStream(); } catch (final IOException e) { throw new ProponoException("ERROR: getting media entry", e); } }
@Override public GetMethod executeRequest( URL url, Map<String, String> queryParams, Integer backendTimeout) throws HttpException, IOException { GetMethod response = EasyMock.createMock(GetMethod.class); expect(response.getStatusCode()).andReturn(200); expect(response.getResponseBodyAsStream()) .andReturn(new ByteArrayInputStream(responseBody)); expect(response.getResponseCharSet()).andReturn("UTF-8"); expect(response.getResponseHeader("Content-Type")).andReturn(null); response.releaseConnection(); expectLastCall(); replay(response); return response; } });
public void fetchContents() throws ProponoException { final GetMethod method = new GetMethod(getHrefResolved()); clientCollection.addAuthentication(method); try { clientCollection.getHttpClient().executeMethod(method); if (method.getStatusCode() != 200) { throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode()); } final SAXBuilder builder = new SAXBuilder(); final Document catsDoc = builder.build(new InputStreamReader(method.getResponseBodyAsStream())); parseCategoriesElement(catsDoc.getRootElement()); } catch (final IOException ioe) { throw new ProponoException("ERROR: reading out-of-line categories", ioe); } catch (final JDOMException jde) { throw new ProponoException("ERROR: parsing out-of-line categories", jde); } finally { method.releaseConnection(); } } }
@Override public GetMethod executeRequest( URL url, Map<String, String> queryParams, Integer backendTimeout, WMSLayer.HttpRequestMode httpRequestMode) throws HttpException, IOException { GetMethod response = EasyMock.createMock(GetMethod.class); expect(response.getStatusCode()).andReturn(200); expect(response.getResponseBodyAsStream()) .andReturn(new ByteArrayInputStream(responseBody)); expect(response.getResponseCharSet()).andReturn("UTF-8"); expect(response.getResponseHeader("Content-Type")) .andReturn(new Header("Content-Type", "image/png")); response.releaseConnection(); expectLastCall(); replay(response); return response; } });