Example usage for org.springframework.http HttpStatus PRECONDITION_FAILED

List of usage examples for org.springframework.http HttpStatus PRECONDITION_FAILED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus PRECONDITION_FAILED.

Prototype

HttpStatus PRECONDITION_FAILED

To view the source code for org.springframework.http HttpStatus PRECONDITION_FAILED.

Click Source Link

Document

412 Precondition failed .

Usage

From source file:com.netflix.genie.web.controllers.GenieExceptionMapperUnitTests.java

/**
 * Test method argument not valid exceptions.
 *
 * @throws IOException on error/*from w  w  w.  jav  a 2 s.  c  om*/
 */
@Test
@SuppressFBWarnings(value = "DM_NEW_FOR_GETCLASS", justification = "It's needed for the test")
public void canHandleMethodArgumentNotValidExceptions() throws IOException {
    // Method is a final class so can't mock it. Just use the current method.
    final Method method = new Object() {
    }.getClass().getEnclosingMethod();
    final MethodParameter parameter = Mockito.mock(MethodParameter.class);
    Mockito.when(parameter.getMethod()).thenReturn(method);

    final BindingResult bindingResult = Mockito.mock(BindingResult.class);
    Mockito.when(bindingResult.getAllErrors()).thenReturn(Lists.newArrayList());

    final MethodArgumentNotValidException exception = new MethodArgumentNotValidException(parameter,
            bindingResult);

    this.mapper.handleMethodArgumentNotValidException(this.response, exception);
    Mockito.verify(this.response, Mockito.times(1))
            .sendError(Mockito.eq(HttpStatus.PRECONDITION_FAILED.value()), Mockito.anyString());
    Mockito.verify(counterId, Mockito.times(1)).withTag(MetricsConstants.TagKeys.EXCEPTION_CLASS,
            exception.getClass().getCanonicalName());
    Mockito.verify(counter, Mockito.times(1)).increment();
}

From source file:de.zib.gndms.gndmc.dspace.Test.SliceClientTest.java

@Test(groups = { "sliceServiceTest" }, dependsOnMethods = { "testCreateSubspace" })
public void testCreateSliceKind() {
    try {/*from w  ww.  j a  v  a 2 s  . com*/
        final ResponseEntity<Specifier<Void>> sliceKind = subspaceClient.createSliceKind(subspaceId,
                sliceKindId, sliceKindConfig, admindn);
        Assert.assertNotNull(sliceKind);
        Assert.assertEquals(sliceKind.getStatusCode(), HttpStatus.CREATED);
    } catch (HttpClientErrorException e) {
        if (!e.getStatusCode().equals(HttpStatus.PRECONDITION_FAILED)) // already exists from last test?
            throw e;
    }

    final ResponseEntity<List<Specifier<Void>>> listResponseEntity = subspaceClient.listSliceKinds(subspaceId,
            admindn);
    final List<Specifier<Void>> specifierList = listResponseEntity.getBody();

    for (Specifier<Void> s : specifierList) {
        if (!s.getUriMap().containsKey(UriFactory.SLICE_KIND))
            continue;
        if (s.getUriMap().get(UriFactory.SLICE_KIND).equals(sliceKindId))
            return;
    }

    throw new IllegalStateException(
            "The created SliceKind " + sliceKindId + " could not be found in SliceKindListing");
}

From source file:com.sothawo.taboo2.Taboo2Service.java

/**
 * ExceptionHandler for IllegalArgumentException. returns the exception's error message in the body with the 412
 * status code./* ww w.  ja v a  2 s.co  m*/
 *
 * @param e
 *         the exception to handle
 * @return HTTP PRECONDITION_FAILED Response Status and error message
 */
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.PRECONDITION_FAILED)
public final String exceptionHandlerIllegalArgumentException(final IllegalArgumentException e) {
    return '"' + e.getMessage() + '"';
}

From source file:alfio.controller.api.admin.CheckInApiController.java

@RequestMapping(value = "/check-in/{eventName}/label-layout", method = GET)
public ResponseEntity<LabelLayout> getLabelLayoutForEvent(@PathVariable("eventName") String eventName,
        Principal principal) {//  www.  j ava2s.  c o m
    return optionally(() -> eventManager.getSingleEvent(eventName, principal.getName()))
            .filter(checkInManager.isOfflineCheckInAndLabelPrintingEnabled()).map(this::parseLabelLayout)
            .orElseGet(() -> new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED));
}

From source file:de.zib.gndms.dspace.service.SubspaceServiceImpl.java

@Override
@RequestMapping(value = "/_{subspaceId}/_{slicekindId}", method = RequestMethod.PUT)
@Secured("ROLE_ADMIN")
public ResponseEntity<Specifier<Void>> createSliceKind(@PathVariable final String subspaceId,
        @PathVariable final String slicekindId, @RequestBody final String config,
        @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = getSubspaceHeaders(subspaceId, dn);

    if (!subspaceProvider.exists(subspaceId)) {
        logger.info("Illegal Access: subspace " + subspaceId + " not found");
        return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.NOT_FOUND);
    }//from  w  w w  . ja v a 2  s. c  om
    if (slicekindProvider.exists(subspaceId, slicekindId)) {
        logger.info("Illegal Access: slicekind " + slicekindId
                + " could not be created because it already exists.");
        return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.PRECONDITION_FAILED);
    }

    // TODO: catch creation errors and return appropriate HttpStatus
    slicekindProvider.create(slicekindId, "subspace:" + subspaceId + "; " + config);

    // generate specifier and return it
    Specifier<Void> spec = new Specifier<Void>();

    HashMap<String, String> urimap = new HashMap<String, String>(2);
    urimap.put(UriFactory.SERVICE, "dspace");
    urimap.put(UriFactory.SUBSPACE, subspaceId);
    urimap.put(UriFactory.SLICE_KIND, slicekindId);
    urimap.put(UriFactory.BASE_URL, baseUrl);
    spec.setUriMap(new HashMap<String, String>(urimap));
    spec.setUrl(uriFactory.sliceKindUri(urimap, null));

    return new ResponseEntity<Specifier<Void>>(spec, headers, HttpStatus.CREATED);
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractChannelController.java

@RequestMapping(value = ("/createchannel"), method = RequestMethod.GET)
public String createChannel(ModelMap map, HttpServletResponse response) {
    logger.debug("### createChannel method starting...(GET)");
    // Add precondition
    if (!channelService.isChannelCreationAllowed()) {
        response.setStatus(HttpStatus.PRECONDITION_FAILED.value());
        logger.debug("### createChannel(GET) method ending. PreConditions failed.");
        return null;
    }// www .  j  a  v a 2 s .  c  o  m
    map.addAttribute("channels", channelService.getChannels(null, null, null));
    map.addAttribute("currencies", currencyValueService.listActiveCurrencies());

    logger.debug("### createChannel method end...(GET)");
    return "channels.create";
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractBillingController.java

@RequestMapping(value = "/editcreditcarddetails", method = RequestMethod.POST)
public ModelMap editCreditCard(@RequestParam(value = "tenant", required = false) String tenantParam,
        @ModelAttribute("billingInfo") BillingInfoForm form, HttpServletResponse response,
        HttpServletRequest request, ModelMap map) throws IOException {
    logger.debug("###Entering in edit(tenantId, billingAddress,response) method @POST");

    Tenant effectiveTenant = tenantService.get(tenantParam);
    map.addAttribute("tenant", effectiveTenant);
    try {//from  w w  w.j a  v  a2  s . com
        map.addAttribute("isAccountExistInPaymentGateway",
                ((PaymentGatewayService) connectorManagementService
                        .getOssServiceInstancebycategory(ConnectorType.PAYMENT_GATEWAY))
                                .isAccountExistInPaymentGateway(effectiveTenant));
        CreditCard creditCard = form.getCreditCard();
        billingService.editCreditCard(effectiveTenant, creditCard, getRemoteUserIp(request),
                request.getLocale(), getCurrentUser());
    } catch (CreditCardFraudCheckException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        throw new InvalidAjaxRequestException(ex.getMessage());
    } catch (PaymentGatewayServiceException e) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        throw new InvalidAjaxRequestException(e.getMessage());
    } catch (BillingServiceException e) {
        response.setStatus(HttpStatus.PRECONDITION_FAILED.value());
        throw new InvalidAjaxRequestException(e.getMessage());
    } catch (Exception e) {
        logger.error("Got Exception while updating billing info : ", e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        throw new InvalidAjaxRequestException(messageSource
                .getMessage("ui.usage.billing.paymentinfo.cc.edit.errormsg", null, getSessionLocale(request)));
    }
    String redirectToURL = "/portal/portal/tenants/editcurrent?action=showcreditcardtab&tenant=" + tenantParam;
    map.put("redirecturl", redirectToURL);
    String message = "billing.info.updated";
    String messageArgs = effectiveTenant.getName();
    eventService.createEvent(new Date(), effectiveTenant, message, messageArgs, Source.PORTAL, Scope.ACCOUNT,
            Category.ACCOUNT, Severity.INFORMATION, true);
    return map;
}