PeppolURLProvider implements IPeppolURLProvider { @Nonnull public String getDNSNameOfParticipant (@Nonnull final IParticipantIdentifier aParticipantIdentifier, @Nullable final String sSMLZoneName) throws SMPDNSResolutionException { ValueEnforcer.notNull (aParticipantIdentifier, "ParticipantIdentifier"); if (StringHelper.hasText (sSMLZoneName) && !StringHelper.endsWith (sSMLZoneName, '.')) throw new SMPDNSResolutionException ("if an SML zone name is specified, it must end with a dot (.). Value is: " + sSMLZoneName); final String sIdentifierScheme = StringHelper.getNotNull (aParticipantIdentifier.getScheme ()).toLowerCase (URL_LOCALE); if (!PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierSchemeValid (sIdentifierScheme)) if (LOGGER.isWarnEnabled ()) LOGGER.warn ("Invalid Peppol participant identifier scheme '" + sIdentifierScheme + "' used"); final String sValue = StringHelper.getNotNull (aParticipantIdentifier.getValue ()); final StringBuilder ret = new StringBuilder (); if ("*".equals (sValue)) { ret.append ("*."); } else { ret.append (PeppolIdentifierHelper.DNS_HASHED_IDENTIFIER_PREFIX) .append (getHashValueStringRepresentation (sValue.toLowerCase (URL_LOCALE))) .append ('.'); } if (!sIdentifierScheme.isEmpty ()) ret.append (sIdentifierScheme).append ('.'); if (StringHelper.hasText (sSMLZoneName)) { ret.append (sSMLZoneName); } ret.deleteCharAt (ret.length () - 1); return ret.toString (); } PeppolURLProvider(); @Nonnull static String getHashValueStringRepresentation(@Nonnull final String sValueToHash); @Nonnull String getDNSNameOfParticipant(@Nonnull final IParticipantIdentifier aParticipantIdentifier,
                                         @Nullable final String sSMLZoneName); static final PeppolURLProvider MUTABLE_INSTANCE; static final IPeppolURLProvider INSTANCE; static final Charset URL_CHARSET; static final Locale URL_LOCALE; }
@Test @SuppressFBWarnings ("NP_NONNULL_PARAM_VIOLATION") public void testGetDNSNameOfParticipant () throws SMPDNSResolutionException { assertEquals ("B-f5e78500450d37de5aabe6648ac3bb70.iso6523-actorid-upis.edelivery.tech.ec.europa.eu", INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("0088:123abc"), ESML.DIGIT_PRODUCTION)); assertEquals ("B-f5e78500450d37de5aabe6648ac3bb70.iso6523-actorid-upis.edelivery.tech.ec.europa.eu", INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("0088:123ABC"), ESML.DIGIT_PRODUCTION)); assertEquals ("B-85008b8279e07ab0392da75fa55856a2.iso6523-actorid-upis.acc.edelivery.tech.ec.europa.eu", INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("9915:test"), ESML.DIGIT_TEST)); assertEquals ("B-f5e78500450d37de5aabe6648ac3bb70.edelivery.tech.ec.europa.eu", INSTANCE.getDNSNameOfParticipant (SimpleIdentifierFactory.INSTANCE.createParticipantIdentifier (null, "0088:123abc"), ESML.DIGIT_PRODUCTION)); assertEquals ("B-d41d8cd98f00b204e9800998ecf8427e.iso6523-actorid-upis.edelivery.tech.ec.europa.eu", INSTANCE.getDNSNameOfParticipant (SimpleIdentifierFactory.INSTANCE.createParticipantIdentifier (PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, null), ESML.DIGIT_PRODUCTION)); assertEquals ("B-d41d8cd98f00b204e9800998ecf8427e.edelivery.tech.ec.europa.eu", INSTANCE.getDNSNameOfParticipant (SimpleIdentifierFactory.INSTANCE.createParticipantIdentifier (null, null), ESML.DIGIT_PRODUCTION)); assertEquals ("B-d41d8cd98f00b204e9800998ecf8427e", INSTANCE.getDNSNameOfParticipant (SimpleIdentifierFactory.INSTANCE.createParticipantIdentifier (null, null), (String) null)); assertEquals ("*.iso6523-actorid-upis.edelivery.tech.ec.europa.eu", INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("*"), ESML.DIGIT_PRODUCTION)); assertEquals ("B-f5e78500450d37de5aabe6648ac3bb70.iso6523-actorid-upis", INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("0088:123ABC"), (String) null)); assertEquals ("B-f5e78500450d37de5aabe6648ac3bb70.iso6523-actorid-upis", INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("0088:123ABC"), "")); assertEquals ("B-f5e78500450d37de5aabe6648ac3bb70.iso6523-actorid-upis.at", INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("0088:123ABC"), "at.")); if (false) LOGGER.info (INSTANCE.getDNSNameOfParticipant (IF.createParticipantIdentifierWithDefaultScheme ("9915:b"), ESML.DIGIT_PRODUCTION)); try { INSTANCE.getDNSNameOfParticipant (null, "anyzone.org."); fail (); } catch (final NullPointerException ex) { } try { INSTANCE.getDNSNameOfParticipant (new SimpleParticipantIdentifier ("scheme", "value"), "anyzone"); fail (); } catch (final SMPDNSResolutionException ex) { } }