public int getResponseStatusCode() { if (method == null) throw new IllegalStateException("Request has not been made."); return this.method.getStatusCode(); }
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; } }
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(); } }
doConnect(method); int code = method.getStatusCode(); if (code != 206) throw new IOException("Server does not support Range requests, code= " + code);
doConnect(method); int code = method.getStatusCode(); if (code != 206) throw new IOException("Server does not support Range requests, code= " + code);
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; }
@Test public void testIllegalRequest() throws IOException, InvalidRangeException { String url = TestOnLocalServer.withHttpPath("/dodsC/scanLocal/testWrite.nc.dds?"); String esc = url + URLEncoder.encode("<bad>\nworse", CDM.UTF8); try (HTTPSession session = HTTPFactory.newSession(esc)) { HTTPMethod method = HTTPFactory.Get(session); method.execute(); Assert.assertEquals(400, method.getStatusCode()); } } }
private HTTPMethod getHttpResponse(URI uri) throws IOException { HTTPMethod method = null; try { method = HTTPFactory.Get(uri.toString()); method.getSession().setConnectionTimeout(this.connectionTimeout); method.getSession().setSoTimeout(this.socketTimeout); method.setFollowRedirects(this.followRedirects); method.setRequestHeader("Accept-Encoding", this.contentEncoding); method.execute(); int statusCode = method.getStatusCode(); if (statusCode == 200 || statusCode == 201) { return method; } method.execute(); return method; } catch (Throwable t) { if (method != null) method.close(); throw t; } } }