/** * Get CONTENT-TYPE */ public String getContentType() { return getResponseHeader("Content-Type").getValue(); }
/** * Get CONTENT-TYPE */ public String getContentType() { return getResponseHeader("Content-Type").getValue(); }
/** * Return the current date as reported by the Fedora server. * * @throws IOException * if the HTTP Date header is not provided by the server for any * reason, or it is in the wrong format. */ public Date getServerDate() throws IOException { HttpInputStream in = get("/describe", false, false); String dateString = null; try { Header header = in.getResponseHeader("Date"); if (header == null) { throw new IOException("Date was not supplied in HTTP response " + "header for " + m_baseURL + "describe"); } dateString = header.getValue(); // This is the date format recommended by RFC2616 SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.parse(dateString); } catch (ParseException e) { throw new IOException("Unparsable date (" + dateString + ") in HTTP response header for " + m_baseURL + "describe"); } finally { in.close(); } }
@Test public void testAccessParmResolver() throws Exception { String location = "/getAccessParmResolver?PID=fedora-system:ContentModel-3.0&sDefPID=fedora-system:3&methodName=viewObjectProfile"; HttpInputStream result = s_client.get(getBaseURL() + location, false, false); assertEquals(302, result.getStatusCode()); String expected = getBaseURL() + "/get/fedora-system:ContentModel-3.0/fedora-system:3/viewObjectProfile/"; assertEquals(expected, result.getResponseHeader(HttpHeaders.LOCATION).getValue()); } @Test
/** * Ping the given endpoint to see if an HTTP 302 status code is returned. If * so, return the location given in the HTTP response header. If not, return * null. */ private URL getRedirectURL(String location) throws IOException { HttpInputStream in = get(location, false, false); try { if (in.getStatusCode() == 302) { Header h = in.getResponseHeader("location"); if (h != null) { return new URL(h.getValue()); } } return null; } finally { try { in.close(); } catch (Exception e) { } } }
status); Header hLoc = in.getResponseHeader(HttpHeaders.LOCATION); if (hLoc != null) { String location = hLoc.getValue();
while (300 <= status && status <= 399 && count <= wconfig.getMaxRedirects()) { if (in.getResponseHeader(HttpHeaders.LOCATION) == null) { in.close(); throw new IOException("Redirect HTTP response provided no location header."); url = in.getResponseHeader(HttpHeaders.LOCATION).getValue(); in.close(); setHeaders(request, wconfig.getUserAgent(), ifNoneMatch, ifModifiedSince, range);
while (300 <= status && status <= 399 && count <= wconfig.getMaxRedirects()) { if (in.getResponseHeader(HttpHeaders.LOCATION) == null) { in.close(); throw new IOException("Redirect HTTP response provided no location header."); url = in.getResponseHeader(HttpHeaders.LOCATION).getValue(); in.close(); setHeaders(request, wconfig.getUserAgent(), ifNoneMatch, ifModifiedSince, range);