Skip to content

Commit

Permalink
[SHIBUI-580]
Browse files Browse the repository at this point in the history
Added a simple POJO for transmitting errors from custom exception handlers.
Added a custom exception handler for when bad things happen when parsing JSON Resolvers.
Fixed a couple typos.
  • Loading branch information
Bill Smith committed Jul 5, 2018
1 parent 382294a commit 07c7e9f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.internet2.tier.shibboleth.admin.ui.controller;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
* @author Bill Smith (wsmith@unicon.net)
*/
@AllArgsConstructor
@Getter
@Setter
@ToString
public class ErrorResponse {
private String errorCode;
private String errorMessage;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package edu.internet2.tier.shibboleth.admin.ui.controller;

import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolver;
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolverValidationService;
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolverValidator;
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -19,6 +20,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.io.IOException;
import java.net.URI;

import static edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolverValidator.ValidationResult;
Expand All @@ -34,6 +36,11 @@ public class MetadataResolversController {
@Autowired
MetadataResolverValidationService metadataResolverValidationService;

@ExceptionHandler({InvalidTypeIdException.class, IOException.class, HttpMessageNotReadableException.class})
public ResponseEntity<?> unableToParseJson(Exception ex) {
return ResponseEntity.badRequest().body(new ErrorResponse(HttpStatus.BAD_REQUEST.toString(), ex.getMessage()));
}

@GetMapping("/MetadataResolvers")
@Transactional(readOnly = true)
public ResponseEntity<?> getAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* A facade that aggregates {@link MetadataResolverValidator}s available to call just one of them supporting the type of a given resolver.
* If no {@link MetadataResolverValidator}s are configured, conciders provided MetadataResolver as valid.
* If no {@link MetadataResolverValidator}s are configured, considers provided MetadataResolver as valid.
* <p>
* Uses chain-of-responsibility design pattern
*
Expand All @@ -22,7 +22,7 @@ public MetadataResolverValidationService(List<MetadataResolverValidator<T>> vali
this.validators = validators != null ? validators : new ArrayList<>();
}

@SuppressWarnings("Uncheked")
@SuppressWarnings("Unchecked")
public ValidationResult validateIfNecessary(T metadataResolver) {
Optional<MetadataResolverValidator<T>> validator =
this.validators
Expand Down

0 comments on commit 07c7e9f

Please sign in to comment.