static public String getUrlAsString(String url) throws HTTPException { try ( HTTPSession session = HTTPFactory.newSession(url); HTTPMethod m = HTTPFactory.Get(session);) { int status = m.execute(); String content = null; if(status == 200) { content = m.getResponseAsString(); } return content; } }
allFiles.add(location); session = HTTPFactory.newSession(url); method = HTTPFactory.Head(session);
static public HTTPMethod Post(String legalurl) throws HTTPException { return Post(null, legalurl); }
static public HTTPMethod Get(HTTPSession session) throws HTTPException { return Get(session, null); }
@BeforeClass public static void setupCorrect() throws HTTPException { HTTPSession sess = HTTPFactory.newSession(server); session = sess; }
static public HTTPMethod Head(HTTPSession session) throws HTTPException { return Head(session, null); }
static public HTTPMethod Put(String legalurl) throws HTTPException { return Put(null, legalurl); }
static public HTTPMethod Get(String legalurl) throws HTTPException { return Get(null, legalurl); }
_session = HTTPFactory.newSession(this.urlString);
static public HTTPMethod Head(String legalurl) throws HTTPException { return Head(null, legalurl); }
static public HTTPMethod Put(HTTPSession session) throws HTTPException { return Put(session, null); }
public static FeatureType isCdmrfEndpoint(String endpoint) throws IOException { HTTPSession httpClient = HTTPFactory.newSession(endpoint); String url = endpoint + "?req=featureType"; // get the header try (HTTPMethod method = HTTPFactory.Get(httpClient, url)) { method.setFollowRedirects(true); int statusCode = method.execute(); if (statusCode != 200) return null; String content = method.getResponseAsString(); return FeatureType.getType(content); } catch (Throwable t) { t.printStackTrace(); 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; } }
public HTTPMethod(HTTPSession.Methods m, HTTPSession session, String url) throws HTTPException { if(url == null && session != null) url = session.getURL(); try { new URL(url); } catch (MalformedURLException mue) { throw new HTTPException("Malformed URL: " + url, mue); } if(session == null) { session = HTTPFactory.newSession(url); localsession = true; } this.session = session; url = HTTPSession.removeprincipal(url); this.legalurl = url; this.session.addMethod(this); this.methodclass = m; }
allFiles.add(location); session = HTTPFactory.newSession(url); HTTPMethod method = HTTPFactory.Head(session,url)) {
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 public HTTPMethod Post(HTTPSession session) throws HTTPException { return Post(session, null); }
static int putUrlAsString(String content, String url) throws HTTPException { int status = 0; try { try (HTTPMethod m = HTTPFactory.Put(url)) { m.setRequestContent(new StringEntity(content, ContentType.create("application/text", "UTF-8"))); status = m.execute(); } } catch (UnsupportedCharsetException uce) { throw new HTTPException(uce); } return status; }
session = HTTPFactory.newSession(sbuff.toString()); method = HTTPFactory.Get(session); statusCode = method.execute(); } catch (HTTPException he) {
static String getUrlAsString(String url) throws HTTPException { try ( HTTPMethod m = HTTPFactory.Get(url);) { int status = m.execute(); String content = null; if(status == 200) { content = m.getResponseAsString(); } return content; } }