Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private JsonStructure executarWS(String url, HttpMethod metodoHTTP, Object parametros) throws GenericException {
- HttpEntity<String> httpEntity = new HttpEntity<>(parametros.toString(), createHeaders());
- // TODO Remover após testes
- SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
- Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.3.28", 8080));
- clientHttpRequestFactory.setProxy(proxy);
- RestTemplate rt = new RestTemplate(clientHttpRequestFactory);
- String strJsonResposta = "";
- try {
- if (HttpMethod.POST.equals(metodoHTTP)) {
- strJsonResposta = rt.postForObject(url, httpEntity, String.class);
- } else if (HttpMethod.GET.equals(metodoHTTP)) {
- strJsonResposta = rt.getForObject(url, String.class);
- }
- } catch (RestClientException e) {
- throw new GenericException("Erro inesperado", e);
- }
- try {
- return Json.createReader(new StringReader(strJsonResposta)).readObject();
- } catch (JsonException e) {
- return Json.createReader(new StringReader(strJsonResposta)).readArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement