Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beansProjectDescription> | ||
<version>1</version> | ||
<pluginVersion><![CDATA[3.9.4.201804120850-RELEASE]]></pluginVersion> | ||
<configSuffixes> | ||
<configSuffix><![CDATA[xml]]></configSuffix> | ||
</configSuffixes> | ||
<enableImports><![CDATA[false]]></enableImports> | ||
<configs> | ||
</configs> | ||
<autoconfigs> | ||
</autoconfigs> | ||
<configSets> | ||
</configSets> | ||
</beansProjectDescription> |
73 changes: 73 additions & 0 deletions
73
src/main/java/uk/org/iay/incommon/validator/api/ApiException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.org.iay.incommon.validator.api; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.joda.time.DateTime; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** | ||
* Exception class for use within the API. | ||
*/ | ||
public class ApiException extends Exception { | ||
|
||
/** Serial version UID. */ | ||
private static final long serialVersionUID = -5046975083822313941L; | ||
|
||
/** HTTP Status to be reported by this exception. */ | ||
private final HttpStatus status; | ||
|
||
/** When the exception was created. */ | ||
private final DateTime when; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param stat HTTP status | ||
* @param msg message | ||
*/ | ||
public ApiException(final HttpStatus stat, final String msg) { | ||
super(msg); | ||
status = stat; | ||
when = DateTime.now(); | ||
} | ||
|
||
/** | ||
* Reuturns the wrapped {@link HttpStatus} value. | ||
* | ||
* @return an {@link HttpStatus} | ||
*/ | ||
public HttpStatus getStatus() { | ||
return status; | ||
} | ||
|
||
/** | ||
* Convert to a {@link Map} so that the data can be turned into | ||
* a JSON response. | ||
* | ||
* @return a new {@link Map} containing the exception information | ||
*/ | ||
public Map<String, Object> toMap() { | ||
final Map<String, Object> m = new HashMap<>(); | ||
m.put("status", Integer.valueOf(getStatus().value())); | ||
m.put("error", getStatus().getReasonPhrase()); | ||
m.put("message", getMessage()); | ||
m.put("exception", getClass().getName()); | ||
m.put("timestamp", when); | ||
return m; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/uk/org/iay/incommon/validator/api/NotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.org.iay.incommon.validator.api; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
/** | ||
* {@link ApiException} representing a "not found" condition. | ||
*/ | ||
public class NotFoundException extends ApiException { | ||
|
||
/** Serial version UID. */ | ||
private static final long serialVersionUID = 424520235843161978L; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param msg message to be included in the exception | ||
*/ | ||
public NotFoundException(final String msg) { | ||
super(HttpStatus.NOT_FOUND, msg); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/uk/org/iay/incommon/validator/api/ValidatorsApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* NOTE: This class is auto generated by the swagger code generator program (2.3.1). | ||
* https://github.com/swagger-api/swagger-codegen | ||
* Do not edit the class manually. | ||
* | ||
* **IAY**: The only changes here from the generated file have been to clean up the imports | ||
* list and to add "throws ApiException" to the validate method. | ||
*/ | ||
package uk.org.iay.incommon.validator.api; | ||
|
||
import java.util.List; | ||
|
||
import javax.validation.Valid; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiParam; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import uk.org.iay.incommon.validator.models.Status; | ||
import uk.org.iay.incommon.validator.models.Validator; | ||
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2018-05-12T13:33:10.546+01:00") | ||
|
||
@Api(value = "validators", description = "the validators API") | ||
public interface ValidatorsApi { | ||
|
||
@ApiOperation(value = "lists available validators", nickname = "getValidators", notes = "Lists all of the available validator pipelines. ", response = Validator.class, responseContainer = "List", tags={ "validation", }) | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 200, message = "list of validator identifiers and descriptions", response = Validator.class, responseContainer = "List") }) | ||
@RequestMapping(value = "/validators", | ||
produces = { "application/json" }, | ||
method = RequestMethod.GET) | ||
ResponseEntity<List<Validator>> getValidators(); | ||
|
||
|
||
@ApiOperation(value = "performs a validation", nickname = "validate", notes = "", response = Status.class, responseContainer = "List", tags={ "validation", }) | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 200, message = "The result of a validation operation is a (possibly empty) array of `Status` objects derived from the `StatusMetadata` instances attached to the item being validated. These may include errors, and it is up to the client to determine what constitues a \"pass\" or \"fail\". ", response = Status.class, responseContainer = "List") }) | ||
@RequestMapping(value = "/validators/{validator_id}/validate", | ||
produces = { "application/json" }, | ||
consumes = { "application/xml+samlmetadata" }, | ||
method = RequestMethod.POST) | ||
ResponseEntity<List<Status>> validate(@ApiParam(value = "An identifier for the validation to be performed. ",required=true) @PathVariable("validator_id") String validatorId,@ApiParam(value = "The metadata to be validated." ,required=true ) @Valid @RequestBody String metadata) | ||
throws ApiException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters