Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. private JsonStructure executarWS(String url, HttpMethod metodoHTTP, Object parametros) throws GenericException {
  2.         HttpEntity<String> httpEntity = new HttpEntity<>(parametros.toString(), createHeaders());
  3.  
  4.         // TODO Remover após testes
  5.         SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
  6.         Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.3.28", 8080));
  7.         clientHttpRequestFactory.setProxy(proxy);
  8.  
  9.         RestTemplate rt = new RestTemplate(clientHttpRequestFactory);
  10.  
  11.         String strJsonResposta = "";
  12.  
  13.         try {
  14.             if (HttpMethod.POST.equals(metodoHTTP)) {
  15.                 strJsonResposta = rt.postForObject(url, httpEntity, String.class);
  16.             } else if (HttpMethod.GET.equals(metodoHTTP)) {
  17.                 strJsonResposta = rt.getForObject(url, String.class);
  18.             }
  19.         } catch (RestClientException e) {
  20.             throw new GenericException("Erro inesperado", e);
  21.         }
  22.  
  23.         try {
  24.             return Json.createReader(new StringReader(strJsonResposta)).readObject();
  25.         } catch (JsonException e) {
  26.             return Json.createReader(new StringReader(strJsonResposta)).readArray();
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement