Get domain information (WHOIS) using Apache Commons Net API- ADF & Java

Sharing is Caring

We can get domain information using Apache commons net library. It supports various protocols and WHOIS information is one of them

WhoisClient class provides access to domain information
See what docs say –

The WhoisClient class implements the client side of the Internet Whois Protocol defined in RFC 954. To query a host you create a WhoisClient instance, connect to the host, query the host, and finally disconnect from the host. If the whois service you want to query is on a non-standard port, connect to the host at that port.

Download required library or if this link doesn’t work then goto API page and download from there

This simple java method will fetch information of domain using Apache library


/**Method to get domain WhoIs information using Apache Commons Net API
 * @param domainName
 * @return
public String getWhoisDomainInformation(String domainName) {
StringBuilder info = new StringBuilder("");
WhoisClient whois = new WhoisClient();
try {
String data = whois.query("=" + domainName);

} catch (SocketException e) {
} catch (IOException e) {
return info.toString();


    • Now created an ADF Application and a page in the viewController project
    • Added library (commons-net jar file) in viewController project



    • Here I am using one button and two input text, first one to enter the domain name and the second one is to show fetched WHOIS information

    • On button click, I have called above method and passed domain name (To get domain name use component binding of inputText) and to show fetched information a String variable is mapped with the second inputText

See Managed Bean code and Page XML Source (How it is mapped) –

//String to store domain information and to show on page in second inputText
private String domainInfoDet;
//First Input Text component binding to get domain name in managed bean
private RichInputText domainNameBind;

public void setDomainInfoDet(String domainInfoDet) {
this.domainInfoDet = domainInfoDet;

public String getDomainInfoDet() {
return domainInfoDet;

public void setDomainNameBind(RichInputText domainNameBind) {
this.domainNameBind = domainNameBind;

public RichInputText getDomainNameBind() {
return domainNameBind;

/**Action Listener to execute method on button click
 * @param actionEvent
public void getDomainInfoAction(ActionEvent actionEvent) {
//domainNameBind is component binding of first inputText
if (domainNameBind.getValue() != null) {
String domainName = (String) domainNameBind.getValue();
//Set WHOIS info in string to show on page (Second InputText)
domainInfoDet = getWhoisDomainInformation(domainName);

XML Source of Page-

<af:form id="f1">
                <af:panelBox text="Domain Information" id="pb1" showDisclosure="false">
                    <f:facet name="toolbar"/>
                    <af:panelGroupLayout id="pgl1" layout="vertical" halign="center">
                        <af:panelGroupLayout id="pgl2" layout="horizontal">
                            <af:inputText label="Domain Name" id="it1"
                            <af:button text="Get Information" id="b1" inlineStyle="font-weight:bold;"
                        <af:inputText label="Label 1" id="it2"
                                      contentStyle="width:600px;color:#405d9a;font-weight:bold;" simple="true" rows="40"
                                      value="#{viewScope.DomainInformationBean.domainInfoDet}" partialTriggers="b1"
  • All Done:), Run and check application

Sample ADF Application – Download
Cheers:) Happy Learning

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *