コード例 #1
0
 public Response submit(Transaction transaction) {
   logger.info("submit()->called");
   Response response = new Response();
   ResponseError responseError = new ResponseError();
   try {
     response = managementTransactionsService.submit(transaction);
   } catch (Exception ex) {
     response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
     responseError.setMessage(ex.getMessage());
     responseError.setErrorCode(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()));
     response.setData(responseError);
     logger.error(ex);
   }
   return response;
 }
コード例 #2
0
 @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
 @ExceptionHandler(Exception.class)
 public ErrorResponse internalError(final Exception exception, final HttpServletRequest request) {
   LOG.error("Unexpected error", exception);
   return createErrorResponse(
       HttpStatus.INTERNAL_SERVER_ERROR.value(), exception.getMessage(), request);
 }
 /**
  * If application fails or unknown error then return 500.
  *
  * @param ex Caused exception.
  * @return Internal server error.
  */
 @ExceptionHandler
 @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
 @ResponseBody
 public ErrorElementType handleException(final RuntimeException ex) {
   LOGGER.error("Error occured during request.", ex);
   ErrorElementType element = new ErrorElementType();
   element.setErrorcode(BigInteger.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()));
   element.setMessage("Application error. Send mail to [email protected].");
   return element;
 }
コード例 #4
0
 /**
  * 处理服务器端其他错误
  *
  * @param request 请求对象
  * @param exception 异常对象
  * @param locale 地理信息
  * @return
  */
 @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
 @ExceptionHandler({Exception.class})
 @ResponseBody
 public BaseResponseEntity<?> handleAllException(
     HttpServletRequest request, Exception exception, Locale locale) {
   return BaseResponseEntity.build(
       HttpStatus.INTERNAL_SERVER_ERROR.value(),
       APIStatus.SERVER_ERROR.getStatus(),
       APIStatus.SERVER_ERROR.name(),
       exception,
       request);
 }
コード例 #5
0
  /*
   * (non-Javadoc)
   * @see com.xmdevelopments.services.AuthService#submit()
   */
  @Override
  public Response submit() {
    String prefix = " submit()";
    logger.info(prefix + "->called");

    Response response = new Response();
    ResponseError responseError = new ResponseError();
    try {
      // Assumed that passed the WSSE validation
      // TODO authentication procedure
      response.setResponseCode(HttpStatus.OK.value());
      response.setData("Authentication successful");
    } catch (Exception ex) {
      response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
      responseError.setMessage(ex.getMessage());
      responseError.setErrorCode(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()));
      response.setData(responseError);
      logger.error(prefix, ex);
    }
    return response;
  }
コード例 #6
0
  @RequestMapping(value = "passes/{passTypeId}/{serialNo}", method = RequestMethod.GET)
  public void getPass(
      WebRequest webRequest,
      HttpServletResponse response,
      @PathVariable String passTypeId,
      @PathVariable String serialNo,
      @RequestHeader(value = "Authorization", defaultValue = "not_provided") String authorization)
      throws IOException {

    final String authToken = getAuthToken(authorization);
    //        if (null == authToken) {
    //            response.sendError(HttpStatus.UNAUTHORIZED.value());
    //            return;
    //        }

    try {
      //            final AbstractPassEntity pass = passbookService.getPass(passTypeId, serialNo,
      // authToken);
      //
      //            final long lastModified = pass.getUpdatedDate().getTime();
      //            if (webRequest.checkNotModified(lastModified)) {
      //                // shortcut exit - no further processing necessary
      //                return;
      //            }

      // write the .pkpass to the response
      ServletOutputStream out = response.getOutputStream();
      response.setContentType(CONTENT_TYPE_PASS);
      response.setHeader(CONTENT_DISPOSITION__NAME, CONTENT_DISPOSITION_VALUE);
      int length = passbookService.writePass(out, passTypeId, serialNo);
      out.flush();
      out.close();
      response.setStatus(HttpStatus.OK.value());
      LOG.info("Wrote pass of {} bytes", length);
      return;

      //        } catch (NoSuchPassException ex) {
      //            response.sendError(HttpStatus.NOT_FOUND.value());
      //            return;
    } catch (NoSuchPassTypeException ex) {
      response.sendError(HttpStatus.UNPROCESSABLE_ENTITY.value());
      return;
      //        } catch (InvalidAuthTokenException ex) {
      //            response.sendError(HttpStatus.UNAUTHORIZED.value());
      //            return;
    } catch (Exception ex) {
      LOG.error("Exception thrown by Service.writePass", ex);
      response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
      return;
    }
  }
コード例 #7
0
 @Override
 protected void doFilterInternal(
     HttpServletRequest request, HttpServletResponse response, FilterChain chain)
     throws ServletException, IOException {
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   String path = new UrlPathHelper().getPathWithinApplication(request);
   int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
   try {
     chain.doFilter(request, response);
     status = getStatus(response);
   } finally {
     stopWatch.stop();
     recordMetrics(request, path, status, stopWatch.getTotalTimeMillis());
   }
 }
コード例 #8
0
  @Test
  public void shouldReturn500WhenFailedToScheduleJobForEnrollment() throws Exception {

    MessageCampaignException.MessageKey message =
        new MessageCampaignException.MessageKey(
            "msgCampaign.error.schedulingError", Arrays.asList(EXTERNAL_ID));

    doThrow(new SchedulingException(EXTERNAL_ID, null))
        .when(enrollmentRestController)
        .enrollOrUpdateUser(any(String.class), any(String.class), any(EnrollmentRequest.class));

    controller
        .perform(
            post("/enrollments/{campaignName}/users", CAMPAIGN_NAME)
                .contentType(MediaType.APPLICATION_JSON)
                .param("externalId", EXTERNAL_ID)
                .param("enrollmentId", "9001"))
        .andExpect(status().is(HttpStatus.INTERNAL_SERVER_ERROR.value()))
        .andExpect(content().string(jsonMatcher(GSON.toJson(message))));
  }