Url Checking Tool in Java Java Java Projects Tools by Rajesh Kumar Sahanee - June 17, 2018April 13, 20200 Post Views: 7,529 Hello Friends, Today I am going to share a url checking tool which I have developed few days ago in Java. This tool filter outs the bad urls and working urls from list of urls. I am going to share code also, so that you can develop it yourself and you can also extend its feature according to your need or you can add on your creativity in this tool. So here is the code MainForm.java MainForm.java Java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package urlcheckingtool; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import javax.net.ssl.HttpsURLConnection; import javax.swing.SwingUtilities; /** * * @author rajesh kumar sahanee */ public class MainForm extends javax.swing.JFrame { /** * Creates new form MainForm */ public MainForm() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { mainSP = new javax.swing.JSplitPane(); leftJP = new javax.swing.JPanel(); urlsJL = new javax.swing.JLabel(); jScrollPane4 = new javax.swing.JScrollPane(); urlsJTA = new javax.swing.JTextArea(); processJB = new javax.swing.JButton(); processJPB = new javax.swing.JProgressBar(); jPanel1 = new javax.swing.JPanel(); cb301CB = new javax.swing.JCheckBox(); cb403CB = new javax.swing.JCheckBox(); cb404CB = new javax.swing.JCheckBox(); cb500CB = new javax.swing.JCheckBox(); rightSP = new javax.swing.JSplitPane(); jPanel2 = new javax.swing.JPanel(); notFoundUrlsJL = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); notFoundUrlsJTA = new javax.swing.JTextArea(); jPanel3 = new javax.swing.JPanel(); workingUrlsJL = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); workingUrlsJTA = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Url Checking Tool"); leftJP.setMinimumSize(new java.awt.Dimension(260, 0)); leftJP.setPreferredSize(new java.awt.Dimension(200, 435)); urlsJL.setText("Urls"); urlsJTA.setColumns(20); urlsJTA.setRows(5); jScrollPane4.setViewportView(urlsJTA); processJB.setText("Process"); processJB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { processJBActionPerformed(evt); } }); jPanel1.setAutoscrolls(true); cb301CB.setText("301"); cb403CB.setText("403"); cb404CB.setText("404"); cb500CB.setText("500"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(cb301CB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cb403CB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cb404CB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cb500CB) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cb301CB) .addComponent(cb403CB) .addComponent(cb404CB) .addComponent(cb500CB)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); javax.swing.GroupLayout leftJPLayout = new javax.swing.GroupLayout(leftJP); leftJP.setLayout(leftJPLayout); leftJPLayout.setHorizontalGroup( leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(leftJPLayout.createSequentialGroup() .addContainerGap() .addGroup(leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane4) .addGroup(leftJPLayout.createSequentialGroup() .addComponent(processJB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(processJPB, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) .addGroup(leftJPLayout.createSequentialGroup() .addComponent(urlsJL) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); leftJPLayout.setVerticalGroup( leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leftJPLayout.createSequentialGroup() .addContainerGap() .addComponent(urlsJL) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(processJPB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(processJB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(6, 6, 6)) ); mainSP.setLeftComponent(leftJP); rightSP.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); jPanel2.setMinimumSize(new java.awt.Dimension(0, 200)); jPanel2.setPreferredSize(new java.awt.Dimension(200, 200)); notFoundUrlsJL.setText("Not Working Urls"); notFoundUrlsJTA.setColumns(20); notFoundUrlsJTA.setRows(5); jScrollPane1.setViewportView(notFoundUrlsJTA); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(notFoundUrlsJL) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(notFoundUrlsJL) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE) .addContainerGap()) ); rightSP.setLeftComponent(jPanel2); workingUrlsJL.setText("Working Urls"); workingUrlsJTA.setColumns(20); workingUrlsJTA.setRows(5); jScrollPane2.setViewportView(workingUrlsJTA); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(workingUrlsJL) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addComponent(workingUrlsJL) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE) .addContainerGap()) ); rightSP.setRightComponent(jPanel3); mainSP.setRightComponent(rightSP); getContentPane().add(mainSP, java.awt.BorderLayout.CENTER); pack(); }// </editor-fold> private void processJBActionPerformed(java.awt.event.ActionEvent evt) { if(processJB.getText().equals("Process")) { stop = false; processJB.setText("Stop"); } else { stop = true; processJB.setText("Process"); return; } String urls[] = urlsJTA.getText().split("\n"); notFoundUrls = ""; workingUrls = ""; processJPB.setValue(-1); processJPB.setIndeterminate(true); final ArrayList<String> errorCodes = new ArrayList(); if(cb301CB.isSelected()) { errorCodes.add("301"); } if(cb403CB.isSelected()) { errorCodes.add("403"); } if(cb404CB.isSelected()) { errorCodes.add("404"); } if(cb500CB.isSelected()) { errorCodes.add("500"); } Thread worker = new Thread() { public void run() { for(int i = 0; i < urls.length; i++) { if(stop) { break; } try { if (errorCodes.contains(getResponseCode(urls[i]))) { notFoundUrls += urls[i] + "\n"; } else { workingUrls += urls[i] + "\n"; } SwingUtilities.invokeLater(new Runnable() { public void run() { notFoundUrlsJTA.setText(notFoundUrls); workingUrlsJTA.setText(workingUrls); } }); //Thread.sleep(500); } catch (IOException e) { } } SwingUtilities.invokeLater(new Runnable() { public void run() { processJPB.setIndeterminate(false); processJPB.setValue(100); processJB.setText("Process"); } }); } }; worker.start(); // So we don't hold up the dispatch thread. } public static String getResponseCode(String urlString) throws MalformedURLException, IOException { if(!urlString.startsWith("http://") && !urlString.startsWith("https://")) { urlString = "http://" + urlString; } URL u = new URL(urlString); if (u.getProtocol().equals("https")) { HttpsURLConnection huc = (HttpsURLConnection) u.openConnection(); huc.setRequestMethod("GET"); huc.setConnectTimeout(10000); huc.connect(); return String.valueOf(huc.getResponseCode()); } else { HttpURLConnection huc = (HttpURLConnection) u.openConnection(); huc.setRequestMethod("GET"); huc.setConnectTimeout(10000); huc.connect(); return String.valueOf(huc.getResponseCode()); } } String notFoundUrls = new String(); String workingUrls = new String(); boolean stop = false; // Variables declaration - do not modify private javax.swing.JCheckBox cb301CB; private javax.swing.JCheckBox cb403CB; private javax.swing.JCheckBox cb404CB; private javax.swing.JCheckBox cb500CB; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JPanel leftJP; private javax.swing.JSplitPane mainSP; private javax.swing.JLabel notFoundUrlsJL; private javax.swing.JTextArea notFoundUrlsJTA; private javax.swing.JButton processJB; private javax.swing.JProgressBar processJPB; private javax.swing.JSplitPane rightSP; private javax.swing.JLabel urlsJL; private javax.swing.JTextArea urlsJTA; private javax.swing.JLabel workingUrlsJL; private javax.swing.JTextArea workingUrlsJTA; // End of variables declaration } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package urlcheckingtool; import java.io.IOException;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.util.ArrayList;import javax.net.ssl.HttpsURLConnection;import javax.swing.SwingUtilities; /** * * @author rajesh kumar sahanee */public class MainForm extends javax.swing.JFrame { /** * Creates new form MainForm */ public MainForm() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { mainSP = new javax.swing.JSplitPane(); leftJP = new javax.swing.JPanel(); urlsJL = new javax.swing.JLabel(); jScrollPane4 = new javax.swing.JScrollPane(); urlsJTA = new javax.swing.JTextArea(); processJB = new javax.swing.JButton(); processJPB = new javax.swing.JProgressBar(); jPanel1 = new javax.swing.JPanel(); cb301CB = new javax.swing.JCheckBox(); cb403CB = new javax.swing.JCheckBox(); cb404CB = new javax.swing.JCheckBox(); cb500CB = new javax.swing.JCheckBox(); rightSP = new javax.swing.JSplitPane(); jPanel2 = new javax.swing.JPanel(); notFoundUrlsJL = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); notFoundUrlsJTA = new javax.swing.JTextArea(); jPanel3 = new javax.swing.JPanel(); workingUrlsJL = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); workingUrlsJTA = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Url Checking Tool"); leftJP.setMinimumSize(new java.awt.Dimension(260, 0)); leftJP.setPreferredSize(new java.awt.Dimension(200, 435)); urlsJL.setText("Urls"); urlsJTA.setColumns(20); urlsJTA.setRows(5); jScrollPane4.setViewportView(urlsJTA); processJB.setText("Process"); processJB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { processJBActionPerformed(evt); } }); jPanel1.setAutoscrolls(true); cb301CB.setText("301"); cb403CB.setText("403"); cb404CB.setText("404"); cb500CB.setText("500"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(cb301CB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cb403CB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cb404CB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cb500CB) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cb301CB) .addComponent(cb403CB) .addComponent(cb404CB) .addComponent(cb500CB)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); javax.swing.GroupLayout leftJPLayout = new javax.swing.GroupLayout(leftJP); leftJP.setLayout(leftJPLayout); leftJPLayout.setHorizontalGroup( leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(leftJPLayout.createSequentialGroup() .addContainerGap() .addGroup(leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane4) .addGroup(leftJPLayout.createSequentialGroup() .addComponent(processJB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(processJPB, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) .addGroup(leftJPLayout.createSequentialGroup() .addComponent(urlsJL) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); leftJPLayout.setVerticalGroup( leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leftJPLayout.createSequentialGroup() .addContainerGap() .addComponent(urlsJL) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(leftJPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(processJPB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(processJB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(6, 6, 6)) ); mainSP.setLeftComponent(leftJP); rightSP.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); jPanel2.setMinimumSize(new java.awt.Dimension(0, 200)); jPanel2.setPreferredSize(new java.awt.Dimension(200, 200)); notFoundUrlsJL.setText("Not Working Urls"); notFoundUrlsJTA.setColumns(20); notFoundUrlsJTA.setRows(5); jScrollPane1.setViewportView(notFoundUrlsJTA); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(notFoundUrlsJL) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(notFoundUrlsJL) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE) .addContainerGap()) ); rightSP.setLeftComponent(jPanel2); workingUrlsJL.setText("Working Urls"); workingUrlsJTA.setColumns(20); workingUrlsJTA.setRows(5); jScrollPane2.setViewportView(workingUrlsJTA); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(workingUrlsJL) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addComponent(workingUrlsJL) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE) .addContainerGap()) ); rightSP.setRightComponent(jPanel3); mainSP.setRightComponent(rightSP); getContentPane().add(mainSP, java.awt.BorderLayout.CENTER); pack(); }// </editor-fold> private void processJBActionPerformed(java.awt.event.ActionEvent evt) { if(processJB.getText().equals("Process")) { stop = false; processJB.setText("Stop"); } else { stop = true; processJB.setText("Process"); return; } String urls[] = urlsJTA.getText().split("\n"); notFoundUrls = ""; workingUrls = ""; processJPB.setValue(-1); processJPB.setIndeterminate(true); final ArrayList<String> errorCodes = new ArrayList(); if(cb301CB.isSelected()) { errorCodes.add("301"); } if(cb403CB.isSelected()) { errorCodes.add("403"); } if(cb404CB.isSelected()) { errorCodes.add("404"); } if(cb500CB.isSelected()) { errorCodes.add("500"); } Thread worker = new Thread() { public void run() { for(int i = 0; i < urls.length; i++) { if(stop) { break; } try { if (errorCodes.contains(getResponseCode(urls[i]))) { notFoundUrls += urls[i] + "\n"; } else { workingUrls += urls[i] + "\n"; } SwingUtilities.invokeLater(new Runnable() { public void run() { notFoundUrlsJTA.setText(notFoundUrls); workingUrlsJTA.setText(workingUrls); } }); //Thread.sleep(500); } catch (IOException e) { } } SwingUtilities.invokeLater(new Runnable() { public void run() { processJPB.setIndeterminate(false); processJPB.setValue(100); processJB.setText("Process"); } }); } }; worker.start(); // So we don't hold up the dispatch thread. } public static String getResponseCode(String urlString) throws MalformedURLException, IOException { if(!urlString.startsWith("http://") && !urlString.startsWith("https://")) { urlString = "http://" + urlString; } URL u = new URL(urlString); if (u.getProtocol().equals("https")) { HttpsURLConnection huc = (HttpsURLConnection) u.openConnection(); huc.setRequestMethod("GET"); huc.setConnectTimeout(10000); huc.connect(); return String.valueOf(huc.getResponseCode()); } else { HttpURLConnection huc = (HttpURLConnection) u.openConnection(); huc.setRequestMethod("GET"); huc.setConnectTimeout(10000); huc.connect(); return String.valueOf(huc.getResponseCode()); } } String notFoundUrls = new String(); String workingUrls = new String(); boolean stop = false; // Variables declaration - do not modify private javax.swing.JCheckBox cb301CB; private javax.swing.JCheckBox cb403CB; private javax.swing.JCheckBox cb404CB; private javax.swing.JCheckBox cb500CB; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JPanel leftJP; private javax.swing.JSplitPane mainSP; private javax.swing.JLabel notFoundUrlsJL; private javax.swing.JTextArea notFoundUrlsJTA; private javax.swing.JButton processJB; private javax.swing.JProgressBar processJPB; private javax.swing.JSplitPane rightSP; private javax.swing.JLabel urlsJL; private javax.swing.JTextArea urlsJTA; private javax.swing.JLabel workingUrlsJL; private javax.swing.JTextArea workingUrlsJTA; // End of variables declaration } Main.java Main.java Java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package urlcheckingtool; /** * * @author rajesh kumar sahanee */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MainForm().setVisible(true); } }); } } 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package urlcheckingtool; /** * * @author rajesh kumar sahanee */public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MainForm().setVisible(true); } }); } } Screenshot NetBeans Project Download Url Checking Tool 1 file(s) 37.37 KB Download Thank you, Please don’t forget to share if you like it