I want to get the information for WHOIS server. I have written a code in java. I am getting the connection reset error for some some domain. Follwoing method retrieves the WHOIS server information.
public void populateWhoisDetails(String domain) {
logger.info("Retriving the Whois information for " + domain);
Socket theSocket = null;
BufferedReader in = null;
PrintWriter writer = null;
try {
String whosisServer = whoisDNSModel.getWhosisServer();
if (StringUtil.isNotEmpty(whosisServer)) {
whoisDNSModel.setDomainName(domain);
if (DomainProcessorEnum.VALID.equals(processorEnum)) {
InetAddress inetAddress = InetAddress
.getByName(whosisServer);
theSocket = new Socket();
theSocket.connect(new InetSocketAddress(inetAddress,43),120000);
writer = new PrintWriter(theSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
theSocket.getInputStream()));
writer.println(domain+Constants.NEWLINE);
writer.flush();
String line = null;
while ((line = in.readLine()) != null) {
if (line.contains(Constants.COLON)) {
String[] strArray = line.split(Pattern
.quote(Constants.COLON));
if (strArray[0].contains(Constants.REGISTRANT)) {
StringBuilder stringBuilder = populateRegistrantInformation(
in, domain);
whoisDNSModel.setRegistrant(stringBuilder
.toString());
} else if (null == whoisDNSModel
.getDnsCreatetionDate()
&& strArray[0]
.contains(Constants.CREATED_ON)
|| strArray[0]
.contains(Constants.CREATION_DATE)) {
String dateStr = strArray[1];
whoisDNSModel.setDnsCreatetionDate(dateStr);
}
}
}
}
theSocket.close();
}
} catch (UnknownHostException unknownHostException) {
logger.log(Level.SEVERE,unknownHostException.getMessage(),unknownHostException);
}catch (IOException ioException) {
logger.log(Level.SEVERE,ioException.getMessage(), ioException);
}
logger.info("Retrieved the Whois information for " + domain);
}
Can any one please help me to resolve the issue?