use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.
the class MesaIdDocumentoId2AssinarComSenhaPost method run.
@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
if (!req.sistema.contains(".eproc"))
throw new Exception("Operação disponível apenas para o Eproc");
Usuario u = BalcaojusServlet.getPrincipal();
if (u.usuarios.get(req.sistema) == null)
throw new PresentableUnloggedException("Login inválido para " + Utils.getName(req.sistema));
if (!u.usuario.equalsIgnoreCase(req.username))
throw new PresentableUnloggedException("Login não confere");
if (!u.getSenha().equals(req.password)) {
Random r = new Random();
Thread.sleep(2000 + r.nextInt(2000));
throw new PresentableUnloggedException("Senha não confere");
}
IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost.Request q = new IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost.Request();
Future<SwaggerAsyncResponse<IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost.Response>> future = SwaggerCall.callAsync(getContext(), Utils.getApiEprocPassword(req.sistema), "POST", Utils.getApiEprocUrl(req.sistema) + "/usuario/" + u.usuario + "/mesa/null/documento/" + req.id2 + "/assinar-com-senha", q, IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost.Response.class);
SwaggerAsyncResponse<IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost.Response> sar = future.get();
if (sar.getException() != null)
throw sar.getException();
IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost.Response r = (IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost.Response) sar.getResp();
resp.status = r.status;
resp.mensagem = r.errormsg;
}
use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.
the class MesaIdDocumentoId2SalvarPost method run.
@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
if (!req.sistema.contains(".eproc"))
throw new Exception("Operação disponível apenas para o Eproc");
Usuario u = BalcaojusServlet.getPrincipal();
if (u.usuarios.get(req.sistema) == null)
throw new PresentableUnloggedException("Login inválido para " + Utils.getName(req.sistema));
IUsuarioUsernameMesaIdDocumentoId2SalvarPost.Request q = new IUsuarioUsernameMesaIdDocumentoId2SalvarPost.Request();
q.html = req.html.replace(" ", " ");
q.html = Html2Pdf.cleanHtmlJSoup(q.html, true);
Future<SwaggerAsyncResponse<IUsuarioUsernameMesaIdDocumentoId2SalvarPost.Response>> future = SwaggerCall.callAsync(getContext(), Utils.getApiEprocPassword(req.sistema), "POST", Utils.getApiEprocUrl(req.sistema) + "/usuario/" + u.usuario + "/mesa/null/documento/" + req.id2 + "/salvar", q, IUsuarioUsernameMesaIdDocumentoId2SalvarPost.Response.class);
SwaggerAsyncResponse<IUsuarioUsernameMesaIdDocumentoId2SalvarPost.Response> sar = future.get();
if (sar.getException() != null)
throw sar.getException();
IUsuarioUsernameMesaIdDocumentoId2SalvarPost.Response r = (IUsuarioUsernameMesaIdDocumentoId2SalvarPost.Response) sar.getResp();
resp.status = r.status;
}
use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.
the class CertidaoEmitirRequisitanteCpfcnpjPost method run.
@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
if (!CertidaoObterTokenGet.isValidToken(req.token, null, req.requisitante, req.cpfcnpj))
throw new PresentableException("Token inválido");
FetchResponse r = fetch(Utils.getCertApiUrl(req.sistema) + "/bv_emissao_cert.asp", Utils.getCertApiPassword(req.sistema), "POST", "Botao=Emitir&CPFReq=" + req.requisitante + "&NumDocPess=" + req.cpfcnpj);
if (r.headerFields.containsKey(Utils.ERROR_MESSAGE))
throw new PresentableUnloggedException(r.headerFields.get(Utils.ERROR_MESSAGE).get(0));
if (r.headerFields.containsKey(Utils.RESULT_KIND)) {
resp.tipo = r.headerFields.get(Utils.RESULT_KIND).get(0);
resp.html = Utils.obterHtml(r.html, resp.tipo);
}
if (r.headerFields.containsKey(Utils.CERT_NUMBER))
resp.numero = r.headerFields.get(Utils.CERT_NUMBER).get(0);
if (r.headerFields.containsKey(Utils.NAME))
resp.nome = r.headerFields.get(Utils.NAME).get(0);
if (r.headerFields.containsKey(Utils.QS))
resp.qs = r.headerFields.get(Utils.QS).get(0);
if (r.headerFields.containsKey(Utils.POST_PARAMS))
resp.params = r.headerFields.get(Utils.POST_PARAMS).get(0);
if (!r.headerFields.containsKey(Utils.RESULT_KIND) && resp.html == null) {
resp.tipo = "REQUERER";
resp.numero = req.cpfcnpj;
resp.nome = "Nome não disponível";
resp.html = "Essa certidão não pôde ser emitida de forma automática.\r\n" + "Isto ocorre porque pode haver algum processo vinculado ao requerente,\r\n" + "caso de homonímia, ou outro caso que exija análise para emissão.\r\n" + "Basta clicar no botão abaixo para solicitar o processamento desse pedido\r\n" + "para impressão através de nosso site no prazo de 05 dias úteis.";
}
}
use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.
the class CertidaoEmitirRequisitanteCpfcnpjPost method fetch.
public static FetchResponse fetch(String url, String authorization, String method, String body) throws Exception {
HttpURLConnection con = null;
URL obj = new URL(url);
con = (HttpURLConnection) obj.openConnection();
con.setRequestProperty("User-Agent", "SwaggerServlets");
if (authorization != null)
con.setRequestProperty("Authorization", authorization);
con.setRequestMethod(method);
if ("POST".equals(method)) {
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// set timeout to 5 seconds
con.setConnectTimeout(5000);
// set read timeout to 20 seconds
con.setReadTimeout(20000);
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(body.getBytes(StandardCharsets.UTF_8));
wr.flush();
wr.close();
}
con.setInstanceFollowRedirects(false);
int responseCode = con.getResponseCode();
while (responseCode == 302) {
String newUrl = con.getHeaderField("Location");
String cookies = con.getHeaderField("Set-Cookie");
if (!newUrl.startsWith("http://") && !newUrl.startsWith("https://"))
newUrl = url.substring(0, url.lastIndexOf("/") + 1) + newUrl;
URL obj2 = new URL(newUrl);
con = (HttpURLConnection) obj2.openConnection();
con.setRequestProperty("Cookie", cookies);
con.setRequestProperty("User-Agent", "SwaggerServlets");
if (authorization != null)
con.setRequestProperty("Authorization", authorization);
con.setRequestMethod("GET");
responseCode = con.getResponseCode();
}
if (responseCode >= 400 && responseCode < 600) {
SwaggerError err = null;
InputStream errorStream = null;
String string = null;
errorStream = con.getErrorStream();
if (errorStream != null)
string = convertStreamToString(errorStream);
String errormsg = "HTTP ERROR: " + Integer.toString(responseCode) + " - " + string;
if (con.getResponseMessage() != null)
errormsg = errormsg + " - " + con.getResponseMessage();
errormsg = errormsg.replaceAll("\\s+", " ");
throw new PresentableUnloggedException(errormsg);
}
FetchResponse resp = new FetchResponse();
resp.html = convertStreamToString(con.getInputStream());
resp.headerFields = con.getHeaderFields();
return resp;
}
use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.
the class CertidaoReimprimirNumeroCpfcnpjGet method run.
@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
if (!CertidaoObterTokenGet.isValidToken(req.token, req.numero, null, req.cpfcnpj))
throw new PresentableException("Token inválido");
FetchResponse r = CertidaoEmitirRequisitanteCpfcnpjPost.fetch(Utils.getCertApiUrl(req.sistema) + "/bv_cons_cert_lib.asp", Utils.getCertApiPassword(req.sistema), "POST", "Botao=Emitir&NumProt=" + req.numero + "&NumDocPess=" + req.cpfcnpj);
if (r.headerFields.containsKey(Utils.ERROR_MESSAGE))
throw new PresentableUnloggedException(r.headerFields.get(Utils.ERROR_MESSAGE).get(0));
resp.html = r.html;
if (r.headerFields.containsKey(Utils.RESULT_KIND)) {
resp.tipo = r.headerFields.get(Utils.RESULT_KIND).get(0);
resp.html = Utils.obterHtml(resp.html, resp.tipo);
}
if (r.headerFields.containsKey(Utils.CERT_NUMBER))
resp.numero = r.headerFields.get(Utils.CERT_NUMBER).get(0);
}
Aggregations