NUM Java library

Java library for the NUM protocol

License

License

Categories

Categories

Java Languages CLI User Interface
GroupId

GroupId

uk.num
ArtifactId

ArtifactId

num-java-client-lib
Last Version

Last Version

0.12.13
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

NUM Java library
Java library for the NUM protocol
Project URL

Project URL

https://github.com/NUMtechnology/num-java-client-lib
Source Code Management

Source Code Management

https://github.com/NUMtechnology/num-java-client-lib

Download num-java-client-lib

Dependencies

compile (7)

Group / Artifact Type Version
uk.modl : java-interpreter jar 0.1.21
uk.num : num-java-client-lib-base jar 0.1.5
dnsjava : dnsjava jar 3.3.1
org.apache.logging.log4j : log4j-core jar 2.13.0
org.projectlombok : lombok jar 1.18.4
commons-io : commons-io jar 2.6
antlr : antlr jar 2.7.7

Project Modules

There are no modules declared in this project.

NUM Java Client Library

A Java client for the NUM protocol - making NUM protocol adoption in Java a cinch.

See the full Specification at num.uk and the Explainer for more information.

The NUM protocol supports a range of modules that add rich functionality in an extensible way.

The NUM URI Scheme

The NUM protocol uses the familiar URL format for its URIs and allows modules to interpret data in a variety of ways.

The data stored in a NUM Record is converted to JSON String format that can be parsed into JSON objects and Java objects for straightforward incorporation into Java programs. Here are some example NUM URIs with module 1 - the Contacts module. The default module is 0 (zero) if no module is specified, which has no module schema.

As you can see from the examples above, data can be associated with domains and email addresses, and can be organised hierarchically if desired. In future, the protocol will support more than just domains and email addresses.

Additional modules can be referenced in the same way as ports in other URIs:

  • num://numexample.com:2 for the WhoHas module.
  • num://numexample.com:3 for the Images module.
  • num://numexample.com:4 for the Custodians module.
  • num://numexample.com:5 for the Payments module.
  • num://numexample.com:6 for the Regulatory module.
  • num://numexample.com:7 for the Public Key module.
  • num://numexample.com:8 for the Intellectual Property module.
  • num://numexample.com:9 for the Terms module.
  • num://numexample.com:10 for the Bugs module.
  • num://numexample.com:nn for your own module?

Adding Support for the NUM Protocol

The NUM protocol library is available in the Maven Repository.

Building with Gradle

compile 'uk.num:num-java-client-lib:1.0.0'

Building with Maven

<!-- https://mvnrepository.com/artifact/uk.num/num-java-client-lib -->
<dependency>
    <groupId>uk.num</groupId>
    <artifactId>num-java-client-lib</artifactId>
    <version>1.0.0</version>
</dependency>

Java Class Bindings for NUM Modules

Class libraries for the NUM modules will be added in future. The code examples below show what will be possible when these bindings become available. In the meantime the generic JSON API of your favourite JSON parser library will have to be used.

Example API Usage

An example without setting NUM protocol parameters

If NUM protocol parameters are not needed then the programming interface is very simple.

// The required query parameters are defined by the module, in this case module 1 - Contacts

    final URL url = NumProtocolSupport.toUrl("num://numexample.com:1/?C=gb&L=en");

// Use Apache Commons IO to load the JSON from DNS

        final String json = IOUtils.toString(url, StandardCharsets.UTF_8);

// Optionally parse the JSON to the required Module class binding

    ContactsModule contactsModule = objectMapper.readValue(json, ContactsModule.class);

// Access the module data using its Java class binding

    List<Organisation> orgs = contactsModule.getOrganisations();
...

An example with setting NUM protocol parameters

Setting NUM protocol parameters is only slightly more verbose.

// The required query parameters are defined by the module, in this case module 1 - Contacts

    final URL url = NumProtocolSupport.toUrl("num://numexample.com:1/?C=gb&L=en");

// Set a flag to trigger the zone populator in case there is no record available.

    final NUMURLConnection connection = new NUMURLConnection(url);

    connection.setRequestProperty(NUMURLConnection.USE_POPULATOR, "true");

// Use Apache Commons IO to load the JSON from DNS

    final String json = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);

// Optionally parse the JSON to the required Module class binding

    ContactsModule contactsModule = objectMapper.readValue(json, ContactsModule.class);

// Access the module data using its Java class binding

    List<Organisation> orgs = contactsModule.getOrganisations();
...

Protocol Parameters

The code example above shows the use of NUM connection properties; the following properties are supported:

  • NUMURLConnection.USE_POPULATOR defaults to "false". When set to "true" if no NUM record is found then the NUM Server will attempt to scrape information to satisfy the query.
  • NUMURLConnection.HIDE_PARAMS defaults to "true" and automatically prefixes query parameters with an underscore so that they do not appear in the JSON output. When set to "false" the parameters are left untouched, each parameter can be hidden manually by prepending with an underscore.

Record Location and DNSSEC Signature Check

When using the NUMURLConnection object there are two additional results available after the NUM record is retrieved:

        final boolean signed = connection.isDnsSecSigned();
        final NumAPICallbacks.Location location = connection.getLocation(); // INDEPENDENT or HOSTED

Logging

The NUM library uses slf4j over Logback for logging, and requires a logback.xml file on the classpath.

uk.num

NUM

Versions

Version
0.12.13
0.12.12
0.12.11
0.12.9
0.12.8
0.12.7
0.12.6
0.12.5
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
0.11.1
0.11.0
0.10.0
0.9.16
0.9.15
0.9.14
0.9.13
0.9.12
0.9.11
0.9.10
0.9.9
0.9.8
0.9.7
0.9.6
0.9.5
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.10
0.0.9
0.0.8
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1