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;
 }
 public void uploadApplication(
     String appName, ApplicationArchive archive, UploadStatusCallback callback)
     throws IOException {
   Assert.notNull(appName, "AppName must not be null");
   Assert.notNull(archive, "Archive must not be null");
   if (callback == null) {
     callback = UploadStatusCallback.NONE;
   }
   CloudResources knownRemoteResources = getKnownRemoteResources(archive);
   callback.onCheckResources();
   callback.onMatchedFileNames(knownRemoteResources.getFilenames());
   UploadApplicationPayload payload = new UploadApplicationPayload(archive, knownRemoteResources);
   callback.onProcessMatchedResources(payload.getTotalUncompressedSize());
   HttpEntity<?> entity = generatePartialResourceRequest(payload, knownRemoteResources);
   String url = getUrl("apps/{appName}/application");
   try {
     getRestTemplate().put(url, entity, appName);
   } catch (HttpServerErrorException hsee) {
     if (HttpStatus.INTERNAL_SERVER_ERROR.equals(hsee.getStatusCode())) {
       // this is for supporting legacy Micro Cloud Foundry 1.1 and older
       uploadAppUsingLegacyApi(url, entity, appName);
     } else {
       throw hsee;
     }
   }
 }
 @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;
 }
 /**
  * 处理服务器端其他错误
  *
  * @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);
 }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
  @ExceptionHandler(Exception.class)
  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  public ModelAndView handleServerErrors(Exception ex) {

    logger.error(ex.getMessage(), ex);
    if (logger.isDebugEnabled()) {
      logger.debug("An exception has been thrown");
    }
    return new ModelAndView(
        jsonView,
        "error",
        new MessageResponse(HttpStatus.INTERNAL_SERVER_ERROR.name(), ex.getMessage()));
  }
  @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;
    }
  }
Exemplo n.º 9
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());
   }
 }
  @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))));
  }