Search in sources :

Example 1 with RESTCallInterruptException

use of org.mifos.rest.approval.service.RESTCallInterruptException in project head by mifos.

the class ApprovalServiceTest method createApprovalMethod.

private void createApprovalMethod() throws Exception {
    Class[] c = new Class[1];
    c[0] = String.class;
    MethodArgHolder args = new MethodArgHolder(c, new Object[1], new String[1]);
    ApprovalMethod am = new ApprovalMethod("updateCall", StubRESTController.class, args);
    try {
        approvalService.create(am);
        fail("should have thrown interrupt exception");
    } catch (RESTCallInterruptException e) {
    }
}
Also used : RESTCallInterruptException(org.mifos.rest.approval.service.RESTCallInterruptException) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) BeforeClass(org.junit.BeforeClass)

Example 2 with RESTCallInterruptException

use of org.mifos.rest.approval.service.RESTCallInterruptException in project head by mifos.

the class ApprovalServiceTest method createFailureApprovalMethod.

private void createFailureApprovalMethod() throws Exception {
    Class[] c = new Class[1];
    c[0] = String.class;
    MethodArgHolder args = new MethodArgHolder(c, new Object[1], new String[1]);
    ApprovalMethod am = new ApprovalMethod("failCall", StubRESTController.class, args);
    try {
        approvalService.create(am);
        fail("should have thrown interrupt exception");
    } catch (RESTCallInterruptException e) {
    }
}
Also used : RESTCallInterruptException(org.mifos.rest.approval.service.RESTCallInterruptException) MethodArgHolder(org.mifos.rest.approval.domain.MethodArgHolder) ApprovalMethod(org.mifos.rest.approval.domain.ApprovalMethod) BeforeClass(org.junit.BeforeClass)

Example 3 with RESTCallInterruptException

use of org.mifos.rest.approval.service.RESTCallInterruptException in project head by mifos.

the class AspectJApprovalInterceptorTest method testRESTCallExecution.

@Test
@Transactional
public void testRESTCallExecution() throws Exception {
    Assert.assertEquals(0, approvalService.getAllWaiting().size());
    try {
        stubRestController.createCall("HELLO");
        Assert.fail("should throw interrupt exception");
    } catch (RESTCallInterruptException e) {
    }
    Assert.assertEquals(1, approvalService.getAllWaiting().size());
    RESTApprovalEntity entity = approvalService.getAllWaiting().get(0);
    Assert.assertEquals("arg", entity.getApprovalMethod().getArgsHolder().getNames()[0]);
}
Also used : RESTApprovalEntity(org.mifos.rest.approval.domain.RESTApprovalEntity) RESTCallInterruptException(org.mifos.rest.approval.service.RESTCallInterruptException) Test(org.junit.Test) Transactional(org.mifos.framework.hibernate.helper.Transactional)

Example 4 with RESTCallInterruptException

use of org.mifos.rest.approval.service.RESTCallInterruptException in project head by mifos.

the class UncaughtExceptionHandler method doResolveException.

@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    ModelAndView modelAndView = checkForAccessDenied(ex, request);
    if (modelAndView == null) {
        modelAndView = checkForPageJndiException(ex, request);
    }
    if (modelAndView == null) {
        modelAndView = checkForPageExpiredException(ex, request);
    }
    if (modelAndView == null) {
        modelAndView = checkForMaxUploadSizeExceededException(ex, request);
    }
    if (request.getRequestURI().endsWith("json")) {
        if (modelAndView == null && ex instanceof RESTCallInterruptException) {
            // should move to explicit @ExceptionHandler(RESTCallInterruptException) controller method
            modelAndView = new ModelAndView();
            modelAndView.addObject("status", "interrupt");
            modelAndView.addObject("approvalId", ((RESTCallInterruptException) ex).getApprovalId());
            modelAndView.addObject("cause", "The call has been interrupt for approval");
            return modelAndView;
        }
        if (modelAndView == null || ex instanceof AccessDeniedException) {
            // should move to explicit @ExceptionHandler(Exception) controller method
            modelAndView = new ModelAndView();
            modelAndView.addObject("status", "error");
            modelAndView.addObject("cause", ex.getMessage());
            logger.error("REST API exception : URI '" + request.getRequestURI() + "'", ex);
            return modelAndView;
        }
    }
    if (modelAndView == null) {
        modelAndView = super.doResolveException(request, response, handler, ex);
    }
    if (modelAndView != null && !"HEAD".equals(request.getMethod())) {
        String requestUri = request.getRequestURI();
        logger.error("Uncaught exception while accessing '" + requestUri + "'", ex);
        modelAndView.addObject("uncaughtException", ex);
        modelAndView.addObject("requestUri", requestUri);
        if (ex != null) {
            Writer result = new StringWriter();
            ex.printStackTrace(new PrintWriter(result));
            modelAndView.addObject("stackString", result.toString());
        }
    }
    return modelAndView;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) RESTCallInterruptException(org.mifos.rest.approval.service.RESTCallInterruptException) StringWriter(java.io.StringWriter) ModelAndView(org.springframework.web.servlet.ModelAndView) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Aggregations

RESTCallInterruptException (org.mifos.rest.approval.service.RESTCallInterruptException)4 BeforeClass (org.junit.BeforeClass)2 ApprovalMethod (org.mifos.rest.approval.domain.ApprovalMethod)2 MethodArgHolder (org.mifos.rest.approval.domain.MethodArgHolder)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Test (org.junit.Test)1 Transactional (org.mifos.framework.hibernate.helper.Transactional)1 RESTApprovalEntity (org.mifos.rest.approval.domain.RESTApprovalEntity)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1