private void checkHeaders(HTTPMethod method) { if(debugHeaders) { DAPNode.log.debug("\nOpenConnection Headers for " + method.getPath()); DAPNode.log.debug("Status Line: " + method.getStatusLine()); } Header[] responseHeaders = method.getResponseHeaders(); for(int i1 = 0; i1 < responseHeaders.length; i1++) { Header responseHeader = responseHeaders[i1]; if(debugHeaders) DAPNode.log.debug(" " + responseHeader); String key = responseHeader.getName(); String value = responseHeader.getValue(); if(key.equals("Last-Modified")) { lastModified = value; if(debugHeaders) DAPNode.log.debug(" **found lastModified = " + lastModified); } else if(key.equals("X-Last-Extended")) { lastExtended = value; if(debugHeaders) DAPNode.log.debug(" **found lastExtended = " + lastExtended); } else if(key.equals("X-Last-Modified-Invalid")) { lastModifiedInvalid = value; if(debugHeaders) DAPNode.log.debug(" **found lastModifiedInvalid = " + lastModifiedInvalid); } } if(debugHeaders) DAPNode.log.debug("OpenConnection Headers for " + method.getPath()); }
public static InputStream sendQuery(HTTPSession session, String remoteURI, String query) throws IOException { long start = System.currentTimeMillis(); StringBuilder sbuff = new StringBuilder(remoteURI); sbuff.append("?"); sbuff.append(query); if (showRequest) System.out.printf(" CdmRemote sendQuery= %s", sbuff); HTTPMethod method = HTTPFactory.Get(session, sbuff.toString()); try { int statusCode = method.execute(); if (statusCode == 404) { throw new FileNotFoundException(method.getPath() + " " + method.getStatusLine()); } else if (statusCode >= 400) { throw new IOException(method.getPath() + " " + method.getStatusLine()); } InputStream stream = method.getResponseBodyAsStream(); if (showRequest) System.out.printf(" took %d msecs %n", System.currentTimeMillis() - start); // Leave the stream open. We must also leave the HTTPMethod open because the two are linked: // calling close() on one object causes the other object to be closed as well. return stream; } catch (IOException e) { // Close the HTTPMethod if there was an exception; otherwise leave it open. method.close(); throw e; } }