From ffd41d35ff9704ab9322ac9bbc0cc95f40b0fc0c Mon Sep 17 00:00:00 2001 From: andre.guimaraes Date: Wed, 25 Apr 2018 10:37:15 -0300 Subject: [PATCH] Corrige testes de conexoes --- .classpath | 2 ++ WebContent/META-INF/MANIFEST.MF | 3 +++ WebContent/WEB-INF/beans.xml | 9 +++++++++ src/main/java/br/gov/ans/integracao/sei/rest/InfoResource.java | 142 ++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------- src/main/resources/messages.properties | 1 + src/main/webapp/api-docs/api_data.js | 97 +++++++++++++++++++++++++++++++------------------------------------------------------------------ src/main/webapp/api-docs/api_data.json | 97 +++++++++++++++++++++++++++++++------------------------------------------------------------------ src/main/webapp/api-docs/api_project.js | 2 +- src/main/webapp/api-docs/api_project.json | 2 +- 9 files changed, 111 insertions(+), 244 deletions(-) create mode 100644 WebContent/META-INF/MANIFEST.MF create mode 100644 WebContent/WEB-INF/beans.xml diff --git a/.classpath b/.classpath index 8893b9e..2905cda 100644 --- a/.classpath +++ b/.classpath @@ -34,5 +34,7 @@ + + diff --git a/WebContent/META-INF/MANIFEST.MF b/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/WebContent/WEB-INF/beans.xml b/WebContent/WEB-INF/beans.xml new file mode 100644 index 0000000..e90e3cc --- /dev/null +++ b/WebContent/WEB-INF/beans.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/br/gov/ans/integracao/sei/rest/InfoResource.java b/src/main/java/br/gov/ans/integracao/sei/rest/InfoResource.java index 6f529e4..bdf0260 100644 --- a/src/main/java/br/gov/ans/integracao/sei/rest/InfoResource.java +++ b/src/main/java/br/gov/ans/integracao/sei/rest/InfoResource.java @@ -19,13 +19,15 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import javax.xml.bind.annotation.XmlRootElement; import org.jboss.logging.Logger; import br.gov.ans.dao.DAO; import br.gov.ans.exceptions.BusinessException; import br.gov.ans.factories.qualifiers.PropertiesInfo; +import br.gov.ans.integracao.sei.client.SeiPortTypeProxy; +import br.gov.ans.integracao.sei.modelo.Operacao; +import br.gov.ans.integracao.sei.utils.Constantes; import br.gov.ans.modelo.LogIntegracaoSistemica; import br.gov.ans.utils.MessageUtils; @@ -42,6 +44,9 @@ public class InfoResource { @Inject private MessageUtils messages; + @Inject + private SeiPortTypeProxy seiNativeService; + @Inject @PropertiesInfo(file="config.properties", key="versao.sistema") public String versao; @@ -77,7 +82,7 @@ public class InfoResource { */ @GET @Path("/versao") - @Produces(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) public String getNumeroVersao(){ return versao; } @@ -104,14 +109,12 @@ public class InfoResource { */ @GET @Path("/conexoes/mysql") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Banco testMySQLConnection() throws Exception{ + @Produces(MediaType.TEXT_PLAIN) + public String testMySQLConnection() throws Exception{ Query query = emMySQL.createNativeQuery("SELECT version()"); - Banco banco = new Banco(); try{ - banco.setVersao((String) query.getSingleResult()); - return banco; + return((String) query.getSingleResult()); }catch(Exception ex){ logger.error(messages.getMessage("erro.testar.mysql")); throw new Exception(messages.getMessage("erro.testar.mysql")); @@ -119,7 +122,7 @@ public class InfoResource { } /** - * @api {get} /info/conexoes/oracle Testar conexão MySQL + * @api {get} /info/conexoes/oracle Testar conexão Oracle * @apiName testOracleConnection * @apiGroup Info * @apiVersion 2.0.0 @@ -140,37 +143,30 @@ public class InfoResource { */ @GET @Path("/conexoes/oracle") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Banco testOracleConnection() throws Exception{ - Query query = emOracle.createNativeQuery("SELECT * FROM V$VERSION WHERE ROWNUM = 1"); - Banco banco = new Banco(); + @Produces(MediaType.TEXT_PLAIN) + public String testOracleConnection() throws Exception{ + Query query = emOracle.createNativeQuery("SELECT BANNER FROM V$VERSION WHERE ROWNUM = 1"); try{ - banco.setVersao((String) query.getSingleResult()); - return banco; + return ((String) query.getSingleResult()); }catch(Exception ex){ logger.error(messages.getMessage("erro.testar.oracle"),ex); throw new Exception(messages.getMessage("erro.testar.oracle")); } } - + /** - * @api {get} /info Informações - * @apiName getInfo + * @api {get} /info/conexoes/sei Testar conexão SEI + * @apiName testSEIConnection * @apiGroup Info * @apiVersion 2.0.0 * - * @apiDescription Retorna informações da aplicação + * @apiDescription Testa a conexão com o SEI fazendo uma consulta ao serviço listar unidades. * * @apiExample {curl} Exemplo de requisição: - * curl -i http:///sei-broker/service/info + * curl -i http:///sei-broker/service/info/conexoes/sei * - * @apiSuccess {Info} info Informações da aplicação. - * @apiSuccess {Banco} info.oracle Informações da conexão Oracle. - * @apiSuccess {String} info.oracle.versao Versão do banco. - * @apiSuccess {Banco} info.mysql Informações da conexão MySQL. - * @apiSuccess {String} info.mysql.versao Versão do banco. - * @apiSuccess {String} info.versao Versão do SEI-Broker. + * @apiSuccess {String} mensagem Mensagem de sucesso. * * @apiErrorExample {json} Error-Response: * HTTP/1.1 500 Internal Server Error @@ -180,15 +176,17 @@ public class InfoResource { * } */ @GET - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Info getInfo() throws Exception{ - Info info = new Info(); - - info.setVersao(getNumeroVersao()); - info.setMySql(testMySQLConnection()); - info.setOracle(testOracleConnection()); - - return info; + @Path("/conexoes/sei") + @Produces(MediaType.TEXT_PLAIN) + public String testSEIConnection() throws Exception{ + try{ + seiNativeService.listarUnidades(Constantes.SEI_BROKER, Operacao.LISTAR_UNIDADES, null, null); + + return "SEI respondeu com sucesso."; + }catch(Exception ex){ + logger.error(messages.getMessage("erro.testar.sei"),ex); + throw new Exception(messages.getMessage("erro.testar.sei")); + } } @SuppressWarnings("unchecked") @@ -202,81 +200,5 @@ public class InfoResource { return query.getResultList(); } - - @GET - @Produces(MediaType.TEXT_HTML) - public String getInfoHTML() throws Exception{ - StringBuilder html = new StringBuilder(); - Info informacoes = getInfo(); - List requests = getUltimosRequests("1", "10"); - - html.append(""); - html.append("SEI-Broker - informações"); - html.append(""); - html.append("

Informações

"); - html.append(""); - html.append(""); - html.append(""); - html.append(""); - html.append("
SEI-Broker"+informacoes.getVersao()+"
Oracle"+informacoes.getOracle().getVersao()+"
MySQL"+informacoes.getMySql().getVersao()+"
"); - html.append("
"); - html.append("

Últimos requests

"); - html.append(""); - - html.append(""); - for(LogIntegracaoSistemica l : requests){ - html.append(""); - } - - html.append("
DATAORIGEMDESTINO
"+l.getData()+""+l.getOrigem()+""+l.getDestino()+"
"); - html.append(""); - html.append(""); - - return html.toString(); - } - - - @XmlRootElement - public static class Banco { - private String versao; - - public String getVersao() { - return versao; - } - - public void setVersao(String versao) { - this.versao = versao; - } - } - - @XmlRootElement - public static class Info { - private String versao; - private Banco oracle; - private Banco mySql; - - public String getVersao() { - return versao; - } - - public void setVersao(String versao) { - this.versao = versao; - } - - public Banco getOracle() { - return oracle; - } - - public void setOracle(Banco oracle) { - this.oracle = oracle; - } - public Banco getMySql() { - return mySql; - } - - public void setMySql(Banco mySql) { - this.mySql = mySql; - } - } } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 6651dca..9ac205b 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -61,6 +61,7 @@ erro.template.documento.recebido = O uso de templates é vedado a documentos gera erro.template.nao.encontrado = Template {0} não encontrado. erro.testar.mysql = Erro ao testar conexao MySQL. erro.testar.oracle = Erro ao testar conexao Oracle. +erro.testar.sei = Erro ao testar conexao com SEI. erro.tipo.documento.nao.encontrado = Nenhum tipo de documento foi encontrado. erro.tipo.pessoa.invalido = Tipo de pessoa inválido. erro.unidade.nao.encontrada = Unidade {0} não encontrada. diff --git a/src/main/webapp/api-docs/api_data.js b/src/main/webapp/api-docs/api_data.js index b8dfb2f..03a2b1e 100644 --- a/src/main/webapp/api-docs/api_data.js +++ b/src/main/webapp/api-docs/api_data.js @@ -1325,8 +1325,8 @@ define({ "api": [ "url": "", "version": "0.0.0", "filename": "sei-broker/src/main/webapp/api-docs/main.js", - "group": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_src_main_webapp_api_docs_main_js", - "groupTitle": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_src_main_webapp_api_docs_main_js", + "group": "C__git_sei_broker_src_main_webapp_api_docs_main_js", + "groupTitle": "C__git_sei_broker_src_main_webapp_api_docs_main_js", "name": "" }, { @@ -1352,9 +1352,9 @@ define({ "api": [ "type": "", "url": "", "version": "0.0.0", - "filename": "sei-broker/target/sei-broker-2.4.2/api-docs/main.js", - "group": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_target_sei_broker_2_4_2_api_docs_main_js", - "groupTitle": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_target_sei_broker_2_4_2_api_docs_main_js", + "filename": "sei-broker/target/sei-broker-2.5/api-docs/main.js", + "group": "C__git_sei_broker_target_sei_broker_2_5_api_docs_main_js", + "groupTitle": "C__git_sei_broker_target_sei_broker_2_5_api_docs_main_js", "name": "" }, { @@ -4893,16 +4893,16 @@ define({ "api": [ }, { "type": "get", - "url": "/info", - "title": "Informações", - "name": "getInfo", + "url": "/info/versao", + "title": "Consultar versão", + "name": "getNumeroVersao", "group": "Info", "version": "2.0.0", - "description": "

Retorna informações da aplicação

", + "description": "

Este método realiza uma consulta para saber a versão do sei-broker que está disponível.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info", + "content": "curl -i http:///sei-broker/service/info/versao", "type": "curl" } ], @@ -4911,45 +4911,10 @@ define({ "api": [ "Success 200": [ { "group": "Success 200", - "type": "Info", - "optional": false, - "field": "info", - "description": "

Informações da aplicação.

" - }, - { - "group": "Success 200", - "type": "Banco", - "optional": false, - "field": "info.oracle", - "description": "

Informações da conexão Oracle.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "info.oracle.versao", - "description": "

Versão do banco.

" - }, - { - "group": "Success 200", - "type": "Banco", - "optional": false, - "field": "info.mysql", - "description": "

Informações da conexão MySQL.

" - }, - { - "group": "Success 200", "type": "String", "optional": false, - "field": "info.mysql.versao", - "description": "

Versão do banco.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "info.versao", - "description": "

Versão do SEI-Broker.

" + "field": "versao", + "description": "

Número da versão.

" } ] } @@ -4968,16 +4933,16 @@ define({ "api": [ }, { "type": "get", - "url": "/info/versao", - "title": "Consultar versão", - "name": "getNumeroVersao", + "url": "/info/conexoes/mysql", + "title": "Testar conexão MySQL", + "name": "testMySQLConnection", "group": "Info", "version": "2.0.0", - "description": "

Este método realiza uma consulta para saber a versão do sei-broker que está disponível.

", + "description": "

Testa a conexão com o MySQL e retorna o número de versão do banco.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info/versao", + "content": "curl -i http:///sei-broker/service/info/conexoes/mysql", "type": "curl" } ], @@ -4989,7 +4954,7 @@ define({ "api": [ "type": "String", "optional": false, "field": "versao", - "description": "

Número da versão.

" + "description": "

Número de versão do MySQL.

" } ] } @@ -5008,16 +4973,16 @@ define({ "api": [ }, { "type": "get", - "url": "/info/conexoes/mysql", - "title": "Testar conexão MySQL", - "name": "testMySQLConnection", + "url": "/info/conexoes/oracle", + "title": "Testar conexão Oracle", + "name": "testOracleConnection", "group": "Info", "version": "2.0.0", - "description": "

Testa a conexão com o MySQL e retorna o número de versão do banco.

", + "description": "

Testa a conexão com o Oracle e retorna o número de versão do banco.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info/conexoes/mysql", + "content": "curl -i http:///sei-broker/service/info/conexoes/oracle", "type": "curl" } ], @@ -5029,7 +4994,7 @@ define({ "api": [ "type": "String", "optional": false, "field": "versao", - "description": "

Número de versão do MySQL.

" + "description": "

Número de versão do Oracle.

" } ] } @@ -5048,16 +5013,16 @@ define({ "api": [ }, { "type": "get", - "url": "/info/conexoes/oracle", - "title": "Testar conexão MySQL", - "name": "testOracleConnection", + "url": "/info/conexoes/sei", + "title": "Testar conexão SEI", + "name": "testSEIConnection", "group": "Info", "version": "2.0.0", - "description": "

Testa a conexão com o Oracle e retorna o número de versão do banco.

", + "description": "

Testa a conexão com o SEI fazendo uma consulta ao serviço listar unidades.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info/conexoes/oracle", + "content": "curl -i http:///sei-broker/service/info/conexoes/sei", "type": "curl" } ], @@ -5068,8 +5033,8 @@ define({ "api": [ "group": "Success 200", "type": "String", "optional": false, - "field": "versao", - "description": "

Número de versão do Oracle.

" + "field": "mensagem", + "description": "

Mensagem de sucesso.

" } ] } diff --git a/src/main/webapp/api-docs/api_data.json b/src/main/webapp/api-docs/api_data.json index 44ec68e..b332f3c 100644 --- a/src/main/webapp/api-docs/api_data.json +++ b/src/main/webapp/api-docs/api_data.json @@ -1325,8 +1325,8 @@ "url": "", "version": "0.0.0", "filename": "sei-broker/src/main/webapp/api-docs/main.js", - "group": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_src_main_webapp_api_docs_main_js", - "groupTitle": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_src_main_webapp_api_docs_main_js", + "group": "C__git_sei_broker_src_main_webapp_api_docs_main_js", + "groupTitle": "C__git_sei_broker_src_main_webapp_api_docs_main_js", "name": "" }, { @@ -1352,9 +1352,9 @@ "type": "", "url": "", "version": "0.0.0", - "filename": "sei-broker/target/sei-broker-2.4.2/api-docs/main.js", - "group": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_target_sei_broker_2_4_2_api_docs_main_js", - "groupTitle": "C__ANS_sei_broker_Fontes_branches_desenvolvimento_versao_3_sei_broker_target_sei_broker_2_4_2_api_docs_main_js", + "filename": "sei-broker/target/sei-broker-2.5/api-docs/main.js", + "group": "C__git_sei_broker_target_sei_broker_2_5_api_docs_main_js", + "groupTitle": "C__git_sei_broker_target_sei_broker_2_5_api_docs_main_js", "name": "" }, { @@ -4893,16 +4893,16 @@ }, { "type": "get", - "url": "/info", - "title": "Informações", - "name": "getInfo", + "url": "/info/versao", + "title": "Consultar versão", + "name": "getNumeroVersao", "group": "Info", "version": "2.0.0", - "description": "

Retorna informações da aplicação

", + "description": "

Este método realiza uma consulta para saber a versão do sei-broker que está disponível.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info", + "content": "curl -i http:///sei-broker/service/info/versao", "type": "curl" } ], @@ -4911,45 +4911,10 @@ "Success 200": [ { "group": "Success 200", - "type": "Info", - "optional": false, - "field": "info", - "description": "

Informações da aplicação.

" - }, - { - "group": "Success 200", - "type": "Banco", - "optional": false, - "field": "info.oracle", - "description": "

Informações da conexão Oracle.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "info.oracle.versao", - "description": "

Versão do banco.

" - }, - { - "group": "Success 200", - "type": "Banco", - "optional": false, - "field": "info.mysql", - "description": "

Informações da conexão MySQL.

" - }, - { - "group": "Success 200", "type": "String", "optional": false, - "field": "info.mysql.versao", - "description": "

Versão do banco.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "info.versao", - "description": "

Versão do SEI-Broker.

" + "field": "versao", + "description": "

Número da versão.

" } ] } @@ -4968,16 +4933,16 @@ }, { "type": "get", - "url": "/info/versao", - "title": "Consultar versão", - "name": "getNumeroVersao", + "url": "/info/conexoes/mysql", + "title": "Testar conexão MySQL", + "name": "testMySQLConnection", "group": "Info", "version": "2.0.0", - "description": "

Este método realiza uma consulta para saber a versão do sei-broker que está disponível.

", + "description": "

Testa a conexão com o MySQL e retorna o número de versão do banco.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info/versao", + "content": "curl -i http:///sei-broker/service/info/conexoes/mysql", "type": "curl" } ], @@ -4989,7 +4954,7 @@ "type": "String", "optional": false, "field": "versao", - "description": "

Número da versão.

" + "description": "

Número de versão do MySQL.

" } ] } @@ -5008,16 +4973,16 @@ }, { "type": "get", - "url": "/info/conexoes/mysql", - "title": "Testar conexão MySQL", - "name": "testMySQLConnection", + "url": "/info/conexoes/oracle", + "title": "Testar conexão Oracle", + "name": "testOracleConnection", "group": "Info", "version": "2.0.0", - "description": "

Testa a conexão com o MySQL e retorna o número de versão do banco.

", + "description": "

Testa a conexão com o Oracle e retorna o número de versão do banco.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info/conexoes/mysql", + "content": "curl -i http:///sei-broker/service/info/conexoes/oracle", "type": "curl" } ], @@ -5029,7 +4994,7 @@ "type": "String", "optional": false, "field": "versao", - "description": "

Número de versão do MySQL.

" + "description": "

Número de versão do Oracle.

" } ] } @@ -5048,16 +5013,16 @@ }, { "type": "get", - "url": "/info/conexoes/oracle", - "title": "Testar conexão MySQL", - "name": "testOracleConnection", + "url": "/info/conexoes/sei", + "title": "Testar conexão SEI", + "name": "testSEIConnection", "group": "Info", "version": "2.0.0", - "description": "

Testa a conexão com o Oracle e retorna o número de versão do banco.

", + "description": "

Testa a conexão com o SEI fazendo uma consulta ao serviço listar unidades.

", "examples": [ { "title": "Exemplo de requisição:", - "content": "curl -i http:///sei-broker/service/info/conexoes/oracle", + "content": "curl -i http:///sei-broker/service/info/conexoes/sei", "type": "curl" } ], @@ -5068,8 +5033,8 @@ "group": "Success 200", "type": "String", "optional": false, - "field": "versao", - "description": "

Número de versão do Oracle.

" + "field": "mensagem", + "description": "

Mensagem de sucesso.

" } ] } diff --git a/src/main/webapp/api-docs/api_project.js b/src/main/webapp/api-docs/api_project.js index b8d26e3..6fc8b96 100644 --- a/src/main/webapp/api-docs/api_project.js +++ b/src/main/webapp/api-docs/api_project.js @@ -8,7 +8,7 @@ define({ "apidoc": "0.2.0", "generator": { "name": "apidoc", - "time": "2018-04-09T12:23:09.782Z", + "time": "2018-04-25T13:34:37.392Z", "url": "http://apidocjs.com", "version": "0.15.1" } diff --git a/src/main/webapp/api-docs/api_project.json b/src/main/webapp/api-docs/api_project.json index 265fff4..b1cd6bc 100644 --- a/src/main/webapp/api-docs/api_project.json +++ b/src/main/webapp/api-docs/api_project.json @@ -8,7 +8,7 @@ "apidoc": "0.2.0", "generator": { "name": "apidoc", - "time": "2018-04-09T12:23:09.782Z", + "time": "2018-04-25T13:34:37.392Z", "url": "http://apidocjs.com", "version": "0.15.1" } -- libgit2 0.21.2