-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Customizing Cloudevents validation
Signed-off-by: vbhat6 <[email protected]>
- Loading branch information
vbhat6
committed
Feb 7, 2024
1 parent
f1e1f96
commit 982d4ae
Showing
6 changed files
with
90 additions
and
91 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
core/src/main/java/io/cloudevents/core/provider/CloudEventValidatorProvider.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,70 @@ | ||
/* | ||
* Copyright 2018-Present The CloudEvents Authors | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 io.cloudevents.core.provider; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.core.validator.CloudEventValidator; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceConfigurationError; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* CloudEventValidatorProvider is a singleton class which loads and access CE Validator service providers on behalf of service clients. | ||
*/ | ||
public class CloudEventValidatorProvider { | ||
|
||
private static CloudEventValidatorProvider cloudEventValidatorProvider; | ||
|
||
private ServiceLoader<CloudEventValidator> loader; | ||
|
||
private CloudEventValidatorProvider(){ | ||
loader = ServiceLoader.load(CloudEventValidator.class); | ||
} | ||
|
||
public static synchronized CloudEventValidatorProvider getInstance(){ | ||
if(cloudEventValidatorProvider == null){ | ||
cloudEventValidatorProvider = new CloudEventValidatorProvider(); | ||
} | ||
return cloudEventValidatorProvider; | ||
} | ||
|
||
/** | ||
* iterates through available Cloudevent validators. | ||
* @param cloudEvent | ||
*/ | ||
public void validate(CloudEvent cloudEvent){ | ||
try{ | ||
// | ||
Iterator<CloudEventValidator> validatorIterator = loader.iterator(); | ||
while (validatorIterator.hasNext()){ | ||
CloudEventValidator validator = validatorIterator.next(); | ||
validator.validate(cloudEvent); | ||
|
||
} | ||
} catch (ServiceConfigurationError serviceError) { | ||
|
||
serviceError.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
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
17 changes: 17 additions & 0 deletions
17
core/src/main/java/io/cloudevents/core/validator/CloudEventValidator.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
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
11 changes: 0 additions & 11 deletions
11
core/src/test/java/io/cloudevents/core/v1/CustomCloudEventValidator.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
core/src/test/java/io/cloudevents/core/v1/CustomCloudEventValidatorImpl.java
This file was deleted.
Oops, something went wrong.