User Tools
Writing /app/www/public/data/meta/development/snmp/http-library.meta failed
development:snmp:http-library
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| development:snmp:http-library [2019/04/12 17:36] – adsilva | development:snmp:http-library [2021/06/25 10:09] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== HTTP Library ====== | ||
| + | --- // | ||
| + | |||
| + | The JavaHttpClient is a wrapper library developed as a part of R&D (in April 2019 IDMS-3748) so as to provide a HTTP client for our aging SnmpManager as it wasn't practical to upgrade the existing libraries. | ||
| + | |||
| + | The JavaHttpClient was created to deal with the following primary challenges: | ||
| + | - Allow connecting to web servers with bad SSL | ||
| + | - Allow to connect(using curl fallback) to newer SSL ciphers/ | ||
| + | - Allow to post/ | ||
| + | - Support reading and writing raw header information. | ||
| + | |||
| + | |||
| + | Example usage: | ||
| + | |||
| + | |||
| + | |||
| + | <code groovy> | ||
| + | import | ||
| + | |||
| + | String url = "" | ||
| + | String body =""" | ||
| + | CustomHttpResponse chr = null | ||
| + | CustomHttpClient client = new JavaHttpClient() | ||
| + | url = ' | ||
| + | log.info "url: "+url | ||
| + | chr = client.get(url, | ||
| + | log.info chr.dump() | ||
| + | assert chr.success == true | ||
| + | |||
| + | url = ' | ||
| + | log.info "url: "+url | ||
| + | chr = client.options(url, | ||
| + | log.info chr.dump() | ||
| + | assert chr.success == true | ||
| + | |||
| + | //head not testable | ||
| + | |||
| + | url = ' | ||
| + | log.info "url: "+url | ||
| + | chr = client.delete(url, | ||
| + | log.info chr.dump() | ||
| + | assert chr.success == true | ||
| + | |||
| + | url = ' | ||
| + | log.info "url: "+url | ||
| + | chr = client.post(url, | ||
| + | log.info chr.dump() | ||
| + | assert chr.success == true | ||
| + | |||
| + | url = ' | ||
| + | log.info "url: "+url | ||
| + | chr = client.put(url, | ||
| + | log.info chr.dump() | ||
| + | assert chr.success == true | ||
| + | |||
| + | url = ' | ||
| + | log.info "url: "+url | ||
| + | chr = client.patch(url, | ||
| + | log.info chr.dump() | ||
| + | assert chr.success == true | ||
| + | </ | ||
| + | |||
| + | JavaHttpClient falls to CurlHttpClient if it is unable to process due to SSL specific exceptions. | ||
| + | |||
| + | |||
| + | CustomHttpResponse has two convenience methods : | ||
| + | |||
| + | There are some gotchas to remember due to the way RFC allows duplicate HTTP headers keys, | ||
| + | The working is defined in the tests below | ||
| + | |||
| + | 1. getCookie | ||
| + | |||
| + | <code groovy> | ||
| + | |||
| + | void testResponse(){ | ||
| + | CustomHttpResponse customHttpResponse = new CustomHttpResponse() | ||
| + | customHttpResponse.getHeaders().put(" | ||
| + | customHttpResponse.getHeaders().put(" | ||
| + | customHttpResponse.getHeaders().put(" | ||
| + | String cookie = customHttpResponse.getCookie(" | ||
| + | assert cookie == " | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | 2. getHeader | ||
| + | |||
| + | <code groovy> | ||
| + | |||
| + | void testGetHeader(){ | ||
| + | CustomHttpResponse customHttpResponse = new CustomHttpResponse() | ||
| + | customHttpResponse.getHeaders().put(" | ||
| + | customHttpResponse.getHeaders().put(" | ||
| + | customHttpResponse.getHeaders().put(" | ||
| + | assert customHttpResponse.getHeader(" | ||
| + | assert customHttpResponse.getHeader(" | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||