public RawResponse makeDeleteRequest(String endpoint, UrlParameters... urlParams) { String url = prepareUrl(agentAddress + endpoint); url = Utils.generateUrl(url, urlParams); return httpTransport.makeDeleteRequest(url); }
public RawResponse makePutRequest(String endpoint, String content, UrlParameters... urlParams) { String url = prepareUrl(agentAddress + endpoint); url = Utils.generateUrl(url, urlParams); return httpTransport.makePutRequest(url, content); }
public RawResponse makeGetRequest(String endpoint, List<UrlParameters> urlParams) { String url = prepareUrl(agentAddress + endpoint); url = Utils.generateUrl(url, urlParams); return httpTransport.makeGetRequest(url); }
@Test public void testGenerateUrl_Encoded() throws Exception { UrlParameters first = new SingleUrlParameters("key", "value value"); UrlParameters second = new SingleUrlParameters("key2"); UrlParameters third = new SingleUrlParameters("key3", "value!value"); assertEquals("/some-url?key=value+value&key2&key3=value%21value", Utils.generateUrl("/some-url", first, second, third)); }
@Test public void testToUrlParameters() throws Exception { UrlParameters parameters = new SingleUrlParameters("key"); assertEquals(Collections.singletonList("key"), parameters.toUrlParameters()); parameters = new SingleUrlParameters("key", "value"); assertEquals(Collections.singletonList("key=value"), parameters.toUrlParameters()); parameters = new SingleUrlParameters("key", "value value"); assertEquals(Collections.singletonList("key=value+value"), parameters.toUrlParameters()); } }
private void checkUnsignedLongRange(long start, long end) throws Exception { for (long l = start; l < end; l++) { String str = Utils.toUnsignedString(l); long l2 = Utils.parseUnsignedLong(str); assertEquals(l, l2); if (l >= 0) { assertEquals(Long.toString(l), str); assertEquals(l, l2); } } }
private String prepareUrl(String url) { if (url.contains(" ")) { // temp hack for old clients who did manual encoding and just use %20 return Utils.encodeUrl(url); } else { return url; } }
ConsulRawClient(HttpTransport httpTransport, String agentHost, int agentPort, String path) { this.httpTransport = httpTransport; // check that agentHost has scheme or not String agentHostLowercase = agentHost.toLowerCase(); if (!agentHostLowercase.startsWith("https://") && !agentHostLowercase.startsWith("http://")) { // no scheme in host, use default 'http' agentHost = "http://" + agentHost; } this.agentAddress = Utils.assembleAgentAddress(agentHost, agentPort, path); }
public static String generateUrl(String baseUrl, UrlParameters... params) { return generateUrl(baseUrl, Arrays.asList(params)); }
private Long parseUnsignedLong(Header header) { if (header == null) { return null; } String value = header.getValue(); if (value == null) { return null; } try { return Utils.parseUnsignedLong(value); } catch (Exception e) { return null; } }
@Override public List<String> toUrlParameters() { if (value != null) { return Collections.singletonList(key + "=" + Utils.encodeValue(value)); } else { return Collections.singletonList(key); } } }
@Test public void testUnsignedLongParsing() throws Exception { checkUnsignedLongRange(-100, 100); checkUnsignedLongRange(Long.MIN_VALUE, Long.MIN_VALUE + 100); checkUnsignedLongRange(Long.MAX_VALUE - 100, Long.MAX_VALUE); }
public RawResponse makePutRequest(String endpoint, byte[] content, UrlParameters... urlParams) { String url = prepareUrl(agentAddress + endpoint); url = Utils.generateUrl(url, urlParams); return httpTransport.makePutRequest(url, content); }
@Test public void testGenerateUrl_Parametrized() throws Exception { UrlParameters first = new SingleUrlParameters("key", "value"); UrlParameters second = new SingleUrlParameters("key2"); assertEquals("/some-url?key=value&key2", Utils.generateUrl("/some-url", first, second)); }
private String prepareUrl(String url) { if (url.contains(" ")) { // temp hack for old clients who did manual encoding and just use %20 return Utils.encodeUrl(url); } else { return url; } }
ConsulRawClient(HttpTransport httpTransport, String agentHost, int agentPort, String path) { this.httpTransport = httpTransport; // check that agentHost has scheme or not String agentHostLowercase = agentHost.toLowerCase(); if (!agentHostLowercase.startsWith("https://") && !agentHostLowercase.startsWith("http://")) { // no scheme in host, use default 'http' agentHost = "http://" + agentHost; } this.agentAddress = Utils.assembleAgentAddress(agentHost, agentPort, path); }
public static String generateUrl(String baseUrl, UrlParameters... params) { return generateUrl(baseUrl, Arrays.asList(params)); }
private Long parseUnsignedLong(Header header) { if (header == null) { return null; } String value = header.getValue(); if (value == null) { return null; } try { return Utils.parseUnsignedLong(value); } catch (Exception e) { return null; } }
@Override public List<String> toUrlParameters() { if (value != null) { return Collections.singletonList(key + "=" + Utils.encodeValue(value)); } else { return Collections.singletonList(key); } } }
@Test public void testEncodeUrl() throws Exception { String uri = "http://example.com/path with spaces"; String expected = "http://example.com/path%20with%20spaces"; assertEquals(expected, Utils.encodeUrl(uri)); }