@IsURL annotation

back to index

Action

Requires that the annotated element be a URL. This annotation can optionally attempt to resolve the host and even fetch the URL in order to check the validity of the value.

Javadoc Ref :  Javadoc reference@IsURL

 Input Types 1
Calendar, Date, Number, CharSequence, byte, int, short, long, double, float
 Output Types
Object
   

1Automatic conversion will take place if the provided input does not match any of the input classes, as described in the conversions part of the manual.

Arguments

validProtocols

Set of valid protocols. Default is the empty array, which means any protocol is allowed

resolveHost
Specifies whether to check the host by performing a DNS lookup
contactHost
Specifies whether to contact the host. If set to true, resolveHost() ignored and assumed to be true, too.
fetchURL
Specifies whether to actually attempt to fetch the URL (only for the http and https protocols). If set to true, resolveHost() and contactHost() are ignored and assumed to be true.
timeout
Specifies the maximum amount of milliseconds to wait if any of the contactHost() fetchURL() attributes are set to true
message

Literal message to use if validation fails.

errorCode
Error code to use if validation fails.
messageKey
Message key to use if validation fails.

 

Example

@Required
@IsURL
private String url;

@IsURL
private URL url1;

@IsURL(resolveHost=true)
private String urlHost;

@IsURL(contactHost=true,timeout=6000)
private String reachableHost;

@IsURL(validProtocols={"https"})
private String secureHost;

@IsURL(fetchURL=true,timeout=6000)
private String reliableSource;