fixes bug#20326
dev: xxx qua: xxx Implementação para enviar a requisição de limpar cache de localidade para várias instancias do serviço api-gateway git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@103389 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
09396374cb
commit
81dd042f1c
|
@ -1,19 +1,12 @@
|
|||
package com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.auth.AuthenticationException;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
|
@ -23,7 +16,6 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.zkoss.zk.ui.util.Clients;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.nimbusds.jose.JOSEException;
|
||||
import com.nimbusds.jose.JWSAlgorithm;
|
||||
import com.nimbusds.jose.JWSHeader;
|
||||
|
@ -52,43 +44,34 @@ public class ItemMenuLimparCacheLocalidadesAPI extends DefaultItemMenuSistema {
|
|||
|
||||
@Override
|
||||
public void ejecutar() {
|
||||
String url = getURLAPI();
|
||||
|
||||
if (StringUtils.isBlank(url)) {
|
||||
Clients.alert(org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.message.naoconfigurado"),
|
||||
org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.title"), Messagebox.INFORMATION);
|
||||
return;
|
||||
String[] urls = getURLSAPI();
|
||||
|
||||
for (String url : urls) {
|
||||
|
||||
if (StringUtils.isBlank(url) || url.contains("|")) {
|
||||
Clients.alert(org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.message.naoconfigurado"),
|
||||
org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.title"), Messagebox.INFORMATION);
|
||||
return;
|
||||
}
|
||||
|
||||
url = montarUrlRequest(url);
|
||||
httpRequestApi(url);
|
||||
}
|
||||
|
||||
String message = "Solicitação de limpeza de cache executada com sucesso, o mesmo já está sendo processado pela API.";
|
||||
Clients.alert(message, org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.title"), Messagebox.INFORMATION);
|
||||
}
|
||||
|
||||
private String montarUrlRequest(String url) {
|
||||
|
||||
url = url.toLowerCase();
|
||||
|
||||
if (!url.endsWith("/")) {
|
||||
url += "/";
|
||||
}
|
||||
|
||||
url = url.concat("adm/limparCache");
|
||||
String message = "Solicitação de limpeza de cache executada com sucesso, o mesmo já está sendo processado pela API.";
|
||||
|
||||
try {
|
||||
httpRequestApi(url);
|
||||
} catch (Exception e) {
|
||||
log.error("Ocorreu um erro ao executar a requisição de limpar cache de localidade da API");
|
||||
}
|
||||
|
||||
Clients.alert(message, org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.title"), Messagebox.INFORMATION);
|
||||
}
|
||||
|
||||
private String obterMensagemResponse(HttpResponse response) throws IOException {
|
||||
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||
|
||||
String line = "";
|
||||
|
||||
StringBuilder result = new StringBuilder("");
|
||||
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
return url.concat("adm/limparCache");
|
||||
}
|
||||
|
||||
private void httpRequestApi(final String url) {
|
||||
|
@ -112,11 +95,10 @@ public class ItemMenuLimparCacheLocalidadesAPI extends DefaultItemMenuSistema {
|
|||
}).start();
|
||||
}
|
||||
|
||||
private String getURLAPI() {
|
||||
private String[] getURLSAPI() {
|
||||
ApplicationContext appContext = AppContext.getApplicationContext();
|
||||
ConstanteService constanteService = (ConstanteService) appContext.getBean("constanteService");
|
||||
|
||||
return constanteService.buscarURLAPI();
|
||||
return constanteService.buscarURLAPI().split("\\|");
|
||||
}
|
||||
|
||||
private String getToken() throws JOSEException {
|
||||
|
|
Loading…
Reference in New Issue