The project contains two OSGi bundles that provide online EU VAT number validation with VAT Information Exchange System (VIES).
vat-checker-api.jar
- Java model for VIES APIvat-checker-service.jar
- service client that uses classes generated from WSDL published by VIES
Bundle offers simple Java service interface:
package org.synus.vies.api;
public interface VatChecker {
VatCheckerResult checkVat(Country country, String vatNumber);
The implementation catches all exceptions (logs them with slf4j) and always returns a result instance of type:
// ...
public class VatCheckerResult {
private final Country country;
private final String vatNumber;
private final Optional<LocalDateTime> requestDate;
private final boolean valid;
private final Optional<String> name;
private final Optional<String> address;
private final Optional<VatCheckerError> error;
// ...
Returned VatCheckerResult
instance can be in following states:
- VAT valid:
valid=true
- VAT invalid:
valid=false
anderror
is empty - VAT checker error:
valid=false
anderror
has enum valuepublic enum VatCheckerError { INVALID_INPUT, INVALID_REQUESTER_INFO, SERVICE_UNAVAILABLE, MS_UNAVAILABLE, TIMEOUT, VAT_BLOCKED, IP_BLOCKED, GLOBAL_MAX_CONCURRENT_REQ, GLOBAL_MAX_CONCURRENT_REQ_TIME, MS_MAX_CONCURRENT_REQ, MS_MAX_CONCURRENT_REQ_TIME, UNEXPECTED, }
Build and install both api and implementation jars on your osgi container.
$ ./gradlew build # to build both jars jar
$ cp vat-checker-api/build/libs/vat-checker-api-1.0.0.jar $MY_OSGI_CONTAINER
$ cp vat-checker-service/build/libs/vat-checker-service-1.0.0.jar $MY_OSGI_CONTAINER
build.gradle
:
dependencies {
compileOnly 'org.synus.vies:vat-checker-api:1.0.0'
}
@Component(
property = {"osgi.command.function=checkvat", "osgi.command.scope=blade"},
service = Object.class
)
public class ExampleCommand {
@Reference
private volatile VatChecker vatChecker;
public void checkvat(String country, String vatNumber) {
System.out.println(vatChecker.checkVat(Country.valueOf(country), vatNumber).isValid());
}
}
$ telnet localhost 11311
Welcome to Apache Felix Gogo
g! checkvat "SK" "2020216748"
true
Want to hack on vat-checker? See CONTRIBUTING.md for information on building, testing and contributing changes.
They are probably not perfect, please let me know if anything feels wrong or incomplete.
The contents of this repository are made available to the public under the terms of the Apache License, Version 2.0. Bundles may depend on non Apache Licensed code.