Java library for representing, parsing and encoding URNs as in RFC2141 and RFC8141

Overview

urnlib

Build Status Coverage Status Maven Central

Java library for representing, parsing and encoding URNs as specified in RFC 2141 and RFC 8141.

The initial URN RFC 2141 of May 1997 was superseeded by RFC 8141 in April 2017. RFC 8141 added support for path characters and optional request, query and fragment parts. While URNs look very similiar to URIs and are somewhat related, different equality rules apply for URNs in regard to URN character encoding rules. Also some synactic rules about case-insensitivity are actually to be defined by the implementing system handling the URNs.

This library provides classes for representing, parsing and constructing an Uniform Resource Name (URN) and its parts Namespace Identifier (NID), Namespace Specific String (NSS) and optional Resolution, Query and Fragment components (RQF). If you don't need RFC 2141 URNs explicitly, always use RFC 8141 URNs because that is the current valid specification and RFC 8141 is backward compatible to RFC 2141.

Further it defines and interface de.slub.urn.URNResolver for URN resolving implementations.

The library is compiled for Java 7.

Usage

import de.slub.urn.URN;
import de.slub.urn.URNSyntaxError;
import de.slub.urn.URN_8141;

import static de.slub.urn.RFC.RFC_8141;

class Demo {
    public void foo() throws URNSyntaxException {
        // Create a RFC 2141 compliant URN (not recommended)
        URN urn1 = URN.rfc2141().parse("urn:examle:1234");

        // Create a RFC 8141 compliant URN (recommended)
        URN urn2 = URN.rfc8141().parse("urn:examle:foo/1234?=cq=cz#bar");

        // Access fragment part of a supposedly RFC 8141 compliant URN
        if (urn2.supports(RFC_8141)) {
            String fragment = ((URN_8141) urn2).getRQFComponents().fragment();
        }
    }
}

Where to find releases?

The master branch of the repository contains the latest developments. Releases are tagged. There are two ways of getting releases of this library. Binaries are obtained through Maven dependencies. Sources via the GitHub Releases download section.

The recommended way is by declaring a dependency, for example in your projects POM file:

<dependency>
  <groupId>de.slub-dresden</groupId>
  <artifactId>urnlib</artifactId>
  <version>[2.0,2.1)</version>
</dependency>

Licensing

The source code is under GNU GENERAL PUBLIC LICENSE, Version 3 (or later) as stated in the source file headers. So if you want to use the source code or a changed version, the source code and the source code using it is automatically licensed under this license.

The binaries (JAR artifacts) however are licensed under The Apache License, Version 2.0 and can be used in commercial products without any licensing changes to that product.

Comments
  • Fix failure to parse r-component when q- or f- component also specified

    Fix failure to parse r-component when q- or f- component also specified

    This pull request fixes #13. Rather than using a mixture of indexOf and regular expressions, we've gone wholesale with an approach that extracts substrings between specified delimiters. The resulting code is shorter and hopefully more performant (regexes being slow, but we haven't actually benchmarked things!). Note that this will only work if the RQF components are used in this exact order, as described in the RFC 8141 spec.

    We've accompanied the revised implementation with two unit tests that would have failed with the original code.

    Thanks to @danielthepope for pairing on this task. Thanks in advance for reading!

    bug 
    opened by PyvesB 8
  • Consider changing to LGPL (or anything less restrictive than GPL)

    Consider changing to LGPL (or anything less restrictive than GPL)

    The GNU General Public License v3.0 imposes conditions on any software integrating a GPL license artifact which are rarely compatible with commercial software.

    Switching to LGPL (GNU Lesser General Public License) would broaden the number of projects in which this library can be used.

    enhancement 
    opened by rnavarropiris 6
  • Make library RFC8141 compliant

    Make library RFC8141 compliant

    Please note in April 2017 the URN RFC was updated. See RFC8141. Major differences, see Wikipedia:

    The slash character (/) is now allowed in the NSS to represent names containing slashes from non-URN identifier systems. The q-component was added to enable passing of parameters to named resources. The r-component was added to enable passing of parameters to resolvers. However, the updated specification notes that the r-component should not be used until its semantics are defined via further standardization.

    enhancement 
    opened by buko 6
  • Justify ignored exception

    Justify ignored exception

    An exception is silently catched without explanation: source

    My guess is the exception "cannot happen", but a brief explanation (in the form of an in-line comment) would be nice :)

    enhancement 
    opened by rnavarropiris 2
  • Publish at maven central, jCenter or whatever is best

    Publish at maven central, jCenter or whatever is best

    Looks like maven central does not play such a central role for Java like CPAN does for Perl, npm for JavaScript or Composer for PHP but I would not like to reuse a module that is not published in such a repository.

    opened by nichtich 2
  • Invalid URN hashCode implementation

    Invalid URN hashCode implementation

    According to the Java specification for hashCode:

    If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

    This true for URN_2141 objects but not for URN_8141 objects. Indeed, the two following URNs are equal but produce different hashCodes:

    URN.rfc8141().parse("urn:example:foo-bar-baz-qux?+CCResolve:cc=uk?=op=map#somepart"); 
    URN.rfc8141().parse("urn:example:foo-bar-baz-qux");
    

    This is due to the fact that hashCode, which calls toString in the current implementation, takes the RQF components into account, whereas equals does not.

    According to RFC 8141, RQF components should not be taken into account for URN-equivalence, so I suggest changing `hashCode's implementation to reflect this. We're happy to contribute this fix! ๐Ÿ‘

    bug 
    opened by PyvesB 1
  • Library fails to parse URNs with both R and Q components

    Library fails to parse URNs with both R and Q components

    We've identified an issue where, if a URN contains both an r- and a q- component, the library fails to parse the r-component correctly.

    urn:example:foo?+key=value?=fizz=buzz says the r-component is key= (value is empty string). We believe there is an issue with the regular expression that is trying to extract the r-component.

    The issue also occurs when the URN contains a f-component, either with or without the q-component.

    bug 
    opened by danielthepope 1
  • URN.create method that throws an IllegalArgumentException

    URN.create method that throws an IllegalArgumentException

    This library is good stuff. Thank you for creating it. ๐Ÿฅ‡

    One minor issue: very often we need to define URNs as static constants in a class. Doing so isn't easy because there's no way to create a URN that doesn't raise an exception (even though we know the URN is a perfectly valid URN). There should be a method similar to URI#create. This method should wrap the URNSyntaxException and raise an IllegalArgumentException. That would make it possible to define URNs as a static constant:

     public static final URN EXAMPLE_URN = URN.create("urn:example:example");
    
    enhancement 
    opened by buko 1
  • Empty NSS parts schould not be allowed

    Empty NSS parts schould not be allowed

    The syntax description for URN NSS parts doesn't allow for NSS parts to be empty. Currently this is considered a valid URN: urn:foo:::::bar.

    According to NSS part syntax NSS should have at least one character.

    See ABNF for RFCs on this: https://tools.ietf.org/html/rfc5234#page-9

    bug invalid 
    opened by claussni 1
  • Bump junit from 4.12 to 4.13.1

    Bump junit from 4.12 to 4.13.1

    Bumps junit from 4.12 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Fix TravisCI build problems

    Fix TravisCI build problems

    TravisCI seems to have stopped supporting OpenJDK 7 and OracleJDK 8. Adjust .travis.yaml file.

    https://travis-ci.community/t/oraclejdk-7-not-supported-on-precise/3643

    enhancement 
    opened by claussni 0
  • Information request: about de.slub.urn.RQF_RFC8141.initialToString()

    Information request: about de.slub.urn.RQF_RFC8141.initialToString()

    Hello,

    I wonder if it's normal that de.slub.urn.RQF_RFC8141.initialToString() concat q and r component without & ?

    If it's not, do you like a p.rย ?

    Thanks in advance.

    opened by floriangasc 0
  • hexadecimal values according to RFC 4198

    hexadecimal values according to RFC 4198

    I'm using urnlib for handling URNs according to RFC 4198. RFC 4198 describes, that RessourceIds, part of Namespacespecific part of a URN, can be in a hexadecimal format, starting with a "%" (Chapter 3 Specification Template). Since I address the content via SHA-1 hashes, this part of the specification is relevant to me. Typically, a FDC URN in my case looks like: urn:fdc:127.0.0.1:20220902:%FFFF When I save this urn in a file via urn.toString() the result looks like: urn:fdc:127.0.0.1:20220902:%ffFF. It's a source of incompatibility, if these URNs are used by other tools. I think, urnlib detects a URL Encoded string, because of the existence of %. Could you please have a look at that?

    opened by indika-dev 0
  • Drop RFC 2141 support

    Drop RFC 2141 support

    Since RFC 8141 is backward compatible to RFC 2141 and succeeds the old RFC, code supporting RFC 2141 can be removed in further major releases in order to clear up the API.

    enhancement 
    opened by claussni 0
Releases(v2.0.1)
Owner
SLUB
Saxon State and University Library Dresden
SLUB
Telegram API Client and Telegram BOT API Library and Framework in Pure java.

Javagram Telegram API Client and Telegram Bot API library and framework in pure Java. Hello Telegram You can use Javagram for both Telegram API Client

Java For Everything 3 Oct 17, 2021
An annotation-based Java library for creating Thrift serializable types and services.

Drift Drift is an easy-to-use, annotation-based Java library for creating Thrift clients and serializable types. The client library is similar to JAX-

null 225 Dec 24, 2022
A Java library for capturing, crafting, and sending packets.

Japanese Logos Pcap4J Pcap4J is a Java library for capturing, crafting and sending packets. Pcap4J wraps a native packet capture library (libpcap, Win

Kaito Yamada 1k Dec 30, 2022
Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.

Socket.IO-client Java This is the Socket.IO Client Library for Java, which is simply ported from the JavaScript client. See also: Android chat demo en

Socket.IO 5k Jan 4, 2023
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Dec 31, 2022
TCP/UDP client/server library for Java, based on Kryo

KryoNet can be downloaded on the releases page. Please use the KryoNet discussion group for support. Overview KryoNet is a Java library that provides

Esoteric Software 1.7k Jan 2, 2023
Unconventional I/O library for Java

one-nio one-nio is a library for building high performance Java servers. It features OS capabilities and JDK internal APIs essential for making your h

OK.ru 589 Dec 29, 2022
๐Ÿงšโ€โ™€๏ธ Java library to interact with YouTrack's REST API.

YouTrack API for Java ??โ€ Java library to interact with YouTrack's REST API.

Noel 2 Oct 1, 2021
An netty based asynchronous socket library for benchion java applications

Benchion Sockets Library An netty based asynchronous socket library for benchion java applications ?? Documents ?? Report Bug ยท Request Feature Conten

Fitchle 3 Dec 25, 2022
A High Performance Network ( TCP/IP ) Library

Chronicle-Network About A High Performance Network library Purpose This library is designed to be lower latency and support higher throughputs by empl

Chronicle Software : Open Source 231 Dec 31, 2022
Simple & Lightweight Netty packet library + event system

Minimalistic Netty-Packet library Create packets with ease Bind events to packets Example Packet: public class TestPacket extends Packet { privat

Pierre Maurice Schwang 17 Dec 7, 2022
A Minecraft library for working with minecraft packets on various platforms, using MCProtocolLib

BetterProtocol A Minecraft library for working with minecraft packets on various platforms, using MCProtocolLib This library is still based on the pro

John 8 Jul 2, 2022
Library for composability of interdependent non-blocking I/O tasks

Composer Composer helps you to organize and execute multiple interdependent asynchronous input/output tasks such as webservice calls, database read/wr

krupal 19 Oct 8, 2021
This is library that look like Scarlet Wrapper Socket.io

This is library that look like Scarlet Wrapper Socket.io

Adkhambek 8 Jan 2, 2023
Socket.IO server implemented on Java. Realtime java framework

Netty-socketio Overview This project is an open-source Java implementation of Socket.IO server. Based on Netty server framework. Checkout Demo project

Nikita Koksharov 6k Dec 30, 2022
ssh, scp and sftp for java

sshj - SSHv2 library for Java To get started, have a look at one of the examples. Hopefully you will find the API pleasant to work with :) Getting SSH

Jeroen van Erp 2.2k Jan 8, 2023
API gateway for REST and SOAP written in Java.

API gateway for REST and SOAP written in Java.

predic8 GmbH 389 Dec 31, 2022
A barebones WebSocket client and server implementation written in 100% Java.

Java WebSockets This repository contains a barebones WebSocket server and client implementation written in 100% Java. The underlying classes are imple

Nathan Rajlich 9.5k Dec 30, 2022
A Java event based WebSocket and HTTP server

Webbit - A Java event based WebSocket and HTTP server Getting it Prebuilt JARs are available from the central Maven repository or the Sonatype Maven r

null 808 Dec 23, 2022