Commit 80006b08c7611d36a6b4363b13dc5e3d90bcad60
1 parent
b7fc45c4
Exists in
master
and in
1 other branch
Altera pacote dos handlers
Alteração dos pacotes dos handlers para dar uma assinatura única aos handlers, acredito que haja um conflito com o de outras aplicações.
Showing
66 changed files
with
1096 additions
and
1096 deletions
Show diff stats
src/main/java/br/gov/ans/exceptions/BusinessException.java
... | ... | @@ -1,19 +0,0 @@ |
1 | -package br.gov.ans.exceptions; | |
2 | - | |
3 | -import javax.ejb.ApplicationException; | |
4 | - | |
5 | -@ApplicationException | |
6 | -public class BusinessException extends Exception{ | |
7 | - | |
8 | - private static final long serialVersionUID = 1L; | |
9 | - | |
10 | - private String message; | |
11 | - | |
12 | - public BusinessException(String message){ | |
13 | - this.message = message; | |
14 | - } | |
15 | - | |
16 | - public String getMessage() { | |
17 | - return message; | |
18 | - } | |
19 | -} |
src/main/java/br/gov/ans/exceptions/ErrorMessage.java
... | ... | @@ -1,46 +0,0 @@ |
1 | -package br.gov.ans.exceptions; | |
2 | - | |
3 | -import javax.xml.bind.annotation.XmlRootElement; | |
4 | - | |
5 | -import org.codehaus.jackson.annotate.JsonIgnoreProperties; | |
6 | -import org.codehaus.jackson.map.annotate.JsonSerialize; | |
7 | - | |
8 | -@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) | |
9 | -@JsonIgnoreProperties(ignoreUnknown = true) | |
10 | -@XmlRootElement | |
11 | -public class ErrorMessage { | |
12 | - private String error; | |
13 | - private String code; | |
14 | - | |
15 | - public ErrorMessage(){} | |
16 | - | |
17 | - public ErrorMessage(String error) { | |
18 | - this.error = error; | |
19 | - } | |
20 | - | |
21 | - public ErrorMessage(String error, String code) { | |
22 | - this.error = error; | |
23 | - this.code = code; | |
24 | - } | |
25 | - | |
26 | - public ErrorMessage(String error, int code) { | |
27 | - this.error = error; | |
28 | - this.code = String.valueOf(code); | |
29 | - } | |
30 | - | |
31 | - public String getError() { | |
32 | - return error; | |
33 | - } | |
34 | - | |
35 | - public void setError(String error){ | |
36 | - this.error = error; | |
37 | - } | |
38 | - | |
39 | - public String getCode() { | |
40 | - return code; | |
41 | - } | |
42 | - | |
43 | - public void setCode(String code) { | |
44 | - this.code = code; | |
45 | - } | |
46 | -} |
src/main/java/br/gov/ans/exceptions/ResourceConflictException.java
... | ... | @@ -1,23 +0,0 @@ |
1 | -package br.gov.ans.exceptions; | |
2 | - | |
3 | -import javax.ejb.ApplicationException; | |
4 | - | |
5 | -@ApplicationException | |
6 | -public class ResourceConflictException extends Exception{ | |
7 | - | |
8 | - private static final long serialVersionUID = 1L; | |
9 | - | |
10 | - private String message; | |
11 | - | |
12 | - public ResourceConflictException(String message) { | |
13 | - this.message = message; | |
14 | - } | |
15 | - | |
16 | - public String getMessage() { | |
17 | - return message; | |
18 | - } | |
19 | - | |
20 | - public void setMessage(String message) { | |
21 | - this.message = message; | |
22 | - } | |
23 | -} |
src/main/java/br/gov/ans/exceptions/ResourceNotFoundException.java
... | ... | @@ -1,24 +0,0 @@ |
1 | -package br.gov.ans.exceptions; | |
2 | - | |
3 | -import javax.ejb.ApplicationException; | |
4 | - | |
5 | -@ApplicationException | |
6 | -public class ResourceNotFoundException extends Exception { | |
7 | - | |
8 | - private static final long serialVersionUID = 1L; | |
9 | - | |
10 | - private String message; | |
11 | - | |
12 | - public ResourceNotFoundException(String message) { | |
13 | - this.message = message; | |
14 | - } | |
15 | - | |
16 | - public String getMessage() { | |
17 | - return message; | |
18 | - } | |
19 | - | |
20 | - public void setMessage(String message) { | |
21 | - this.message = message; | |
22 | - } | |
23 | - | |
24 | -} |
src/main/java/br/gov/ans/exceptions/WrappedException.java
... | ... | @@ -1,19 +0,0 @@ |
1 | -package br.gov.ans.exceptions; | |
2 | - | |
3 | -import javax.ejb.ApplicationException; | |
4 | - | |
5 | -@ApplicationException | |
6 | -public class WrappedException extends Exception{ | |
7 | - | |
8 | - private static final long serialVersionUID = 1L; | |
9 | - | |
10 | - private Exception ex; | |
11 | - | |
12 | - public WrappedException(Exception ex){ | |
13 | - this.ex = ex; | |
14 | - } | |
15 | - | |
16 | - public Exception getEx() { | |
17 | - return ex; | |
18 | - } | |
19 | -} |
src/main/java/br/gov/ans/exceptions/handlers/AxisFaultHandler.java
... | ... | @@ -1,57 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import java.net.UnknownHostException; | |
6 | - | |
7 | -import javax.inject.Inject; | |
8 | -import javax.ws.rs.core.Context; | |
9 | -import javax.ws.rs.core.HttpHeaders; | |
10 | -import javax.ws.rs.core.Response; | |
11 | -import javax.ws.rs.core.Response.Status; | |
12 | -import javax.ws.rs.ext.ExceptionMapper; | |
13 | -import javax.ws.rs.ext.Provider; | |
14 | - | |
15 | -import org.apache.axis.AxisFault; | |
16 | -import org.jboss.logging.Logger; | |
17 | -import org.xml.sax.SAXException; | |
18 | - | |
19 | -import br.gov.ans.exceptions.ErrorMessage; | |
20 | - | |
21 | -@Provider | |
22 | -public class AxisFaultHandler implements ExceptionMapper<AxisFault>{ | |
23 | - | |
24 | - @Inject | |
25 | - private Logger logger; | |
26 | - | |
27 | - @Context | |
28 | - private HttpHeaders headers; | |
29 | - | |
30 | - @Inject | |
31 | - private UnknownHostExceptionHandler unknownHostExceptionHandler; | |
32 | - | |
33 | - @Inject | |
34 | - private SAXExceptionHandler sAXExceptionHandler; | |
35 | - | |
36 | - @Override | |
37 | - public Response toResponse(AxisFault ex) { | |
38 | - logger.error(ex); | |
39 | - | |
40 | - logger.debug(ex, ex); | |
41 | - | |
42 | - Throwable cause = ex.getCause(); | |
43 | - | |
44 | - if(cause instanceof UnknownHostException){ | |
45 | - return unknownHostExceptionHandler.toResponse((UnknownHostException) cause); | |
46 | - } | |
47 | - | |
48 | - if(cause instanceof SAXException){ | |
49 | - return sAXExceptionHandler.toResponse((SAXException) cause); | |
50 | - } | |
51 | - | |
52 | - return Response.status(Status.INTERNAL_SERVER_ERROR) | |
53 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
54 | - .type(getAcceptType(headers)) | |
55 | - .build(); | |
56 | - } | |
57 | -} |
src/main/java/br/gov/ans/exceptions/handlers/BusinessExceptionHandler.java
... | ... | @@ -1,37 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.core.Context; | |
7 | -import javax.ws.rs.core.HttpHeaders; | |
8 | -import javax.ws.rs.core.Response; | |
9 | -import javax.ws.rs.core.Response.Status; | |
10 | -import javax.ws.rs.ext.ExceptionMapper; | |
11 | -import javax.ws.rs.ext.Provider; | |
12 | - | |
13 | -import org.jboss.logging.Logger; | |
14 | - | |
15 | -import br.gov.ans.exceptions.BusinessException; | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class BusinessExceptionHandler implements ExceptionMapper<BusinessException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - public Response toResponse(BusinessException ex) { | |
28 | - logger.error(ex); | |
29 | - | |
30 | - logger.debug(ex, ex); | |
31 | - | |
32 | - return Response.status(Status.BAD_REQUEST) | |
33 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.BAD_REQUEST.getStatusCode()))) | |
34 | - .type(getAcceptType(headers)) | |
35 | - .build(); | |
36 | - } | |
37 | -} |
src/main/java/br/gov/ans/exceptions/handlers/EJBAccessExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.ejb.EJBAccessException; | |
6 | -import javax.inject.Inject; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class EJBAccessExceptionHandler implements ExceptionMapper<EJBAccessException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(EJBAccessException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.UNAUTHORIZED) | |
34 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.UNAUTHORIZED.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/EJBExceptionHandler.java
... | ... | @@ -1,42 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.ejb.EJBException; | |
6 | -import javax.inject.Inject; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | -import br.gov.ans.utils.MessageUtils; | |
18 | - | |
19 | -@Provider | |
20 | -public class EJBExceptionHandler implements ExceptionMapper<EJBException>{ | |
21 | - | |
22 | - @Inject | |
23 | - private Logger logger; | |
24 | - | |
25 | - @Context | |
26 | - private HttpHeaders headers; | |
27 | - | |
28 | - @Inject | |
29 | - private MessageUtils messages; | |
30 | - | |
31 | - public Response toResponse(EJBException ex) { | |
32 | - logger.error(ex); | |
33 | - | |
34 | - logger.debug(ex, ex); | |
35 | - | |
36 | - return Response.status(Status.INTERNAL_SERVER_ERROR) | |
37 | - .entity(new ErrorMessage(messages.getMessage("erro.inesperado"),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
38 | - .type(getAcceptType(headers)) | |
39 | - .build(); | |
40 | - } | |
41 | - | |
42 | -} |
src/main/java/br/gov/ans/exceptions/handlers/EJBTransactionRolledbackExceptionHandler.java
... | ... | @@ -1,43 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.ejb.EJBTransactionRolledbackException; | |
6 | -import javax.inject.Inject; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | -import br.gov.ans.utils.MessageUtils; | |
18 | - | |
19 | -@Provider | |
20 | -public class EJBTransactionRolledbackExceptionHandler implements ExceptionMapper<EJBTransactionRolledbackException>{ | |
21 | - | |
22 | - @Inject | |
23 | - private Logger logger; | |
24 | - | |
25 | - @Context | |
26 | - private HttpHeaders headers; | |
27 | - | |
28 | - @Inject | |
29 | - private MessageUtils messages; | |
30 | - | |
31 | - @Override | |
32 | - public Response toResponse(EJBTransactionRolledbackException ex) { | |
33 | - logger.error(ex); | |
34 | - | |
35 | - logger.debug(ex, ex); | |
36 | - | |
37 | - return Response.status(Status.INTERNAL_SERVER_ERROR) | |
38 | - .entity(new ErrorMessage(messages.getMessage("erro.inesperado"),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
39 | - .type(getAcceptType(headers)) | |
40 | - .build(); | |
41 | - } | |
42 | - | |
43 | -} |
src/main/java/br/gov/ans/exceptions/handlers/ExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.core.Context; | |
7 | -import javax.ws.rs.core.HttpHeaders; | |
8 | -import javax.ws.rs.core.Response; | |
9 | -import javax.ws.rs.core.Response.Status; | |
10 | -import javax.ws.rs.ext.ExceptionMapper; | |
11 | -import javax.ws.rs.ext.Provider; | |
12 | - | |
13 | -import org.jboss.logging.Logger; | |
14 | - | |
15 | -import br.gov.ans.exceptions.ErrorMessage; | |
16 | - | |
17 | -@Provider | |
18 | -public class ExceptionHandler implements ExceptionMapper<Exception>{ | |
19 | - | |
20 | - @Inject | |
21 | - private Logger logger; | |
22 | - | |
23 | - @Context | |
24 | - private HttpHeaders headers; | |
25 | - | |
26 | - @Override | |
27 | - public Response toResponse(Exception ex) { | |
28 | - logger.error(ex); | |
29 | - | |
30 | - logger.debug(ex, ex); | |
31 | - | |
32 | - return Response.status(Status.INTERNAL_SERVER_ERROR) | |
33 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
34 | - .type(getAcceptType(headers)) | |
35 | - .build(); | |
36 | - } | |
37 | - | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/ForbiddenExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.ForbiddenException; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class ForbiddenExceptionHandler implements ExceptionMapper<ForbiddenException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(ForbiddenException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.FORBIDDEN) | |
34 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.FORBIDDEN.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/LoginExceptionHandler.java
... | ... | @@ -1,89 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import java.io.IOException; | |
6 | -import java.io.PrintWriter; | |
7 | -import java.io.StringWriter; | |
8 | - | |
9 | -import javax.inject.Inject; | |
10 | -import javax.servlet.ServletException; | |
11 | -import javax.servlet.http.HttpServlet; | |
12 | -import javax.servlet.http.HttpServletRequest; | |
13 | -import javax.servlet.http.HttpServletResponse; | |
14 | -import javax.ws.rs.core.MediaType; | |
15 | -import javax.ws.rs.core.Response.Status; | |
16 | -import javax.xml.bind.JAXB; | |
17 | - | |
18 | -import org.jboss.logging.Logger; | |
19 | - | |
20 | -import com.google.gson.Gson; | |
21 | - | |
22 | -import br.gov.ans.exceptions.ErrorMessage; | |
23 | - | |
24 | -//@WebServlet("/loginExceptionHandler") | |
25 | -public class LoginExceptionHandler extends HttpServlet{ | |
26 | - | |
27 | - private static final long serialVersionUID = 1L; | |
28 | - | |
29 | - @Inject | |
30 | - private Logger logger; | |
31 | - | |
32 | - @Override | |
33 | - protected void doPost(HttpServletRequest req, HttpServletResponse resp) | |
34 | - throws ServletException, IOException { | |
35 | - | |
36 | - String acceptType = getAcceptType(req); | |
37 | - | |
38 | - resp.setContentType(acceptType); | |
39 | - resp.setCharacterEncoding("utf-8"); | |
40 | - | |
41 | - CODE code = CODE.valueOf("_"+req.getParameter("code")); | |
42 | - | |
43 | - ErrorMessage error = new ErrorMessage(code.message, code.status.getStatusCode()); | |
44 | - | |
45 | - logger.error(error.getError()); | |
46 | - | |
47 | - PrintWriter out = resp.getWriter(); | |
48 | - | |
49 | - if(acceptType.equals(MediaType.APPLICATION_JSON)){ | |
50 | - out.write(new Gson().toJson(error)); | |
51 | - }else{ | |
52 | - StringWriter sw = new StringWriter(); | |
53 | - JAXB.marshal(error, sw); | |
54 | - | |
55 | - out.write(sw.toString()); | |
56 | - } | |
57 | - } | |
58 | - | |
59 | - @Override | |
60 | - protected void doGet(HttpServletRequest req, HttpServletResponse resp) | |
61 | - throws ServletException, IOException { | |
62 | - doPost(req, resp); | |
63 | - } | |
64 | - | |
65 | - @Override | |
66 | - protected void doPut(HttpServletRequest req, HttpServletResponse resp) | |
67 | - throws ServletException, IOException { | |
68 | - doPost(req, resp); | |
69 | - } | |
70 | - | |
71 | - @Override | |
72 | - protected void doDelete(HttpServletRequest req, HttpServletResponse resp) | |
73 | - throws ServletException, IOException { | |
74 | - doPost(req, resp); | |
75 | - } | |
76 | - | |
77 | - private enum CODE{ | |
78 | - _401(Status.UNAUTHORIZED, "Cliente não autenticado."), | |
79 | - _403(Status.FORBIDDEN, "Cliente não autorizado."); | |
80 | - | |
81 | - Status status; | |
82 | - String message; | |
83 | - | |
84 | - private CODE(Status restStatus, String message) { | |
85 | - this.status = restStatus; | |
86 | - this.message = message; | |
87 | - } | |
88 | - } | |
89 | -} |
src/main/java/br/gov/ans/exceptions/handlers/NotAcceptableExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.NotAcceptableException; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class NotAcceptableExceptionHandler implements ExceptionMapper<NotAcceptableException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(NotAcceptableException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.NOT_ACCEPTABLE) | |
34 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.NOT_ACCEPTABLE.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/NotAllowedExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.NotAllowedException; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class NotAllowedExceptionHandler implements ExceptionMapper<NotAllowedException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(NotAllowedException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.METHOD_NOT_ALLOWED) | |
34 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.METHOD_NOT_ALLOWED.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/NotAuthorizedExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.NotAuthorizedException; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class NotAuthorizedExceptionHandler implements ExceptionMapper<NotAuthorizedException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(NotAuthorizedException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.UNAUTHORIZED) | |
34 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.UNAUTHORIZED.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/NotFoundExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.NotFoundException; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class NotFoundExceptionHandler implements ExceptionMapper<NotFoundException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(NotFoundException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.NOT_FOUND) | |
34 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.NOT_FOUND.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/PersistenceExceptionHandler.java
... | ... | @@ -1,42 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.persistence.PersistenceException; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | -import br.gov.ans.utils.MessageUtils; | |
18 | - | |
19 | -@Provider | |
20 | -public class PersistenceExceptionHandler implements ExceptionMapper<PersistenceException>{ | |
21 | - | |
22 | - @Inject | |
23 | - private Logger logger; | |
24 | - | |
25 | - @Context | |
26 | - private HttpHeaders headers; | |
27 | - | |
28 | - @Inject | |
29 | - private MessageUtils messages; | |
30 | - | |
31 | - public Response toResponse(PersistenceException ex) { | |
32 | - logger.error(ex); | |
33 | - | |
34 | - logger.debug(ex, ex); | |
35 | - | |
36 | - return Response.status(Status.INTERNAL_SERVER_ERROR) | |
37 | - .entity(new ErrorMessage(messages.getMessage("erro.inesperado"),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
38 | - .type(getAcceptType(headers)) | |
39 | - .build(); | |
40 | - } | |
41 | - | |
42 | -} |
src/main/java/br/gov/ans/exceptions/handlers/ResourceConflictExceptionHandler.java
... | ... | @@ -1,37 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.core.Context; | |
7 | -import javax.ws.rs.core.HttpHeaders; | |
8 | -import javax.ws.rs.core.Response; | |
9 | -import javax.ws.rs.core.Response.Status; | |
10 | -import javax.ws.rs.ext.ExceptionMapper; | |
11 | -import javax.ws.rs.ext.Provider; | |
12 | - | |
13 | -import org.jboss.logging.Logger; | |
14 | - | |
15 | -import br.gov.ans.exceptions.ErrorMessage; | |
16 | -import br.gov.ans.exceptions.ResourceConflictException; | |
17 | - | |
18 | -@Provider | |
19 | -public class ResourceConflictExceptionHandler implements ExceptionMapper<ResourceConflictException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - public Response toResponse(ResourceConflictException ex) { | |
28 | - logger.error(ex); | |
29 | - | |
30 | - logger.debug(ex, ex); | |
31 | - | |
32 | - return Response.status(Status.CONFLICT) | |
33 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.CONFLICT.getStatusCode()))) | |
34 | - .type(getAcceptType(headers)) | |
35 | - .build(); | |
36 | - } | |
37 | -} |
src/main/java/br/gov/ans/exceptions/handlers/ResourceNotFoundExceptionHandler.java
... | ... | @@ -1,37 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.core.Context; | |
7 | -import javax.ws.rs.core.HttpHeaders; | |
8 | -import javax.ws.rs.core.Response; | |
9 | -import javax.ws.rs.core.Response.Status; | |
10 | -import javax.ws.rs.ext.ExceptionMapper; | |
11 | -import javax.ws.rs.ext.Provider; | |
12 | - | |
13 | -import org.jboss.logging.Logger; | |
14 | - | |
15 | -import br.gov.ans.exceptions.ErrorMessage; | |
16 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
17 | - | |
18 | -@Provider | |
19 | -public class ResourceNotFoundExceptionHandler implements ExceptionMapper<ResourceNotFoundException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - public Response toResponse(ResourceNotFoundException ex) { | |
28 | - logger.error(ex); | |
29 | - | |
30 | - logger.debug(ex, ex); | |
31 | - | |
32 | - return Response.status(Status.NOT_FOUND) | |
33 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.NOT_FOUND.getStatusCode()))) | |
34 | - .type(getAcceptType(headers)) | |
35 | - .build(); | |
36 | - } | |
37 | -} |
src/main/java/br/gov/ans/exceptions/handlers/SAXExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.core.Context; | |
7 | -import javax.ws.rs.core.HttpHeaders; | |
8 | -import javax.ws.rs.core.Response; | |
9 | -import javax.ws.rs.core.Response.Status; | |
10 | -import javax.ws.rs.ext.ExceptionMapper; | |
11 | -import javax.ws.rs.ext.Provider; | |
12 | - | |
13 | -import org.jboss.logging.Logger; | |
14 | -import org.xml.sax.SAXException; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class SAXExceptionHandler implements ExceptionMapper<SAXException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(SAXException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.INTERNAL_SERVER_ERROR) | |
34 | - .entity(new ErrorMessage("Não foi possível se conectar ao SEI.",String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/UnknownHostExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import java.net.UnknownHostException; | |
6 | - | |
7 | -import javax.inject.Inject; | |
8 | -import javax.ws.rs.core.Context; | |
9 | -import javax.ws.rs.core.HttpHeaders; | |
10 | -import javax.ws.rs.core.Response; | |
11 | -import javax.ws.rs.core.Response.Status; | |
12 | -import javax.ws.rs.ext.ExceptionMapper; | |
13 | -import javax.ws.rs.ext.Provider; | |
14 | - | |
15 | -import org.jboss.logging.Logger; | |
16 | - | |
17 | -import br.gov.ans.exceptions.ErrorMessage; | |
18 | - | |
19 | -@Provider | |
20 | -public class UnknownHostExceptionHandler implements ExceptionMapper<UnknownHostException>{ | |
21 | - | |
22 | - @Inject | |
23 | - private Logger logger; | |
24 | - | |
25 | - @Context | |
26 | - private HttpHeaders headers; | |
27 | - | |
28 | - public Response toResponse(UnknownHostException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.BAD_GATEWAY) | |
34 | - .entity(new ErrorMessage("Não foi possível se conectar ao SEI.",String.valueOf(Status.BAD_GATEWAY.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/WebApplicationExceptionHandler.java
... | ... | @@ -1,38 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.WebApplicationException; | |
7 | -import javax.ws.rs.core.Context; | |
8 | -import javax.ws.rs.core.HttpHeaders; | |
9 | -import javax.ws.rs.core.Response; | |
10 | -import javax.ws.rs.core.Response.Status; | |
11 | -import javax.ws.rs.ext.ExceptionMapper; | |
12 | -import javax.ws.rs.ext.Provider; | |
13 | - | |
14 | -import org.jboss.logging.Logger; | |
15 | - | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | - | |
18 | -@Provider | |
19 | -public class WebApplicationExceptionHandler implements ExceptionMapper<WebApplicationException>{ | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Context | |
25 | - private HttpHeaders headers; | |
26 | - | |
27 | - @Override | |
28 | - public Response toResponse(WebApplicationException ex) { | |
29 | - logger.error(ex); | |
30 | - | |
31 | - logger.debug(ex, ex); | |
32 | - | |
33 | - return Response.status(Status.INTERNAL_SERVER_ERROR) | |
34 | - .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
35 | - .type(getAcceptType(headers)) | |
36 | - .build(); | |
37 | - } | |
38 | -} |
src/main/java/br/gov/ans/exceptions/handlers/WrappedExceptionHandler.java
... | ... | @@ -1,46 +0,0 @@ |
1 | -package br.gov.ans.exceptions.handlers; | |
2 | - | |
3 | -import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.ws.rs.core.Context; | |
7 | -import javax.ws.rs.core.HttpHeaders; | |
8 | -import javax.ws.rs.core.Response; | |
9 | -import javax.ws.rs.core.Response.Status; | |
10 | -import javax.ws.rs.ext.ExceptionMapper; | |
11 | -import javax.ws.rs.ext.Provider; | |
12 | - | |
13 | -import org.jboss.logging.Logger; | |
14 | - | |
15 | -import br.gov.ans.exceptions.BusinessException; | |
16 | -import br.gov.ans.exceptions.ErrorMessage; | |
17 | -import br.gov.ans.exceptions.WrappedException; | |
18 | - | |
19 | -@Provider | |
20 | -public class WrappedExceptionHandler implements ExceptionMapper<WrappedException>{ | |
21 | - | |
22 | - @Inject | |
23 | - private Logger logger; | |
24 | - | |
25 | - @Context | |
26 | - private HttpHeaders headers; | |
27 | - | |
28 | - @Override | |
29 | - public Response toResponse(WrappedException ex) { | |
30 | - logger.error(ex.getEx()); | |
31 | - | |
32 | - logger.debug(ex.getEx(), ex.getEx()); | |
33 | - | |
34 | - Status status = Status.INTERNAL_SERVER_ERROR; | |
35 | - | |
36 | - if(ex.getEx() instanceof BusinessException){ | |
37 | - status = Status.BAD_REQUEST; | |
38 | - } | |
39 | - | |
40 | - return Response.status(status) | |
41 | - .entity(new ErrorMessage(ex.getEx().getMessage(),String.valueOf(status.getStatusCode()))) | |
42 | - .type(getAcceptType(headers)) | |
43 | - .build(); | |
44 | - } | |
45 | - | |
46 | -} |
src/main/java/br/gov/ans/filters/LogRequestFilter.java
... | ... | @@ -1,82 +0,0 @@ |
1 | -package br.gov.ans.filters; | |
2 | - | |
3 | -import java.io.IOException; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.servlet.http.HttpServletRequest; | |
7 | -import javax.ws.rs.container.ContainerRequestContext; | |
8 | -import javax.ws.rs.container.ContainerRequestFilter; | |
9 | -import javax.ws.rs.container.ResourceInfo; | |
10 | -import javax.ws.rs.core.Context; | |
11 | -import javax.ws.rs.core.SecurityContext; | |
12 | -import javax.ws.rs.core.UriInfo; | |
13 | -import javax.ws.rs.ext.Provider; | |
14 | - | |
15 | -import org.jboss.logging.Logger; | |
16 | -import org.jboss.resteasy.core.ResourceMethodInvoker; | |
17 | - | |
18 | -import br.gov.ans.integracao.sei.utils.Constantes; | |
19 | -import br.gov.ans.utils.LogIgnore; | |
20 | -import br.gov.ans.utils.LogIntegracaoUtil; | |
21 | -import br.gov.ans.utils.MessageUtils; | |
22 | - | |
23 | -@Provider | |
24 | -public class LogRequestFilter implements ContainerRequestFilter{ | |
25 | - | |
26 | - @Inject | |
27 | - private LogIntegracaoUtil audit; | |
28 | - | |
29 | - @Inject | |
30 | - private MessageUtils messages; | |
31 | - | |
32 | - @Context | |
33 | - private UriInfo uriInfo; | |
34 | - | |
35 | - @Context | |
36 | - private ResourceInfo resourceInfo; | |
37 | - | |
38 | - @Context | |
39 | - private HttpServletRequest request; | |
40 | - | |
41 | - @Context | |
42 | - private SecurityContext securityContext; | |
43 | - | |
44 | - @Inject | |
45 | - private Logger logger; | |
46 | - | |
47 | - @Override | |
48 | - public void filter(ContainerRequestContext context) throws IOException{ | |
49 | - request.setCharacterEncoding(Constantes.UTF8); | |
50 | - | |
51 | - if(isLoggable()){ | |
52 | - audit.registrarLog(getUserName(),uriInfo.getAbsolutePath().toString(), getMethodName(context)); | |
53 | - } | |
54 | - } | |
55 | - | |
56 | - public String getMethodName(ContainerRequestContext context){ | |
57 | - ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) context.getProperty(Constantes.RESOURCE_METHOD_INVOKER); | |
58 | - | |
59 | - return methodInvoker.getMethod().getName(); | |
60 | - } | |
61 | - | |
62 | - public String getUserName(){ | |
63 | - try{ | |
64 | - return securityContext.getUserPrincipal().getName(); | |
65 | - }catch (Exception ex) { | |
66 | - logger.debug("Sem informações do usuário logado: ", ex); | |
67 | - return messages.getMessage("sem.informacoes.usuario"); | |
68 | - } | |
69 | - } | |
70 | - | |
71 | - private boolean isLoggable(){ | |
72 | - if(resourceInfo.getResourceClass().isAnnotationPresent(LogIgnore.class)){ | |
73 | - return false; | |
74 | - } | |
75 | - | |
76 | - if(resourceInfo.getResourceMethod().isAnnotationPresent(LogIgnore.class)){ | |
77 | - return false; | |
78 | - } | |
79 | - | |
80 | - return true; | |
81 | - } | |
82 | -} |
src/main/java/br/gov/ans/filters/SessionInvalidateFilter.java
... | ... | @@ -1,33 +0,0 @@ |
1 | -package br.gov.ans.filters; | |
2 | - | |
3 | -import java.io.IOException; | |
4 | - | |
5 | -import javax.inject.Inject; | |
6 | -import javax.servlet.http.HttpServletRequest; | |
7 | -import javax.ws.rs.container.ContainerRequestContext; | |
8 | -import javax.ws.rs.container.ContainerResponseContext; | |
9 | -import javax.ws.rs.container.ContainerResponseFilter; | |
10 | -import javax.ws.rs.core.Context; | |
11 | -import javax.ws.rs.ext.Provider; | |
12 | - | |
13 | -import org.jboss.logging.Logger; | |
14 | - | |
15 | -@Provider | |
16 | -public class SessionInvalidateFilter implements ContainerResponseFilter{ | |
17 | - | |
18 | - @Context | |
19 | - private HttpServletRequest request; | |
20 | - | |
21 | - @Inject | |
22 | - private Logger logger; | |
23 | - | |
24 | - @Override | |
25 | - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | |
26 | - throws IOException { | |
27 | - try{ | |
28 | - request.getSession().invalidate(); | |
29 | - }catch(Exception ex){ | |
30 | - logger.error(ex); | |
31 | - } | |
32 | - } | |
33 | -} |
src/main/java/br/gov/ans/integracao/sei/exceptions/BusinessException.java
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions; | |
2 | + | |
3 | +import javax.ejb.ApplicationException; | |
4 | + | |
5 | +@ApplicationException | |
6 | +public class BusinessException extends Exception{ | |
7 | + | |
8 | + private static final long serialVersionUID = 1L; | |
9 | + | |
10 | + private String message; | |
11 | + | |
12 | + public BusinessException(String message){ | |
13 | + this.message = message; | |
14 | + } | |
15 | + | |
16 | + public String getMessage() { | |
17 | + return message; | |
18 | + } | |
19 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/ErrorMessage.java
0 → 100644
... | ... | @@ -0,0 +1,46 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions; | |
2 | + | |
3 | +import javax.xml.bind.annotation.XmlRootElement; | |
4 | + | |
5 | +import org.codehaus.jackson.annotate.JsonIgnoreProperties; | |
6 | +import org.codehaus.jackson.map.annotate.JsonSerialize; | |
7 | + | |
8 | +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) | |
9 | +@JsonIgnoreProperties(ignoreUnknown = true) | |
10 | +@XmlRootElement | |
11 | +public class ErrorMessage { | |
12 | + private String error; | |
13 | + private String code; | |
14 | + | |
15 | + public ErrorMessage(){} | |
16 | + | |
17 | + public ErrorMessage(String error) { | |
18 | + this.error = error; | |
19 | + } | |
20 | + | |
21 | + public ErrorMessage(String error, String code) { | |
22 | + this.error = error; | |
23 | + this.code = code; | |
24 | + } | |
25 | + | |
26 | + public ErrorMessage(String error, int code) { | |
27 | + this.error = error; | |
28 | + this.code = String.valueOf(code); | |
29 | + } | |
30 | + | |
31 | + public String getError() { | |
32 | + return error; | |
33 | + } | |
34 | + | |
35 | + public void setError(String error){ | |
36 | + this.error = error; | |
37 | + } | |
38 | + | |
39 | + public String getCode() { | |
40 | + return code; | |
41 | + } | |
42 | + | |
43 | + public void setCode(String code) { | |
44 | + this.code = code; | |
45 | + } | |
46 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/ResourceConflictException.java
0 → 100644
... | ... | @@ -0,0 +1,23 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions; | |
2 | + | |
3 | +import javax.ejb.ApplicationException; | |
4 | + | |
5 | +@ApplicationException | |
6 | +public class ResourceConflictException extends Exception{ | |
7 | + | |
8 | + private static final long serialVersionUID = 1L; | |
9 | + | |
10 | + private String message; | |
11 | + | |
12 | + public ResourceConflictException(String message) { | |
13 | + this.message = message; | |
14 | + } | |
15 | + | |
16 | + public String getMessage() { | |
17 | + return message; | |
18 | + } | |
19 | + | |
20 | + public void setMessage(String message) { | |
21 | + this.message = message; | |
22 | + } | |
23 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/ResourceNotFoundException.java
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions; | |
2 | + | |
3 | +import javax.ejb.ApplicationException; | |
4 | + | |
5 | +@ApplicationException | |
6 | +public class ResourceNotFoundException extends Exception { | |
7 | + | |
8 | + private static final long serialVersionUID = 1L; | |
9 | + | |
10 | + private String message; | |
11 | + | |
12 | + public ResourceNotFoundException(String message) { | |
13 | + this.message = message; | |
14 | + } | |
15 | + | |
16 | + public String getMessage() { | |
17 | + return message; | |
18 | + } | |
19 | + | |
20 | + public void setMessage(String message) { | |
21 | + this.message = message; | |
22 | + } | |
23 | + | |
24 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/WrappedException.java
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions; | |
2 | + | |
3 | +import javax.ejb.ApplicationException; | |
4 | + | |
5 | +@ApplicationException | |
6 | +public class WrappedException extends Exception{ | |
7 | + | |
8 | + private static final long serialVersionUID = 1L; | |
9 | + | |
10 | + private Exception ex; | |
11 | + | |
12 | + public WrappedException(Exception ex){ | |
13 | + this.ex = ex; | |
14 | + } | |
15 | + | |
16 | + public Exception getEx() { | |
17 | + return ex; | |
18 | + } | |
19 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/AxisFaultHandler.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import java.net.UnknownHostException; | |
6 | + | |
7 | +import javax.inject.Inject; | |
8 | +import javax.ws.rs.core.Context; | |
9 | +import javax.ws.rs.core.HttpHeaders; | |
10 | +import javax.ws.rs.core.Response; | |
11 | +import javax.ws.rs.core.Response.Status; | |
12 | +import javax.ws.rs.ext.ExceptionMapper; | |
13 | +import javax.ws.rs.ext.Provider; | |
14 | + | |
15 | +import org.apache.axis.AxisFault; | |
16 | +import org.jboss.logging.Logger; | |
17 | +import org.xml.sax.SAXException; | |
18 | + | |
19 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
20 | + | |
21 | +@Provider | |
22 | +public class AxisFaultHandler implements ExceptionMapper<AxisFault>{ | |
23 | + | |
24 | + @Inject | |
25 | + private Logger logger; | |
26 | + | |
27 | + @Context | |
28 | + private HttpHeaders headers; | |
29 | + | |
30 | + @Inject | |
31 | + private UnknownHostExceptionHandler unknownHostExceptionHandler; | |
32 | + | |
33 | + @Inject | |
34 | + private SAXExceptionHandler sAXExceptionHandler; | |
35 | + | |
36 | + @Override | |
37 | + public Response toResponse(AxisFault ex) { | |
38 | + logger.error(ex); | |
39 | + | |
40 | + logger.debug(ex, ex); | |
41 | + | |
42 | + Throwable cause = ex.getCause(); | |
43 | + | |
44 | + if(cause instanceof UnknownHostException){ | |
45 | + return unknownHostExceptionHandler.toResponse((UnknownHostException) cause); | |
46 | + } | |
47 | + | |
48 | + if(cause instanceof SAXException){ | |
49 | + return sAXExceptionHandler.toResponse((SAXException) cause); | |
50 | + } | |
51 | + | |
52 | + return Response.status(Status.INTERNAL_SERVER_ERROR) | |
53 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
54 | + .type(getAcceptType(headers)) | |
55 | + .build(); | |
56 | + } | |
57 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/BusinessExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,37 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.core.Context; | |
7 | +import javax.ws.rs.core.HttpHeaders; | |
8 | +import javax.ws.rs.core.Response; | |
9 | +import javax.ws.rs.core.Response.Status; | |
10 | +import javax.ws.rs.ext.ExceptionMapper; | |
11 | +import javax.ws.rs.ext.Provider; | |
12 | + | |
13 | +import org.jboss.logging.Logger; | |
14 | + | |
15 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class BusinessExceptionHandler implements ExceptionMapper<BusinessException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + public Response toResponse(BusinessException ex) { | |
28 | + logger.error(ex); | |
29 | + | |
30 | + logger.debug(ex, ex); | |
31 | + | |
32 | + return Response.status(Status.BAD_REQUEST) | |
33 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.BAD_REQUEST.getStatusCode()))) | |
34 | + .type(getAcceptType(headers)) | |
35 | + .build(); | |
36 | + } | |
37 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/EJBAccessExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.ejb.EJBAccessException; | |
6 | +import javax.inject.Inject; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class EJBAccessExceptionHandler implements ExceptionMapper<EJBAccessException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(EJBAccessException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.UNAUTHORIZED) | |
34 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.UNAUTHORIZED.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/EJBExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.ejb.EJBException; | |
6 | +import javax.inject.Inject; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | +import br.gov.ans.utils.MessageUtils; | |
18 | + | |
19 | +@Provider | |
20 | +public class EJBExceptionHandler implements ExceptionMapper<EJBException>{ | |
21 | + | |
22 | + @Inject | |
23 | + private Logger logger; | |
24 | + | |
25 | + @Context | |
26 | + private HttpHeaders headers; | |
27 | + | |
28 | + @Inject | |
29 | + private MessageUtils messages; | |
30 | + | |
31 | + public Response toResponse(EJBException ex) { | |
32 | + logger.error(ex); | |
33 | + | |
34 | + logger.debug(ex, ex); | |
35 | + | |
36 | + return Response.status(Status.INTERNAL_SERVER_ERROR) | |
37 | + .entity(new ErrorMessage(messages.getMessage("erro.inesperado"),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
38 | + .type(getAcceptType(headers)) | |
39 | + .build(); | |
40 | + } | |
41 | + | |
42 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/EJBTransactionRolledbackExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,43 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.ejb.EJBTransactionRolledbackException; | |
6 | +import javax.inject.Inject; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | +import br.gov.ans.utils.MessageUtils; | |
18 | + | |
19 | +@Provider | |
20 | +public class EJBTransactionRolledbackExceptionHandler implements ExceptionMapper<EJBTransactionRolledbackException>{ | |
21 | + | |
22 | + @Inject | |
23 | + private Logger logger; | |
24 | + | |
25 | + @Context | |
26 | + private HttpHeaders headers; | |
27 | + | |
28 | + @Inject | |
29 | + private MessageUtils messages; | |
30 | + | |
31 | + @Override | |
32 | + public Response toResponse(EJBTransactionRolledbackException ex) { | |
33 | + logger.error(ex); | |
34 | + | |
35 | + logger.debug(ex, ex); | |
36 | + | |
37 | + return Response.status(Status.INTERNAL_SERVER_ERROR) | |
38 | + .entity(new ErrorMessage(messages.getMessage("erro.inesperado"),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
39 | + .type(getAcceptType(headers)) | |
40 | + .build(); | |
41 | + } | |
42 | + | |
43 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/ExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.core.Context; | |
7 | +import javax.ws.rs.core.HttpHeaders; | |
8 | +import javax.ws.rs.core.Response; | |
9 | +import javax.ws.rs.core.Response.Status; | |
10 | +import javax.ws.rs.ext.ExceptionMapper; | |
11 | +import javax.ws.rs.ext.Provider; | |
12 | + | |
13 | +import org.jboss.logging.Logger; | |
14 | + | |
15 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
16 | + | |
17 | +@Provider | |
18 | +public class ExceptionHandler implements ExceptionMapper<Exception>{ | |
19 | + | |
20 | + @Inject | |
21 | + private Logger logger; | |
22 | + | |
23 | + @Context | |
24 | + private HttpHeaders headers; | |
25 | + | |
26 | + @Override | |
27 | + public Response toResponse(Exception ex) { | |
28 | + logger.error(ex); | |
29 | + | |
30 | + logger.debug(ex, ex); | |
31 | + | |
32 | + return Response.status(Status.INTERNAL_SERVER_ERROR) | |
33 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
34 | + .type(getAcceptType(headers)) | |
35 | + .build(); | |
36 | + } | |
37 | + | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/ForbiddenExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.ForbiddenException; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class ForbiddenExceptionHandler implements ExceptionMapper<ForbiddenException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(ForbiddenException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.FORBIDDEN) | |
34 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.FORBIDDEN.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/LoginExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,89 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import java.io.IOException; | |
6 | +import java.io.PrintWriter; | |
7 | +import java.io.StringWriter; | |
8 | + | |
9 | +import javax.inject.Inject; | |
10 | +import javax.servlet.ServletException; | |
11 | +import javax.servlet.http.HttpServlet; | |
12 | +import javax.servlet.http.HttpServletRequest; | |
13 | +import javax.servlet.http.HttpServletResponse; | |
14 | +import javax.ws.rs.core.MediaType; | |
15 | +import javax.ws.rs.core.Response.Status; | |
16 | +import javax.xml.bind.JAXB; | |
17 | + | |
18 | +import org.jboss.logging.Logger; | |
19 | + | |
20 | +import com.google.gson.Gson; | |
21 | + | |
22 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
23 | + | |
24 | +//@WebServlet("/loginExceptionHandler") | |
25 | +public class LoginExceptionHandler extends HttpServlet{ | |
26 | + | |
27 | + private static final long serialVersionUID = 1L; | |
28 | + | |
29 | + @Inject | |
30 | + private Logger logger; | |
31 | + | |
32 | + @Override | |
33 | + protected void doPost(HttpServletRequest req, HttpServletResponse resp) | |
34 | + throws ServletException, IOException { | |
35 | + | |
36 | + String acceptType = getAcceptType(req); | |
37 | + | |
38 | + resp.setContentType(acceptType); | |
39 | + resp.setCharacterEncoding("utf-8"); | |
40 | + | |
41 | + CODE code = CODE.valueOf("_"+req.getParameter("code")); | |
42 | + | |
43 | + ErrorMessage error = new ErrorMessage(code.message, code.status.getStatusCode()); | |
44 | + | |
45 | + logger.error(error.getError()); | |
46 | + | |
47 | + PrintWriter out = resp.getWriter(); | |
48 | + | |
49 | + if(acceptType.equals(MediaType.APPLICATION_JSON)){ | |
50 | + out.write(new Gson().toJson(error)); | |
51 | + }else{ | |
52 | + StringWriter sw = new StringWriter(); | |
53 | + JAXB.marshal(error, sw); | |
54 | + | |
55 | + out.write(sw.toString()); | |
56 | + } | |
57 | + } | |
58 | + | |
59 | + @Override | |
60 | + protected void doGet(HttpServletRequest req, HttpServletResponse resp) | |
61 | + throws ServletException, IOException { | |
62 | + doPost(req, resp); | |
63 | + } | |
64 | + | |
65 | + @Override | |
66 | + protected void doPut(HttpServletRequest req, HttpServletResponse resp) | |
67 | + throws ServletException, IOException { | |
68 | + doPost(req, resp); | |
69 | + } | |
70 | + | |
71 | + @Override | |
72 | + protected void doDelete(HttpServletRequest req, HttpServletResponse resp) | |
73 | + throws ServletException, IOException { | |
74 | + doPost(req, resp); | |
75 | + } | |
76 | + | |
77 | + private enum CODE{ | |
78 | + _401(Status.UNAUTHORIZED, "Cliente não autenticado."), | |
79 | + _403(Status.FORBIDDEN, "Cliente não autorizado."); | |
80 | + | |
81 | + Status status; | |
82 | + String message; | |
83 | + | |
84 | + private CODE(Status restStatus, String message) { | |
85 | + this.status = restStatus; | |
86 | + this.message = message; | |
87 | + } | |
88 | + } | |
89 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/NotAcceptableExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.NotAcceptableException; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class NotAcceptableExceptionHandler implements ExceptionMapper<NotAcceptableException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(NotAcceptableException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.NOT_ACCEPTABLE) | |
34 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.NOT_ACCEPTABLE.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/NotAllowedExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.NotAllowedException; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class NotAllowedExceptionHandler implements ExceptionMapper<NotAllowedException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(NotAllowedException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.METHOD_NOT_ALLOWED) | |
34 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.METHOD_NOT_ALLOWED.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/NotAuthorizedExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.NotAuthorizedException; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class NotAuthorizedExceptionHandler implements ExceptionMapper<NotAuthorizedException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(NotAuthorizedException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.UNAUTHORIZED) | |
34 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.UNAUTHORIZED.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/NotFoundExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.NotFoundException; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class NotFoundExceptionHandler implements ExceptionMapper<NotFoundException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(NotFoundException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.NOT_FOUND) | |
34 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.NOT_FOUND.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/PersistenceExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.persistence.PersistenceException; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | +import br.gov.ans.utils.MessageUtils; | |
18 | + | |
19 | +@Provider | |
20 | +public class PersistenceExceptionHandler implements ExceptionMapper<PersistenceException>{ | |
21 | + | |
22 | + @Inject | |
23 | + private Logger logger; | |
24 | + | |
25 | + @Context | |
26 | + private HttpHeaders headers; | |
27 | + | |
28 | + @Inject | |
29 | + private MessageUtils messages; | |
30 | + | |
31 | + public Response toResponse(PersistenceException ex) { | |
32 | + logger.error(ex); | |
33 | + | |
34 | + logger.debug(ex, ex); | |
35 | + | |
36 | + return Response.status(Status.INTERNAL_SERVER_ERROR) | |
37 | + .entity(new ErrorMessage(messages.getMessage("erro.inesperado"),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
38 | + .type(getAcceptType(headers)) | |
39 | + .build(); | |
40 | + } | |
41 | + | |
42 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/ResourceConflictExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,37 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.core.Context; | |
7 | +import javax.ws.rs.core.HttpHeaders; | |
8 | +import javax.ws.rs.core.Response; | |
9 | +import javax.ws.rs.core.Response.Status; | |
10 | +import javax.ws.rs.ext.ExceptionMapper; | |
11 | +import javax.ws.rs.ext.Provider; | |
12 | + | |
13 | +import org.jboss.logging.Logger; | |
14 | + | |
15 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
16 | +import br.gov.ans.integracao.sei.exceptions.ResourceConflictException; | |
17 | + | |
18 | +@Provider | |
19 | +public class ResourceConflictExceptionHandler implements ExceptionMapper<ResourceConflictException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + public Response toResponse(ResourceConflictException ex) { | |
28 | + logger.error(ex); | |
29 | + | |
30 | + logger.debug(ex, ex); | |
31 | + | |
32 | + return Response.status(Status.CONFLICT) | |
33 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.CONFLICT.getStatusCode()))) | |
34 | + .type(getAcceptType(headers)) | |
35 | + .build(); | |
36 | + } | |
37 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/ResourceNotFoundExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,37 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.core.Context; | |
7 | +import javax.ws.rs.core.HttpHeaders; | |
8 | +import javax.ws.rs.core.Response; | |
9 | +import javax.ws.rs.core.Response.Status; | |
10 | +import javax.ws.rs.ext.ExceptionMapper; | |
11 | +import javax.ws.rs.ext.Provider; | |
12 | + | |
13 | +import org.jboss.logging.Logger; | |
14 | + | |
15 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
16 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
17 | + | |
18 | +@Provider | |
19 | +public class ResourceNotFoundExceptionHandler implements ExceptionMapper<ResourceNotFoundException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + public Response toResponse(ResourceNotFoundException ex) { | |
28 | + logger.error(ex); | |
29 | + | |
30 | + logger.debug(ex, ex); | |
31 | + | |
32 | + return Response.status(Status.NOT_FOUND) | |
33 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.NOT_FOUND.getStatusCode()))) | |
34 | + .type(getAcceptType(headers)) | |
35 | + .build(); | |
36 | + } | |
37 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/SAXExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.core.Context; | |
7 | +import javax.ws.rs.core.HttpHeaders; | |
8 | +import javax.ws.rs.core.Response; | |
9 | +import javax.ws.rs.core.Response.Status; | |
10 | +import javax.ws.rs.ext.ExceptionMapper; | |
11 | +import javax.ws.rs.ext.Provider; | |
12 | + | |
13 | +import org.jboss.logging.Logger; | |
14 | +import org.xml.sax.SAXException; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class SAXExceptionHandler implements ExceptionMapper<SAXException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(SAXException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.INTERNAL_SERVER_ERROR) | |
34 | + .entity(new ErrorMessage("Não foi possível se conectar ao SEI.",String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/UnknownHostExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import java.net.UnknownHostException; | |
6 | + | |
7 | +import javax.inject.Inject; | |
8 | +import javax.ws.rs.core.Context; | |
9 | +import javax.ws.rs.core.HttpHeaders; | |
10 | +import javax.ws.rs.core.Response; | |
11 | +import javax.ws.rs.core.Response.Status; | |
12 | +import javax.ws.rs.ext.ExceptionMapper; | |
13 | +import javax.ws.rs.ext.Provider; | |
14 | + | |
15 | +import org.jboss.logging.Logger; | |
16 | + | |
17 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
18 | + | |
19 | +@Provider | |
20 | +public class UnknownHostExceptionHandler implements ExceptionMapper<UnknownHostException>{ | |
21 | + | |
22 | + @Inject | |
23 | + private Logger logger; | |
24 | + | |
25 | + @Context | |
26 | + private HttpHeaders headers; | |
27 | + | |
28 | + public Response toResponse(UnknownHostException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.BAD_GATEWAY) | |
34 | + .entity(new ErrorMessage("Não foi possível se conectar ao SEI.",String.valueOf(Status.BAD_GATEWAY.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/WebApplicationExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.WebApplicationException; | |
7 | +import javax.ws.rs.core.Context; | |
8 | +import javax.ws.rs.core.HttpHeaders; | |
9 | +import javax.ws.rs.core.Response; | |
10 | +import javax.ws.rs.core.Response.Status; | |
11 | +import javax.ws.rs.ext.ExceptionMapper; | |
12 | +import javax.ws.rs.ext.Provider; | |
13 | + | |
14 | +import org.jboss.logging.Logger; | |
15 | + | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | + | |
18 | +@Provider | |
19 | +public class WebApplicationExceptionHandler implements ExceptionMapper<WebApplicationException>{ | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Context | |
25 | + private HttpHeaders headers; | |
26 | + | |
27 | + @Override | |
28 | + public Response toResponse(WebApplicationException ex) { | |
29 | + logger.error(ex); | |
30 | + | |
31 | + logger.debug(ex, ex); | |
32 | + | |
33 | + return Response.status(Status.INTERNAL_SERVER_ERROR) | |
34 | + .entity(new ErrorMessage(ex.getMessage(),String.valueOf(Status.INTERNAL_SERVER_ERROR.getStatusCode()))) | |
35 | + .type(getAcceptType(headers)) | |
36 | + .build(); | |
37 | + } | |
38 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/exceptions/handlers/WrappedExceptionHandler.java
0 → 100644
... | ... | @@ -0,0 +1,46 @@ |
1 | +package br.gov.ans.integracao.sei.exceptions.handlers; | |
2 | + | |
3 | +import static br.gov.ans.utils.HttpHeadersUtil.getAcceptType; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.ws.rs.core.Context; | |
7 | +import javax.ws.rs.core.HttpHeaders; | |
8 | +import javax.ws.rs.core.Response; | |
9 | +import javax.ws.rs.core.Response.Status; | |
10 | +import javax.ws.rs.ext.ExceptionMapper; | |
11 | +import javax.ws.rs.ext.Provider; | |
12 | + | |
13 | +import org.jboss.logging.Logger; | |
14 | + | |
15 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
16 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
17 | +import br.gov.ans.integracao.sei.exceptions.WrappedException; | |
18 | + | |
19 | +@Provider | |
20 | +public class WrappedExceptionHandler implements ExceptionMapper<WrappedException>{ | |
21 | + | |
22 | + @Inject | |
23 | + private Logger logger; | |
24 | + | |
25 | + @Context | |
26 | + private HttpHeaders headers; | |
27 | + | |
28 | + @Override | |
29 | + public Response toResponse(WrappedException ex) { | |
30 | + logger.error(ex.getEx()); | |
31 | + | |
32 | + logger.debug(ex.getEx(), ex.getEx()); | |
33 | + | |
34 | + Status status = Status.INTERNAL_SERVER_ERROR; | |
35 | + | |
36 | + if(ex.getEx() instanceof BusinessException){ | |
37 | + status = Status.BAD_REQUEST; | |
38 | + } | |
39 | + | |
40 | + return Response.status(status) | |
41 | + .entity(new ErrorMessage(ex.getEx().getMessage(),String.valueOf(status.getStatusCode()))) | |
42 | + .type(getAcceptType(headers)) | |
43 | + .build(); | |
44 | + } | |
45 | + | |
46 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/filters/LogRequestFilter.java
0 → 100644
... | ... | @@ -0,0 +1,82 @@ |
1 | +package br.gov.ans.integracao.sei.filters; | |
2 | + | |
3 | +import java.io.IOException; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.servlet.http.HttpServletRequest; | |
7 | +import javax.ws.rs.container.ContainerRequestContext; | |
8 | +import javax.ws.rs.container.ContainerRequestFilter; | |
9 | +import javax.ws.rs.container.ResourceInfo; | |
10 | +import javax.ws.rs.core.Context; | |
11 | +import javax.ws.rs.core.SecurityContext; | |
12 | +import javax.ws.rs.core.UriInfo; | |
13 | +import javax.ws.rs.ext.Provider; | |
14 | + | |
15 | +import org.jboss.logging.Logger; | |
16 | +import org.jboss.resteasy.core.ResourceMethodInvoker; | |
17 | + | |
18 | +import br.gov.ans.integracao.sei.utils.Constantes; | |
19 | +import br.gov.ans.utils.LogIgnore; | |
20 | +import br.gov.ans.utils.LogIntegracaoUtil; | |
21 | +import br.gov.ans.utils.MessageUtils; | |
22 | + | |
23 | +@Provider | |
24 | +public class LogRequestFilter implements ContainerRequestFilter{ | |
25 | + | |
26 | + @Inject | |
27 | + private LogIntegracaoUtil audit; | |
28 | + | |
29 | + @Inject | |
30 | + private MessageUtils messages; | |
31 | + | |
32 | + @Context | |
33 | + private UriInfo uriInfo; | |
34 | + | |
35 | + @Context | |
36 | + private ResourceInfo resourceInfo; | |
37 | + | |
38 | + @Context | |
39 | + private HttpServletRequest request; | |
40 | + | |
41 | + @Context | |
42 | + private SecurityContext securityContext; | |
43 | + | |
44 | + @Inject | |
45 | + private Logger logger; | |
46 | + | |
47 | + @Override | |
48 | + public void filter(ContainerRequestContext context) throws IOException{ | |
49 | + request.setCharacterEncoding(Constantes.UTF8); | |
50 | + | |
51 | + if(isLoggable()){ | |
52 | + audit.registrarLog(getUserName(),uriInfo.getAbsolutePath().toString(), getMethodName(context)); | |
53 | + } | |
54 | + } | |
55 | + | |
56 | + public String getMethodName(ContainerRequestContext context){ | |
57 | + ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) context.getProperty(Constantes.RESOURCE_METHOD_INVOKER); | |
58 | + | |
59 | + return methodInvoker.getMethod().getName(); | |
60 | + } | |
61 | + | |
62 | + public String getUserName(){ | |
63 | + try{ | |
64 | + return securityContext.getUserPrincipal().getName(); | |
65 | + }catch (Exception ex) { | |
66 | + logger.debug("Sem informações do usuário logado: ", ex); | |
67 | + return messages.getMessage("sem.informacoes.usuario"); | |
68 | + } | |
69 | + } | |
70 | + | |
71 | + private boolean isLoggable(){ | |
72 | + if(resourceInfo.getResourceClass().isAnnotationPresent(LogIgnore.class)){ | |
73 | + return false; | |
74 | + } | |
75 | + | |
76 | + if(resourceInfo.getResourceMethod().isAnnotationPresent(LogIgnore.class)){ | |
77 | + return false; | |
78 | + } | |
79 | + | |
80 | + return true; | |
81 | + } | |
82 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/filters/SessionInvalidateFilter.java
0 → 100644
... | ... | @@ -0,0 +1,33 @@ |
1 | +package br.gov.ans.integracao.sei.filters; | |
2 | + | |
3 | +import java.io.IOException; | |
4 | + | |
5 | +import javax.inject.Inject; | |
6 | +import javax.servlet.http.HttpServletRequest; | |
7 | +import javax.ws.rs.container.ContainerRequestContext; | |
8 | +import javax.ws.rs.container.ContainerResponseContext; | |
9 | +import javax.ws.rs.container.ContainerResponseFilter; | |
10 | +import javax.ws.rs.core.Context; | |
11 | +import javax.ws.rs.ext.Provider; | |
12 | + | |
13 | +import org.jboss.logging.Logger; | |
14 | + | |
15 | +@Provider | |
16 | +public class SessionInvalidateFilter implements ContainerResponseFilter{ | |
17 | + | |
18 | + @Context | |
19 | + private HttpServletRequest request; | |
20 | + | |
21 | + @Inject | |
22 | + private Logger logger; | |
23 | + | |
24 | + @Override | |
25 | + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | |
26 | + throws IOException { | |
27 | + try{ | |
28 | + request.getSession().invalidate(); | |
29 | + }catch(Exception ex){ | |
30 | + logger.error(ex); | |
31 | + } | |
32 | + } | |
33 | +} | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/ArquivoResource.java
... | ... | @@ -16,8 +16,8 @@ import javax.ws.rs.core.Response; |
16 | 16 | import javax.ws.rs.core.UriBuilder; |
17 | 17 | import javax.ws.rs.core.UriInfo; |
18 | 18 | |
19 | -import br.gov.ans.exceptions.BusinessException; | |
20 | 19 | import br.gov.ans.integracao.sei.client.SeiPortTypeProxy; |
20 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
21 | 21 | import br.gov.ans.integracao.sei.modelo.Arquivo; |
22 | 22 | import br.gov.ans.integracao.sei.modelo.ArquivoCriado; |
23 | 23 | import br.gov.ans.integracao.sei.modelo.Operacao; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/ContatoResource.java
... | ... | @@ -28,11 +28,11 @@ import javax.ws.rs.core.UriInfo; |
28 | 28 | |
29 | 29 | import org.apache.commons.lang3.ArrayUtils; |
30 | 30 | |
31 | -import br.gov.ans.exceptions.BusinessException; | |
32 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
33 | -import br.gov.ans.exceptions.WrappedException; | |
34 | 31 | import br.gov.ans.integracao.sei.client.Contato; |
35 | 32 | import br.gov.ans.integracao.sei.client.SeiPortTypeProxy; |
33 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
34 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
35 | +import br.gov.ans.integracao.sei.exceptions.WrappedException; | |
36 | 36 | import br.gov.ans.integracao.sei.modelo.Operacao; |
37 | 37 | import br.gov.ans.integracao.sei.modelo.Pessoa; |
38 | 38 | import br.gov.ans.integracao.sei.modelo.enums.Acao; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/DocumentoResource.java
... | ... | @@ -47,15 +47,15 @@ import com.github.mustachejava.Mustache; |
47 | 47 | |
48 | 48 | import br.gov.ans.commons.security.crypt.HashUtils; |
49 | 49 | import br.gov.ans.dao.DAO; |
50 | -import br.gov.ans.exceptions.BusinessException; | |
51 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
52 | -import br.gov.ans.exceptions.WrappedException; | |
53 | 50 | import br.gov.ans.integracao.sei.client.Documento; |
54 | 51 | import br.gov.ans.integracao.sei.client.RetornoConsultaDocumento; |
55 | 52 | import br.gov.ans.integracao.sei.client.RetornoInclusaoDocumento; |
56 | 53 | import br.gov.ans.integracao.sei.client.SeiPortTypeProxy; |
57 | 54 | import br.gov.ans.integracao.sei.dao.DocumentoDAO; |
58 | 55 | import br.gov.ans.integracao.sei.dao.InclusaoDocumentoDAO; |
56 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
57 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
58 | +import br.gov.ans.integracao.sei.exceptions.WrappedException; | |
59 | 59 | import br.gov.ans.integracao.sei.modelo.CancelamentoDocumento; |
60 | 60 | import br.gov.ans.integracao.sei.modelo.DocumentoResumido; |
61 | 61 | import br.gov.ans.integracao.sei.modelo.ExclusaoDocumento; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/InfoResource.java
... | ... | @@ -17,9 +17,9 @@ import javax.ws.rs.core.MediaType; |
17 | 17 | |
18 | 18 | import org.jboss.logging.Logger; |
19 | 19 | |
20 | -import br.gov.ans.exceptions.BusinessException; | |
21 | 20 | import br.gov.ans.integracao.sei.client.SeiPortTypeProxy; |
22 | 21 | import br.gov.ans.integracao.sei.dao.LogIntegracaoSistemicaDAO; |
22 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
23 | 23 | import br.gov.ans.integracao.sei.modelo.Operacao; |
24 | 24 | import br.gov.ans.integracao.sei.utils.Constantes; |
25 | 25 | import br.gov.ans.modelo.LogIntegracaoSistemica; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/InfraResource.java
... | ... | @@ -15,12 +15,12 @@ import javax.ws.rs.core.MediaType; |
15 | 15 | import org.apache.commons.lang3.ArrayUtils; |
16 | 16 | import org.apache.commons.lang3.StringUtils; |
17 | 17 | |
18 | -import br.gov.ans.exceptions.BusinessException; | |
19 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
20 | 18 | import br.gov.ans.integracao.sei.client.Estado; |
21 | 19 | import br.gov.ans.integracao.sei.client.Pais; |
22 | 20 | import br.gov.ans.integracao.sei.client.SeiPortTypeProxy; |
23 | 21 | import br.gov.ans.integracao.sei.dao.CidadeDAO; |
22 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
23 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
24 | 24 | import br.gov.ans.integracao.sei.modelo.Operacao; |
25 | 25 | import br.gov.ans.integracao.sei.utils.Constantes; |
26 | 26 | import br.gov.ans.utils.MessageUtils; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/ProcessoResource.java
... | ... | @@ -37,8 +37,6 @@ import org.apache.commons.lang3.StringUtils; |
37 | 37 | import org.jboss.logging.Logger; |
38 | 38 | import org.jboss.resteasy.annotations.providers.jaxb.Wrapped; |
39 | 39 | |
40 | -import br.gov.ans.exceptions.BusinessException; | |
41 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
42 | 40 | import br.gov.ans.integracao.sei.client.Andamento; |
43 | 41 | import br.gov.ans.integracao.sei.client.AtributoAndamento; |
44 | 42 | import br.gov.ans.integracao.sei.client.RetornoConsultaProcedimento; |
... | ... | @@ -50,6 +48,8 @@ import br.gov.ans.integracao.sei.dao.DocumentoDAO; |
50 | 48 | import br.gov.ans.integracao.sei.dao.ProcessoDAO; |
51 | 49 | import br.gov.ans.integracao.sei.dao.SiparDAO; |
52 | 50 | import br.gov.ans.integracao.sei.dao.UnidadeDAO; |
51 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
52 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
53 | 53 | import br.gov.ans.integracao.sei.modelo.DocumentoResumido; |
54 | 54 | import br.gov.ans.integracao.sei.modelo.EnvioDeProcesso; |
55 | 55 | import br.gov.ans.integracao.sei.modelo.Motivo; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/SiparResource.java
... | ... | @@ -18,10 +18,10 @@ import javax.ws.rs.core.UriInfo; |
18 | 18 | |
19 | 19 | import org.jboss.logging.Logger; |
20 | 20 | |
21 | -import br.gov.ans.exceptions.BusinessException; | |
22 | -import br.gov.ans.exceptions.ResourceConflictException; | |
23 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
24 | 21 | import br.gov.ans.integracao.sei.dao.SiparDAO; |
22 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
23 | +import br.gov.ans.integracao.sei.exceptions.ResourceConflictException; | |
24 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
25 | 25 | import br.gov.ans.integracao.sipar.dao.ControleMigracao; |
26 | 26 | import br.gov.ans.integracao.sipar.dao.ControleMigracaoId; |
27 | 27 | import br.gov.ans.utils.MessageUtils; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/TarefaResource.java
... | ... | @@ -9,8 +9,8 @@ import javax.ws.rs.Produces; |
9 | 9 | import javax.ws.rs.QueryParam; |
10 | 10 | import javax.ws.rs.core.MediaType; |
11 | 11 | |
12 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
13 | 12 | import br.gov.ans.integracao.sei.dao.TarefaDAO; |
13 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
14 | 14 | import br.gov.ans.integracao.sei.modelo.Tarefa; |
15 | 15 | import br.gov.ans.utils.MessageUtils; |
16 | 16 | ... | ... |
src/main/java/br/gov/ans/integracao/sei/rest/UnidadeResource.java
... | ... | @@ -15,9 +15,9 @@ import org.apache.commons.lang3.ArrayUtils; |
15 | 15 | import org.apache.commons.lang3.time.DateUtils; |
16 | 16 | import org.jboss.logging.Logger; |
17 | 17 | |
18 | -import br.gov.ans.exceptions.BusinessException; | |
19 | 18 | import br.gov.ans.integracao.sei.client.SeiPortTypeProxy; |
20 | 19 | import br.gov.ans.integracao.sei.client.Unidade; |
20 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
21 | 21 | import br.gov.ans.integracao.sei.modelo.Operacao; |
22 | 22 | import br.gov.ans.integracao.sei.utils.Constantes; |
23 | 23 | import br.gov.ans.utils.MessageUtils; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/utils/ContatoHelper.java
... | ... | @@ -11,10 +11,10 @@ import javax.inject.Inject; |
11 | 11 | |
12 | 12 | import org.apache.commons.lang3.StringUtils; |
13 | 13 | |
14 | -import br.gov.ans.exceptions.BusinessException; | |
15 | 14 | import br.gov.ans.integracao.sei.client.Contato; |
16 | 15 | import br.gov.ans.integracao.sei.dao.CidadeDAO; |
17 | 16 | import br.gov.ans.integracao.sei.dao.ContatoDAO; |
17 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
18 | 18 | import br.gov.ans.integracao.sei.modelo.Cidade; |
19 | 19 | import br.gov.ans.integracao.sei.modelo.Endereco; |
20 | 20 | import br.gov.ans.integracao.sei.modelo.Pessoa; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/utils/PessoaHelper.java
... | ... | @@ -14,11 +14,11 @@ import org.apache.commons.lang3.StringUtils; |
14 | 14 | import org.apache.commons.lang3.reflect.FieldUtils; |
15 | 15 | import org.jboss.logging.Logger; |
16 | 16 | |
17 | -import br.gov.ans.exceptions.BusinessException; | |
18 | -import br.gov.ans.exceptions.ResourceNotFoundException; | |
19 | 17 | import br.gov.ans.integracao.sei.client.Contato; |
20 | 18 | import br.gov.ans.integracao.sei.dao.CidadeDAO; |
21 | 19 | import br.gov.ans.integracao.sei.dao.ContatoDAO; |
20 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
21 | +import br.gov.ans.integracao.sei.exceptions.ResourceNotFoundException; | |
22 | 22 | import br.gov.ans.integracao.sei.modelo.Endereco; |
23 | 23 | import br.gov.ans.integracao.sei.modelo.Pessoa; |
24 | 24 | import br.gov.ans.integracao.sei.modelo.PessoaFisica; | ... | ... |
src/main/java/br/gov/ans/integracao/sei/utils/Util.java
... | ... | @@ -24,7 +24,7 @@ import org.codehaus.jackson.JsonParseException; |
24 | 24 | import org.codehaus.jackson.map.JsonMappingException; |
25 | 25 | import org.codehaus.jackson.type.TypeReference; |
26 | 26 | |
27 | -import br.gov.ans.exceptions.BusinessException; | |
27 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
28 | 28 | |
29 | 29 | public class Util { |
30 | 30 | ... | ... |
src/main/java/br/gov/ans/integracao/templates/client/ClientTemplatesBroker.java
... | ... | @@ -9,10 +9,10 @@ import javax.ws.rs.core.Response.Status.Family; |
9 | 9 | |
10 | 10 | import org.jboss.logging.Logger; |
11 | 11 | |
12 | -import br.gov.ans.exceptions.BusinessException; | |
13 | -import br.gov.ans.exceptions.ErrorMessage; | |
14 | 12 | import br.gov.ans.factories.qualifiers.Autenticado; |
15 | 13 | import br.gov.ans.factories.qualifiers.SeiQualifiers.TemplatesBrokerParameter; |
14 | +import br.gov.ans.integracao.sei.exceptions.BusinessException; | |
15 | +import br.gov.ans.integracao.sei.exceptions.ErrorMessage; | |
16 | 16 | import br.gov.ans.integracao.sei.utils.Constantes; |
17 | 17 | |
18 | 18 | public class ClientTemplatesBroker { | ... | ... |
src/main/webapp/WEB-INF/web.xml
... | ... | @@ -31,7 +31,7 @@ |
31 | 31 | |
32 | 32 | <servlet> |
33 | 33 | <servlet-name>LoginExceptionHandler</servlet-name> |
34 | - <servlet-class>br.gov.ans.exceptions.handlers.LoginExceptionHandler</servlet-class> | |
34 | + <servlet-class>br.gov.ans.integracao.sei.exceptions.handlers.LoginExceptionHandler</servlet-class> | |
35 | 35 | </servlet> |
36 | 36 | |
37 | 37 | <servlet-mapping> |
... | ... | @@ -124,66 +124,66 @@ |
124 | 124 | <!-- Declaração dos ExceptionHandlers --> |
125 | 125 | <context-param> |
126 | 126 | <param-name>resteasy.businessExceptionHandler</param-name> |
127 | - <param-value>br.gov.ans.exceptions.handlers.BusinessExceptionHandler</param-value> | |
127 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.BusinessExceptionHandler</param-value> | |
128 | 128 | </context-param> |
129 | 129 | <context-param> |
130 | 130 | <param-name>resteasy.EJBTransactionRolledbackExceptionHandler</param-name> |
131 | - <param-value>br.gov.ans.exceptions.handlers.EJBTransactionRolledbackExceptionHandler</param-value> | |
131 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.EJBTransactionRolledbackExceptionHandler</param-value> | |
132 | 132 | </context-param> |
133 | 133 | <context-param> |
134 | 134 | <param-name>resteasy.notAllowedExceptionHandler</param-name> |
135 | - <param-value>br.gov.ans.exceptions.handlers.NotAllowedExceptionHandler</param-value> | |
135 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.NotAllowedExceptionHandler</param-value> | |
136 | 136 | </context-param> |
137 | 137 | <context-param> |
138 | 138 | <param-name>resteasy.notAcceptableExceptionHandler</param-name> |
139 | - <param-value>br.gov.ans.exceptions.handlers.NotAcceptableExceptionHandler</param-value> | |
139 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.NotAcceptableExceptionHandler</param-value> | |
140 | 140 | </context-param> |
141 | 141 | <context-param> |
142 | 142 | <param-name>resteasy.ejbAccessExceptionHandler</param-name> |
143 | - <param-value>br.gov.ans.exceptions.handlers.EJBAccessExceptionHandler</param-value> | |
143 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.EJBAccessExceptionHandler</param-value> | |
144 | 144 | </context-param> |
145 | 145 | <context-param> |
146 | 146 | <param-name>resteasy.notFoundExceptionHandler</param-name> |
147 | - <param-value>br.gov.ans.exceptions.handlers.NotFoundExceptionHandler</param-value> | |
147 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.NotFoundExceptionHandler</param-value> | |
148 | 148 | </context-param> |
149 | 149 | <context-param> |
150 | 150 | <param-name>resteasy.exceptionHandler</param-name> |
151 | - <param-value>br.gov.ans.exceptions.handlers.ExceptionHandler</param-value> | |
151 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.ExceptionHandler</param-value> | |
152 | 152 | </context-param> |
153 | 153 | <context-param> |
154 | 154 | <param-name>resteasy.notAuthorizedExceptionHandler</param-name> |
155 | - <param-value>br.gov.ans.exceptions.handlers.NotAuthorizedExceptionHandler</param-value> | |
155 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.NotAuthorizedExceptionHandler</param-value> | |
156 | 156 | </context-param> |
157 | 157 | <context-param> |
158 | 158 | <param-name>resteasy.forbiddenException</param-name> |
159 | - <param-value>br.gov.ans.exceptions.handlers.ForbiddenException</param-value> | |
159 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.ForbiddenException</param-value> | |
160 | 160 | </context-param> |
161 | 161 | <context-param> |
162 | 162 | <param-name>resteasy.webApplicationException</param-name> |
163 | - <param-value>br.gov.ans.exceptions.handlers.WebApplicationException</param-value> | |
163 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.WebApplicationException</param-value> | |
164 | 164 | </context-param> |
165 | 165 | <context-param> |
166 | 166 | <param-name>resteasy.wrappedExceptionHandler</param-name> |
167 | - <param-value>br.gov.ans.exceptions.handlers.WrappedExceptionHandler</param-value> | |
167 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.WrappedExceptionHandler</param-value> | |
168 | 168 | </context-param> |
169 | 169 | <context-param> |
170 | 170 | <param-name>resteasy.resourceNotFoundExceptionHandler</param-name> |
171 | - <param-value>br.gov.ans.exceptions.handlers.ResourceNotFoundExceptionHandler</param-value> | |
171 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.ResourceNotFoundExceptionHandler</param-value> | |
172 | 172 | </context-param> |
173 | 173 | <context-param> |
174 | 174 | <param-name>resteasy.unknownHostExceptionHandler</param-name> |
175 | - <param-value>br.gov.ans.exceptions.handlers.UnknownHostExceptionHandler</param-value> | |
175 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.UnknownHostExceptionHandler</param-value> | |
176 | 176 | </context-param> |
177 | 177 | <context-param> |
178 | 178 | <param-name>resteasy.axisFaultHandler</param-name> |
179 | - <param-value>br.gov.ans.exceptions.handlers.AxisFaultHandler</param-value> | |
179 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.AxisFaultHandler</param-value> | |
180 | 180 | </context-param> |
181 | 181 | <context-param> |
182 | 182 | <param-name>resteasy.sAXExceptionHandler</param-name> |
183 | - <param-value>br.gov.ans.exceptions.handlers.SAXExceptionHandler</param-value> | |
183 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.SAXExceptionHandler</param-value> | |
184 | 184 | </context-param> |
185 | 185 | <context-param> |
186 | 186 | <param-name>resteasy.persistenceExceptionHandler</param-name> |
187 | - <param-value>br.gov.ans.exceptions.handlers.PersistenceExceptionHandler</param-value> | |
187 | + <param-value>br.gov.ans.integracao.sei.exceptions.handlers.PersistenceExceptionHandler</param-value> | |
188 | 188 | </context-param> |
189 | 189 | </web-app> |
190 | 190 | \ No newline at end of file | ... | ... |