public byte[] getResponseAsBytes(int maxbytes) { byte[] contents = getResponseAsBytes(); if(contents != null && contents.length > maxbytes) { byte[] result = new byte[maxbytes]; System.arraycopy(contents, 0, result, 0, maxbytes); contents = result; } return contents; }
public byte[] getResponseAsBytes(int maxbytes) { byte[] contents = getResponseAsBytes(); if(contents.length > maxbytes) { byte[] result = new byte[maxbytes]; System.arraycopy(contents, 0, result, 0, maxbytes); contents = result; } return contents; }
try (HTTPMethod method = HTTPFactory.Get(b.toString())) { code = callserver(method); byte[] bytes = method.getResponseAsBytes(); if(code != 200) { sresult = new String(bytes, "utf8");
return method.getResponseAsBytes();
@Test public void readCapabilities() { String endpoint = TestOnLocalServer.withHttpPath(path + "?" + query); System.out.printf("GetCapabilities req = '%s'%n", endpoint); try (HTTPSession session = HTTPFactory.newSession(endpoint)) { HTTPMethod method = HTTPFactory.Get(session); int statusCode = method.execute(); Assert.assertEquals(200, statusCode); byte[] content = method.getResponseAsBytes(); assert content.length > 1000; System.out.printf("content='%s'%n", new String(content, "UTF-8")); ByteArrayInputStream bin = new ByteArrayInputStream(content); try { SAXBuilder builder = new SAXBuilder(); org.jdom2.Document tdoc = builder.build(bin); org.jdom2.Element root = tdoc.getRootElement(); } catch (Throwable t) { // if fail, go find where it barfs isValidUTF8(content); assert false; } } catch (Exception e) { e.printStackTrace(); assert false; } }
@Test public void testByteRange() { String file = "http://" + TestDir.remoteTestServer + "/thredds/fileServer/scanLocal/testData.nc"; try { try (HTTPMethod m = HTTPFactory.Get(file)) { m.setRange(0, 9); int statusCode = m.execute(); System.err.printf("status = %d%n", statusCode); Assert.assertTrue("Unexpected return code: " + statusCode, statusCode == 206); byte[] result = m.getResponseAsBytes(); Assert.assertTrue("Wrong size result", result.length == 10); } } catch (Exception e) { } }
case 200: byte[] byteresult = m.getResponseAsBytes(); sresult = new String(byteresult, UTF8); break;