Search in sources :

Example 11 with PresentableUnloggedException

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;
}
Also used : SwaggerAsyncResponse(com.crivano.swaggerservlet.SwaggerAsyncResponse) SwaggerAsyncResponse(com.crivano.swaggerservlet.SwaggerAsyncResponse) Usuario(br.jus.trf2.balcaojus.AutenticarPost.Usuario) Random(java.util.Random) IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost(br.jus.trf2.sistemaprocessual.ISistemaProcessual.IUsuarioUsernameMesaIdDocumentoId2AssinarComSenhaPost) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException)

Example 12 with PresentableUnloggedException

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("&nbsp;", "&#160;");
    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;
}
Also used : SwaggerAsyncResponse(com.crivano.swaggerservlet.SwaggerAsyncResponse) SwaggerAsyncResponse(com.crivano.swaggerservlet.SwaggerAsyncResponse) Usuario(br.jus.trf2.balcaojus.AutenticarPost.Usuario) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) IUsuarioUsernameMesaIdDocumentoId2SalvarPost(br.jus.trf2.sistemaprocessual.ISistemaProcessual.IUsuarioUsernameMesaIdDocumentoId2SalvarPost) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException)

Example 13 with PresentableUnloggedException

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.";
    }
}
Also used : PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) PresentableException(com.crivano.swaggerservlet.PresentableException)

Example 14 with PresentableUnloggedException

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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) SwaggerError(com.crivano.swaggerservlet.SwaggerError) DataOutputStream(java.io.DataOutputStream) InputStream(java.io.InputStream) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) URL(java.net.URL)

Example 15 with PresentableUnloggedException

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);
}
Also used : PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) PresentableException(com.crivano.swaggerservlet.PresentableException) FetchResponse(br.jus.trf2.balcaojus.CertidaoEmitirRequisitanteCpfcnpjPost.FetchResponse)

Aggregations

PresentableUnloggedException (com.crivano.swaggerservlet.PresentableUnloggedException)28 Usuario (br.jus.trf2.balcaojus.AutenticarPost.Usuario)19 UsuarioDetalhe (br.jus.trf2.balcaojus.AutenticarPost.UsuarioDetalhe)8 PresentableException (com.crivano.swaggerservlet.PresentableException)8 SwaggerAsyncResponse (com.crivano.swaggerservlet.SwaggerAsyncResponse)8 Processo (br.jus.trf2.balcaojus.model.Processo)6 Nota (br.jus.trf2.balcaojus.model.Nota)4 FetchResponse (br.jus.trf2.balcaojus.CertidaoEmitirRequisitanteCpfcnpjPost.FetchResponse)3 TipoProcessoJudicial (br.jus.cnj.intercomunicacao_2_2.TipoProcessoJudicial)2 ServicoIntercomunicacao222 (br.jus.cnj.servico_intercomunicacao_2_2.ServicoIntercomunicacao222)2 IUsuarioUsernameMesaIdDocumentoId2SalvarPost (br.jus.trf2.sistemaprocessual.ISistemaProcessual.IUsuarioUsernameMesaIdDocumentoId2SalvarPost)2 JWTVerifyException (com.auth0.jwt.JWTVerifyException)2 IOException (java.io.IOException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 ArrayList (java.util.ArrayList)2 SOAPException (javax.xml.soap.SOAPException)2 TransformerException (javax.xml.transform.TransformerException)2 Holder (javax.xml.ws.Holder)2