Package ch.ralscha.extdirectspring.bean

Examples of ch.ralscha.extdirectspring.bean.ExtDirectResponse


    configuration.setSendExceptionMessage(false);
    configuration.setSendStacktrace(true);
    Map<Class<?>, String> exceptionMessageMapping = new HashMap<Class<?>, String>();
    exceptionMessageMapping.put(NumberFormatException.class, null);
    configuration.setExceptionToMessage(exceptionMessageMapping);
    ExtDirectResponse resp = runTest(configuration);
    assertThat(resp.getMessage()).isEqualTo("For input string: \"xxx\"");
    assertThat(resp.getWhere()).startsWith("java.lang.NumberFormatException");
  }
View Full Code Here


    MvcResult result = ControllerUtil.performRouterRequest(mockMvc, edRequest);
    List<ExtDirectResponse> responses = ControllerUtil.readDirectResponses(result
        .getResponse().getContentAsByteArray());

    assertThat(responses).hasSize(1);
    ExtDirectResponse resp = responses.get(0);
    assertThat(resp.getAction()).isEqualTo("remoteProviderSimple");
    assertThat(resp.getMethod()).isEqualTo("method4b");
    assertThat(resp.getType()).isEqualTo("exception");
    assertThat(resp.getTid()).isEqualTo(2);
    assertThat(resp.getResult()).isNull();

    ReflectionTestUtils.setField(configurationService, "configuration",
        new Configuration());
    configurationService.afterPropertiesSet();
View Full Code Here

    MvcResult result = ControllerUtil.performRouterRequest(mockMvc, edRequest);
    List<ExtDirectResponse> responses = ControllerUtil.readDirectResponses(result
        .getResponse().getContentAsByteArray());

    assertThat(responses).hasSize(1);
    ExtDirectResponse resp = responses.get(0);
    assertThat(resp.getAction()).isEqualTo("remoteProviderSimple");
    assertThat(resp.getMethod()).isEqualTo("method11");
    assertThat(resp.getType()).isEqualTo("exception");
    assertThat(resp.getTid()).isEqualTo(3);
    assertThat(resp.getResult()).isNull();

    ReflectionTestUtils.setField(configurationService, "configuration",
        new Configuration());
    configurationService.afterPropertiesSet();
View Full Code Here

    String prefix = "<html><body><textarea>";
    String suffix = "</textarea><script type=\"text/javascript\">document.domain = 'rootdomain.com';</script></body></html>";
    assertThat(response).startsWith(prefix).endsWith(suffix);
    String json = response.substring(prefix.length(), response.indexOf(suffix));

    ExtDirectResponse edsResponse = ControllerUtil.readDirectResponse(json
        .getBytes(ExtDirectSpringUtil.UTF8_CHARSET));

    assertThat(edsResponse.getType()).isEqualTo("rpc");
    assertThat(edsResponse.getMessage()).isNull();
    assertThat(edsResponse.getWhere()).isNull();
    assertThat(edsResponse.getTid()).isEqualTo(1);
    assertThat(edsResponse.getAction()).isEqualTo("uploadService");
    assertThat(edsResponse.getMethod()).isEqualTo("upload");
  }
View Full Code Here

      MvcResult result = ControllerUtil.performRouterRequest(mockMvc, json);
      List<ExtDirectResponse> responses = ControllerUtil.readDirectResponses(result
          .getResponse().getContentAsByteArray());

      assertThat(responses).hasSize(1);
      ExtDirectResponse resp = responses.get(0);
      assertThat(resp.getAction()).isEqualTo("remoteProviderStoreRead");
      assertThat(resp.getMethod()).isEqualTo("methodFilter");
      assertThat(resp.getType()).isEqualTo("rpc");
      assertThat(resp.getTid()).isEqualTo(index);
      assertThat(resp.getMessage()).isNull();
      assertThat(resp.getWhere()).isNull();
      assertThat(resp.getResult()).isNotNull();

      List<Row> rows = ControllerUtil.convertValue(resp.getResult(),
          new TypeReference<List<Row>>() {
            // nothing here
          });

      assertThat(rows).hasSize(1);
View Full Code Here

  private static void assertResponse(String bean, String method, int tid,
      ResultObject expectedResult, List<ExtDirectResponse> responses) {

    assertThat(responses).hasSize(1);
    ExtDirectResponse resp = responses.get(0);
    assertThat(resp.getAction()).isEqualTo(bean);
    assertThat(resp.getMethod()).isEqualTo(method);
    assertThat(resp.getTid()).isEqualTo(tid);
    assertThat(resp.getType()).isEqualTo("rpc");
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isNull();

    ResultObject result = ControllerUtil.convertValue(resp.getResult(),
        ResultObject.class);

    assertThat(result).isEqualTo(expectedResult);
  }
View Full Code Here

    List<ExtDirectResponse> directResponses = new ArrayList<ExtDirectResponse>();

    for (ExtDirectRequest directRequest : directRequests) {

      ExtDirectResponse directResponse = new ExtDirectResponse(directRequest);

      try {
        MethodInfo methodInfo = ExtDirectSpringUtil.findMethodInfo(context, directRequest.getAction(),
            directRequest.getMethod());

        Object result = processRemotingRequest(request, response, locale, directRequest, methodInfo);

        if (result != null) {

          if (methodInfo.isType(ExtDirectMethodType.FORM_LOAD)
              && !ExtDirectFormLoadResult.class.isAssignableFrom(result.getClass())) {
            result = new ExtDirectFormLoadResult(result);
          } else if ((methodInfo.isType(ExtDirectMethodType.STORE_MODIFY) || methodInfo
              .isType(ExtDirectMethodType.STORE_READ))
              && !ExtDirectStoreResponse.class.isAssignableFrom(result.getClass())
              && configuration.isAlwaysWrapStoreResponse()) {
            result = new ExtDirectStoreResponse((Collection) result);
          }

          directResponse.setResult(result);
        } else {
          if (methodInfo.isType(ExtDirectMethodType.STORE_MODIFY)
              || methodInfo.isType(ExtDirectMethodType.STORE_READ)) {
            directResponse.setResult(Collections.emptyList());
          }
        }

      } catch (Exception e) {
        log.error("Error calling method: " + directRequest.getMethod(), e.getCause() != null ? e.getCause() : e);
View Full Code Here

    List<ExtDirectRequest> directRequests = getExtDirectRequests(rawRequestString);
    List<ExtDirectResponse> directResponses = new ArrayList<ExtDirectResponse>();

    for (ExtDirectRequest directRequest : directRequests) {

      ExtDirectResponse directResponse = new ExtDirectResponse(directRequest);

      try {
        MethodInfo methodInfo = ExtDirectSpringUtil.findMethodInfo(context, directRequest.getAction(),
            directRequest.getMethod());

        Object result = processRemotingRequest(request, response, locale, directRequest, methodInfo);

        if (result != null) {
          ExtDirectMethod annotation = methodInfo.getExtDirectMethodAnnotation();

          if (annotation.value() == ExtDirectMethodType.FORM_LOAD) {
            if (!ExtDirectFormLoadResult.class.isAssignableFrom(result.getClass())) {
              result = new ExtDirectFormLoadResult(result);
            }
          } else if (annotation.value() == ExtDirectMethodType.STORE_MODIFY) {
            if (!ExtDirectStoreResponse.class.isAssignableFrom(result.getClass())) {
              result = new ExtDirectStoreResponse((Collection) result);
            }
          }
        }

        directResponse.setResult(result);
      } catch (Exception e) {
        log.error("Error on method: " + directRequest.getMethod(), e);

        directResponse.setType("exception");

        if (log.isDebugEnabled()) {
          directResponse.setMessage(e.getMessage());
          directResponse.setWhere(getStackTrace(e));
        } else {
          directResponse.setMessage("Server Error");
          directResponse.setWhere(null);
        }
      }

      directResponses.add(directResponse);
    }
View Full Code Here

    List<ExtDirectResponse> directResponses = new ArrayList<ExtDirectResponse>();

    for (ExtDirectRequest directRequest : directRequests) {

      ExtDirectResponse directResponse = new ExtDirectResponse(directRequest);

      try {
        MethodInfo methodInfo = ExtDirectSpringUtil.findMethodInfo(context, directRequest.getAction(),
            directRequest.getMethod());

        Object result = processRemotingRequest(request, response, locale, directRequest, methodInfo);

        if (result != null) {

          if (methodInfo.isType(ExtDirectMethodType.FORM_LOAD)
              && !ExtDirectFormLoadResult.class.isAssignableFrom(result.getClass())) {
            result = new ExtDirectFormLoadResult(result);
          } else if ((methodInfo.isType(ExtDirectMethodType.STORE_MODIFY) || methodInfo
              .isType(ExtDirectMethodType.STORE_READ))
              && !ExtDirectStoreResponse.class.isAssignableFrom(result.getClass())
              && configuration.isAlwaysWrapStoreResponse()) {
            result = new ExtDirectStoreResponse((Collection) result);
          }

          directResponse.setResult(result);
        } else {
          if (methodInfo.isType(ExtDirectMethodType.STORE_MODIFY)
              || methodInfo.isType(ExtDirectMethodType.STORE_READ)) {
            directResponse.setResult(Collections.emptyList());
          }
        }

      } catch (Exception e) {
        log.error("Error calling method: " + directRequest.getMethod(), e.getCause() != null ? e.getCause() : e);
View Full Code Here

  @RequestMapping(value = "/router", method = RequestMethod.POST, params = "extAction")
  public String router(HttpServletRequest request, HttpServletResponse response,
      @RequestParam("extAction") String extAction, @RequestParam("extMethod") String extMethod)
      throws IOException {

    ExtDirectResponse directResponse = new ExtDirectResponse(request);
    MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(extAction, extMethod);
    boolean streamResponse;

    if (methodInfo != null && methodInfo.getForwardPath() != null) {
      return methodInfo.getForwardPath();
    } else if (methodInfo != null && methodInfo.getHandlerMethod() != null) {
      streamResponse = configurationService.getConfiguration().isStreamResponse()
          || methodInfo.isStreamResponse();

      HandlerMethod handlerMethod = methodInfo.getHandlerMethod();
      try {

        ModelAndView modelAndView = null;

        if (configurationService.getConfiguration().isSynchronizeOnSession()
            || methodInfo.isSynchronizeOnSession()) {
          HttpSession session = request.getSession(false);
          if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
              modelAndView = handlerAdapter.handle(request, response, handlerMethod);
            }
          } else {
            modelAndView = handlerAdapter.handle(request, response, handlerMethod);
          }
        } else {
          modelAndView = handlerAdapter.handle(request, response, handlerMethod);
        }

        ExtDirectFormPostResult formPostResult = (ExtDirectFormPostResult) modelAndView.getModel().get(
            "extDirectFormPostResult");
        directResponse.setResult(formPostResult.getResult());
      } catch (Exception e) {
        log.error("Error calling method: " + extMethod, e.getCause() != null ? e.getCause() : e);
        handleException(directResponse, e);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("success", false);
        directResponse.setResult(result);
      }
    } else {
      streamResponse = configurationService.getConfiguration().isStreamResponse();
      log.error("Error invoking method '" + extAction + "." + extMethod + "'. Method  or Bean not found");
      handleMethodNotFoundError(directResponse, extAction, extMethod);
View Full Code Here

TOP

Related Classes of ch.ralscha.extdirectspring.bean.ExtDirectResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.