public String getResponseHeaderValue(String name) { if (method == null) throw new IllegalStateException("Request has not been made."); Header responseHeader = this.method.getResponseHeader(name); return responseHeader == null ? null : responseHeader.getValue(); }
public InputStream getResponseBodyAsInputStream() throws IOException { if (method == null) throw new IllegalStateException("Request has not been made."); InputStream is = method.getResponseAsStream(); Header contentEncodingHeader = method.getResponseHeader("Content-Encoding"); if (contentEncodingHeader != null) { String contentEncoding = contentEncodingHeader.getValue(); if (contentEncoding != null) { if (contentEncoding.equalsIgnoreCase("gzip")) return new GZIPInputStream(is); else if (contentEncoding.equalsIgnoreCase("deflate")) return new InflaterInputStream(is); } } return is; }
static private ServiceType checkIfCdmr(String location) throws IOException { try (HTTPMethod method = HTTPFactory.Head(location + "?req=header")) { int statusCode = method.execute(); if (statusCode >= 300) { if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) throw new IOException("Unauthorized to open dataset " + location); else throw new IOException(location + " is not a valid URL, return status=" + statusCode); } Header h = method.getResponseHeader("Content-Description"); if ((h != null) && (h.getValue() != null)) { String v = h.getValue(); if (v.equalsIgnoreCase("ncstream")) return ServiceType.CdmRemote; } } return null; }
static private ServiceType checkIfDap4(String location) throws IOException { // Strip off any trailing DAP4 prefix if (location.endsWith(".dap")) location = location.substring(0, location.length() - ".dap".length()); else if (location.endsWith(".dmr")) location = location.substring(0, location.length() - ".dmr".length()); else if (location.endsWith(".dmr.xml")) location = location.substring(0, location.length() - ".dmr.xml".length()); else if (location.endsWith(".dsr")) location = location.substring(0, location.length() - ".dsr".length()); try (HTTPMethod method = HTTPFactory.Get(location + ".dmr.xml")) { int status = method.execute(); if (status == 200) { Header h = method.getResponseHeader("Content-Type"); if ((h != null) && (h.getValue() != null)) { String v = h.getValue(); if (v.startsWith("application/vnd.opendap.org")) return ServiceType.DAP4; } } if (status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_FORBIDDEN) throw new IOException("Unauthorized to open dataset " + location); // not dods return null; } }
Header h = method.getResponseHeader("Content-Description"); if ((h != null) && (h.getValue() != null)) { String v = h.getValue();
static private ServiceType checkIfDap4(String location) throws IOException { HTTPMethod method = null; // Strip off any trailing DAP4 prefix if (location.endsWith(".dap")) location = location.substring(0, location.length() - ".dap".length()); else if (location.endsWith(".dmr")) location = location.substring(0, location.length() - ".dmr".length()); else if (location.endsWith(".dsr")) location = location.substring(0, location.length() - ".dsr".length()); try { method = HTTPFactory.Get(location + ".dmr"); int status = method.execute(); if (status == 200) { Header h = method.getResponseHeader("Content-Type"); if ((h != null) && (h.getValue() != null)) { String v = h.getValue(); if (v.startsWith("application/vnd.opendap.org")) return ServiceType.DAP4; } } if (status == 401) throw new IOException("Unauthorized to open dataset " + location); // not dods return null; } finally { if (method != null) method.close(); } }
Header h = method.getResponseHeader("XDAP"); if (h != null) { versionString = h.getValue(); h = method.getResponseHeader("XDODS-Server"); if (h != null) { versionString = h.getValue();
Header h = method.getResponseHeader("Content-Description"); if ((h != null) && (h.getValue() != null)) { String v = h.getValue();
private boolean rangeOk(String url) { try { try (HTTPMethod method = HTTPFactory.Get(session, url)) { method.setRange(0,0); doConnect(method); int code = method.getStatusCode(); if(code != 206) throw new IOException("Server does not support Range requests, code= " + code); Header head = method.getResponseHeader("Content-Range"); total_length = Long.parseLong(head.getValue().substring(head.getValue().lastIndexOf("/") + 1)); // clear stream method.close(); return true; } } catch (IOException e) { return false; } }
Header head = method.getResponseHeader("Accept-Ranges"); if (head == null) { needtest = true; // header is optional - need more testing head = method.getResponseHeader("Content-Length"); if (head == null) { throw new IOException("Server does not support Content-Length");
Header head = method.getResponseHeader("Accept-Ranges"); if (head == null) { needtest = true; // header is optional - need more testing head = method.getResponseHeader("Content-Length"); if (head == null) { throw new IOException("Server does not support Content-Length");
private boolean rangeOk(String url) { HTTPMethod method = null; try { method = HTTPFactory.Get(session,url); method.setRequestHeader("Range", "bytes=" + 0 + "-" + 0); doConnect(method); int code = method.getStatusCode(); if (code != 206) throw new IOException("Server does not support Range requests, code= " + code); Header head = method.getResponseHeader("Content-Range"); total_length=Long.parseLong(head.getValue().substring(head.getValue().lastIndexOf("/")+1)); // clear stream method.close(); return true; } catch (IOException e) { return false; } finally { if (method != null) method.close(); } }
throw new IOException(location + " is not a valid URL, return status=" + statusCode); Header h = method.getResponseHeader("Content-Description"); if ((h != null) && (h.getValue() != null)) { String v = h.getValue();
throw new IOException("Server does not support Range requests, code= " + code); String s = method.getResponseHeader("Content-Length").getValue(); if (s == null) throw new IOException("Server does not send Content-Length header");
Header h = method.getResponseHeader("Content-Length"); if (h != null) { String s = h.getValue();
throw new IOException("Server does not support Range requests, code= " + code); String s = method.getResponseHeader("Content-Length").getValue(); if (s == null) throw new IOException("Server does not send Content-Length header");
throw new IOException(method.getPath() + " " + method.getStatusLine()); Header h = method.getResponseHeader("Content-Length"); if (h != null) { String s = h.getValue();
public int callserver(HTTPMethod method) throws IOException { int code = 0; // Make method call method.execute(); if(DEBUGPARTS) { RequestConfig rc = method.getDebugConfig(); HttpRequestBase hrb = method.debugRequest(); Assert.assertTrue("Could not get request config", rc != null); reportRequest(rc, hrb); } code = method.getStatusCode(); org.apache.http.Header h = method.getResponseHeader(STATUSCODEHEADER); if(h != null) { String scode = h.getValue(); try { int tmpcode = Integer.parseInt(scode); if(tmpcode > 0) code = tmpcode; } catch (NumberFormatException e) { code = code; // ignore } } return code; }
Header header = method.getResponseHeader(ContentType.HEADER); Assert.assertEquals(expectContentType.getContentHeader().toLowerCase(), header.getValue().toLowerCase());
public static void saveContentToFile(String endpoint, int expectCode, ContentType expectContentType, File saveTo) { logger.debug("req = '{}'", endpoint); try (HTTPSession session = HTTPFactory.newSession(endpoint)) { HTTPMethod method = HTTPFactory.Get(session); int statusCode = method.execute(); if (statusCode != 200) { logger.warn("statusCode = {} '{}'", statusCode, method.getResponseAsString()); Assert.assertEquals(expectCode, statusCode); return; } Assert.assertEquals(expectCode, statusCode); if (expectContentType != null) { Header header = method.getResponseHeader(ContentType.HEADER); Assert.assertEquals(expectContentType.getContentHeader(), header.getValue()); } InputStream content = method.getResponseAsStream(); // closing method may close stream ?? IO.appendToFile(content, saveTo.getAbsolutePath()); } catch (Exception e) { logger.error("Problem with HTTP request", e); assert false; } } }