本文整理汇总了Java中org.apache.commons.validator.routines.UrlValidator.ALLOW_LOCAL_URLS属性的典型用法代码示例。如果您正苦于以下问题:Java UrlValidator.ALLOW_LOCAL_URLS属性的具体用法?Java UrlValidator.ALLOW_LOCAL_URLS怎么用?Java UrlValidator.ALLOW_LOCAL_URLS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.validator.routines.UrlValidator
的用法示例。
在下文中一共展示了UrlValidator.ALLOW_LOCAL_URLS属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateURL
public boolean validateURL(String urlToValidate) {
// return FormattedText.validateURL(urlToValidate); // KNL-1105
if (StringUtils.isBlank(urlToValidate)) return false;
if ( ABOUT_BLANK.equals(urlToValidate) ) return true;
// Check if the url is "Escapable" - run through the URL-URI-URL gauntlet
String escapedURL = sanitizeHrefURL(urlToValidate);
if ( escapedURL == null ) return false;
// For a protocol-relative URL, we validate with protocol attached
// RFC 1808 Section 4
if ((urlToValidate.startsWith("//")) && (urlToValidate.indexOf("://") == -1))
{
urlToValidate = PROTOCOL_PREFIX + urlToValidate;
}
// For a site-relative URL, we validate with host name and protocol attached
// SAK-13787 SAK-23752
if ((urlToValidate.startsWith("/")) && (urlToValidate.indexOf("://") == -1))
{
urlToValidate = HOST_PREFIX + urlToValidate;
}
// Validate the url
UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
return urlValidator.isValid(urlToValidate);
}
示例2: validateURL
public boolean validateURL(String urlToValidate) {
if (StringUtils.isBlank(urlToValidate)) return false;
if ( ABOUT_BLANK.equals(urlToValidate) ) return true;
// Check if the url is "Escapable" - run through the URL-URI-URL gauntlet
String escapedURL = sanitizeHrefURL(urlToValidate);
if ( escapedURL == null ) return false;
// For a protocol-relative URL, we validate with protocol attached
// RFC 1808 Section 4
if ((urlToValidate.startsWith("//")) && (urlToValidate.indexOf("://") == -1))
{
urlToValidate = PROTOCOL_PREFIX + urlToValidate;
}
// For a site-relative URL, we validate with host name and protocol attached
// SAK-13787 SAK-23752
if ((urlToValidate.startsWith("/")) && (urlToValidate.indexOf("://") == -1))
{
urlToValidate = HOST_PREFIX + urlToValidate;
}
// Validate the url
UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
return urlValidator.isValid(urlToValidate);
}
示例3: setEndpoint
/**
* Sets the rpc endpoint to which this object will try to make requests.
* @param endpoint The rpc endpoint.
* @throws MalformedURLException When the URL string is not valid.
*/
void setEndpoint( String endpoint ) throws MalformedURLException{
UrlValidator validator = new UrlValidator(new String[]{"http"},UrlValidator.ALLOW_LOCAL_URLS);
if( validator.isValid(endpoint ))
this.endpoint = new URL(endpoint);
else
throw new MalformedURLException();
}
示例4: isValidUrl
@Contract("null, _ -> false")
public static boolean isValidUrl(@Nullable String url, String[] allowedSchemes) {
if (StringUtil.isBlank(url)) {
return false;
}
UrlValidator urlValidator = new UrlValidator(allowedSchemes, UrlValidator.ALLOW_LOCAL_URLS);
return urlValidator.isValid(url);
}
示例5: validate
protected void validate(String user, String password, INodeEntry entry) throws SaltStepValidationException {
checkNotEmpty(SALT_API_END_POINT_OPTION_NAME, saltEndpoint, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING,
entry);
checkNotEmpty(SALT_API_FUNCTION_OPTION_NAME, function, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);
checkNotEmpty(SALT_API_EAUTH_OPTION_NAME, eAuth, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);
checkNotEmpty(SALT_USER_OPTION_NAME, user, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);
checkNotEmpty(SALT_PASSWORD_OPTION_NAME, password, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);
UrlValidator urlValidator = new UrlValidator(endPointSchemes, UrlValidator.ALLOW_LOCAL_URLS);
if (!urlValidator.isValid(saltEndpoint)) {
throw new SaltStepValidationException(SALT_API_END_POINT_OPTION_NAME, String.format(
"%s is not a valid endpoint.", saltEndpoint), SaltApiNodeStepFailureReason.ARGUMENTS_INVALID,
entry.getNodename());
}
}
示例6: parseStringToURI
public static URI parseStringToURI(String uri) {
String[] schemes = {"http","https"};
UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS);
if(urlValidator.isValid(uri)){
try {
return new URI(uri);
} catch (URISyntaxException e) {
return null;
}
}
return null;
}
示例7: isValidUrl
private boolean isValidUrl(String url) {
String[] schemes = {"http", "https"};
long options = UrlValidator.ALLOW_LOCAL_URLS;
UrlValidator urlValidator = new UrlValidator(schemes, options);
return urlValidator.isValid(url);
}
示例8: QueueURLValidator
public QueueURLValidator() {
this(new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES + UrlValidator.ALLOW_LOCAL_URLS));
}
示例9: loadRequiredProperties
/**
* @return {@code true} if required properties are loaded
*/
private boolean loadRequiredProperties() {
if (logger.isDebugEnabled()) {
logger.debug("Loading properties...");
}
// Load properties
String stratosURL = null;
String username = null;
String password = null;
stratosURL = System.getenv(CliConstants.STRATOS_URL_ENV_PROPERTY);
username = System.getenv(CliConstants.STRATOS_USERNAME_ENV_PROPERTY);
password = System.getenv(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY);
if (StringUtils.isBlank(stratosURL)) {
if (logger.isDebugEnabled()) {
logger.debug("Required configuration not found.");
}
// Stratos Controller details are not set.
System.out.format("Could not find required \"%s\" variable in your environment.%n",
CliConstants.STRATOS_URL_ENV_PROPERTY);
return false;
}
if (logger.isDebugEnabled()) {
logger.debug("Required configuration found. Validating {}", stratosURL);
}
int slashCount = StringUtils.countMatches(stratosURL, "/");
int colonCount = StringUtils.countMatches(stratosURL, ":");
UrlValidator urlValidator = new UrlValidator(new String[]{"https"}, UrlValidator.ALLOW_LOCAL_URLS);
// port must be provided, so colonCount must be 2
// context path must not be provided, so slashCount must not be >3
if (!urlValidator.isValid(stratosURL) || colonCount != 2 || slashCount > 3) {
if (logger.isDebugEnabled()) {
logger.debug("Stratos Controller URL {} is not valid", stratosURL);
}
System.out.format(
"The \"%s\" variable in your environment is not a valid URL. You have provided \"%s\".%n"
+ "Please provide the Stratos Controller URL as follows%nhttps://<host>:<port>%n",
CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL);
return false;
}
if (logger.isDebugEnabled()) {
logger.debug("Stratos Controller URL {} is valid.", stratosURL);
logger.debug("Adding the values to context.");
}
context.put(CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL);
context.put(CliConstants.STRATOS_USERNAME_ENV_PROPERTY, username);
context.put(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY, password);
return true;
}
示例10: VerificationServiceImpl
/**
* @throws DrugMatchConfigurationException
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
* @throws IOException
*/
public VerificationServiceImpl() throws DrugMatchConfigurationException, KeyManagementException, NoSuchAlgorithmException, IOException {
String serviceUrl = DrugMatchProperties.getVerificationService();
if (serviceUrl == null) {
throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_SERVICE + "' isn't set!");
}
UrlValidator urlValidator = new UrlValidator(new String[] {"http", "https"}, UrlValidator.ALLOW_LOCAL_URLS);
if (!urlValidator.isValid(serviceUrl.toLowerCase(Locale.ENGLISH))) {
throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_SERVICE + "' isn't a valid HTTP/HTTPS URL!");
}
String login = DrugMatchProperties.getVerificationLogin();
if (login == null) {
throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_LOGIN + "' isn't set!");
}
String password = DrugMatchProperties.getVerificationPassword();
if (password == null) {
throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_PASSWORD + "' isn't set!");
}
URL url = new URL(serviceUrl);
int port;
if (url.getPort() > 0) {
port = url.getPort();
} else {
port = ("https".equals(url.getProtocol().toLowerCase(Locale.ENGLISH))) ? 443 : 80;
}
this.credentialsProvider = new BasicCredentialsProvider();
this.credentialsProvider.setCredentials(
new AuthScope(url.getHost(), port),
new UsernamePasswordCredentials(login, password));
// test if CA root is present in JRE, otherwise invoke SSL workaround
try (CloseableHttpClient httpclient = HttpClients.createDefault();) {
HttpGet httpget = new HttpGet(url.getProtocol() + "://" + url.getHost() + ":" + port);
log.debug("Executing request: {}", httpget.getRequestLine());
try (CloseableHttpResponse response = httpclient.execute(httpget);) {
log.debug("Executed request: {} status: {}", httpget.getRequestLine(), response.getStatusLine());
EntityUtils.consume(response.getEntity());
} catch (SSLHandshakeException e) {
if ("sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target".equals(e.getMessage())) {
log.debug("Unable to establish certificate trust chain, most likely cause: root certificate unavailable from JRE keystore. Proceeding with disabled TrustManager.");
this.customSslSocketFactory = new SSLConnectionSocketFactory(initializeCerts());
} else {
throw e;
}
}
}
}
示例11: validateUrlParameter
/**
* Helper function to validate the url passed to it.
*
* @param url The url that needs to be validated.
* @param sdkErrorCode The error message that needs to be thrown.
* @throws ApiException
*/
public static void validateUrlParameter(String url, SdkErrorCodes sdkErrorCode) throws ApiException {
UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
if(!urlValidator.isValid(url))
throw new ApiException(sdkErrorCode);
}
示例12: isURLValid
/**
* Check if URI is a valid URL.
*
* @param uriString
* @return
*/
protected static Boolean isURLValid(String uriString) {
String[] schemes = {"http", "https"};
UrlValidator urlValidator = new UrlValidator(schemes,UrlValidator.ALLOW_LOCAL_URLS);
return urlValidator.isValid(uriString);
}