@Test public void malformedUrlProtocol() { assertFalse(FormatUtils.isValidUrl(MALFORMED_PROTOCOL)); }
public static boolean isValidUrl(String url) { boolean hasValidProtocol; boolean hasValidHost; try { hasValidProtocol = isHttpsUrl(url) || url.startsWith(HTTP_PROTOCOL); URL wsdlUrl = new URL(url); String asciiHost = IDN.toASCII(wsdlUrl.getHost()); hasValidHost = asciiHost.matches(URL_HOST_REGEX); } catch (MalformedURLException | IllegalArgumentException e) { return false; } return hasValidProtocol && hasValidHost; }
FormatUtils { public static boolean isValidUrl(String url) { boolean hasValidProtocol; boolean hasValidHost; try { hasValidProtocol = isHttpsUrl(url) || url.startsWith(HTTP_PROTOCOL); URL wsdlUrl = new URL(url); String asciiHost = IDN.toASCII(wsdlUrl.getHost()); hasValidHost = asciiHost.matches(URL_HOST_REGEX); } catch (MalformedURLException | IllegalArgumentException e) { return false; } return hasValidProtocol && hasValidHost; } }
FormatUtils { public static boolean isValidUrl(String url) { boolean hasValidProtocol; boolean hasValidHost; try { hasValidProtocol = isHttpsUrl(url) || url.startsWith(HTTP_PROTOCOL); URL wsdlUrl = new URL(url); String asciiHost = IDN.toASCII(wsdlUrl.getHost()); hasValidHost = asciiHost.matches(URL_HOST_REGEX); } catch (MalformedURLException | IllegalArgumentException e) { return false; } return hasValidProtocol && hasValidHost; } private  FormatUtils(); }
FormatUtils { public static boolean isValidUrl(String url) { boolean hasValidProtocol; boolean hasValidHost; try { hasValidProtocol = isHttpsUrl(url) || url.startsWith(HTTP_PROTOCOL); URL wsdlUrl = new URL(url); String asciiHost = IDN.toASCII(wsdlUrl.getHost()); hasValidHost = asciiHost.matches(URL_HOST_REGEX); } catch (MalformedURLException | IllegalArgumentException e) { return false; } return hasValidProtocol && hasValidHost; } private  FormatUtils(); static OffsetDateTime fromDateToOffsetDateTime(Date date); static Date fromOffsetDateTimeToDate(OffsetDateTime offsetDateTime); static boolean isValidUrl(String url); static boolean isHttpsUrl(String url); static String getServiceFullName(ServiceType serviceType); static String getServiceFullName(WsdlParser.ServiceInfo serviceInfo); static Long parseLongIdOrThrowNotFound(String id); static int countOccurences(String from, char searched); static String xRoadIdToEncodedId(XRoadId xRoadId); static boolean isValidBackupFilename(String filename); static String encodeStringToBase64(String toBeEncoded); }
FormatUtils { public static boolean isValidUrl(String url) { boolean hasValidProtocol; boolean hasValidHost; try { hasValidProtocol = isHttpsUrl(url) || url.startsWith(HTTP_PROTOCOL); URL wsdlUrl = new URL(url); String asciiHost = IDN.toASCII(wsdlUrl.getHost()); hasValidHost = asciiHost.matches(URL_HOST_REGEX); } catch (MalformedURLException | IllegalArgumentException e) { return false; } return hasValidProtocol && hasValidHost; } private  FormatUtils(); static OffsetDateTime fromDateToOffsetDateTime(Date date); static Date fromOffsetDateTimeToDate(OffsetDateTime offsetDateTime); static boolean isValidUrl(String url); static boolean isHttpsUrl(String url); static String getServiceFullName(ServiceType serviceType); static String getServiceFullName(WsdlParser.ServiceInfo serviceInfo); static Long parseLongIdOrThrowNotFound(String id); static int countOccurences(String from, char searched); static String xRoadIdToEncodedId(XRoadId xRoadId); static boolean isValidBackupFilename(String filename); static String encodeStringToBase64(String toBeEncoded); static final String HTTPS_PROTOCOL; static final String HTTP_PROTOCOL; static final String URL_HOST_REGEX; }