Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Java Programming Forums Desktop App (Is that okay?)

  1. #1
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Java Programming Forums Desktop App (Is that okay?)

    A desktop app that checks threads for new posts, new notifications and what have you sounded nice so I decided to start working on one. However, this will obviously be doing a lot of authentication through login.php while I am testing and wasn't sure if that would be kosher. I can probably have it do the 'stay logged in' thing and just pass the stored cookie to the site so that there won't be multiple login attempts each time it gets run. Right now, I can log in and get to the main page to begin scraping, but I wanted to make sure doing this was fine with the site's administration before going further. Doesn't seem to me this would be a problem but doesn't hurt to be sure.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Programming Forums Desktop App (Is that okay?)

    I think somebody else was working on a similar application. Might want to do a search and contact that person before you reinvent the wheel.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Java Programming Forums Desktop App (Is that okay?)

    Hello KucerakJM.

    Thank you for your enthusiasm.
    As Kevin pointed out, something like this has been brought up many times.

    I am trying to find the threads but here is one:

    http://www.javaprogrammingforums.com...-software.html

    I'm sure it will be a fun project to work on but I can't really see it of being much use.
    All the features such as newest posts, posts with zero replies etc are all functions easily accessed directly on the forums.

    Although I don't mind you testing the application, I would prefer it if you had a test environment rather than making multiple requests to the live site.
    I understand how this could be hard though as vBulletin is a licensed application.

    I would be very interested to see the code you have written to login to the forums.
    Maybe you could submit it and we can add it to the code tutorials section or promote it to an article?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Java Programming Forums Desktop App (Is that okay?)

    Thank you for the replies. I did do a search for other ideas like this and found that they were from a while back which is why I made this additional thread. I know it's a bit redundant but I see my app as being a bit different. The idea is just to have a desktop app scrape info such as new threads/posts (which could be put into a "watch" list) or private messages (the only reason login would really be needed) and then notify the user appropriately; probably through a little popup containing a link that opens the page in a browser. The following does the login work, whether or not it's the best way to go about it, I can't say but it does work.

    import java.io.BufferedReader;
    //import java.io.BufferedWriter;
    import java.io.DataOutputStream;
    import java.io.InputStreamReader;
    import java.math.BigInteger;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.Scanner;
     
     
    public class barebonesLogin {
    	public static void main(String[] args) throws Exception 
    	{
    		String username, password;
    		Scanner input = new Scanner(System.in);
     
    		System.out.println("Please enter your username: ");
    		username = input.nextLine();
     
    		System.out.println("Please enter your password: ");
    		password = input.nextLine();
     
    		login("http://javaprogrammingforums.com/login.php?do=login", username, MD5Password(password));
    	}
     
    	public static void login(String url, String username, String password) throws Exception 
    	{	
    		// This was obtained through the Live HTTP Headers firefox plugin
    		String content = "vb_login_username=" + username + "&vb_login_password=&vb_login_password_hint=Password&cookieuser=1&s=&" +
    				"securitytoken=guest&do=login&vb_login_md5password="+ password +"&vb_login_md5password_utf="+ password; 
     
    		// Create a new URL object
    		URL website = new URL(url);
    		// Creates Connection referred by the URL object
    		HttpURLConnection conn = (HttpURLConnection) website.openConnection(); 
    		// Set some basic connection properties
    		conn.setRequestMethod("POST"); 
    		conn.setDoOutput(true); 
    		conn.setDoInput(true);
    		conn.connect();
     
    		// Create a DataOutputStream to be able to write data to the underlying HttpURLConnection outputstream
    		DataOutputStream out = new DataOutputStream(conn.getOutputStream()); 
    		// Send the content
    		out.writeBytes(content);
     
    		/*
    		// Variables for getting header names and setting cookie value(s)
    		String hName=null;
    		String cookie = null;
     
    		// Loops through headers to obtain all cookie values and add them to the cookie String
    		// The cookie would be used later to access pages as a logged-in user
    		for (int i=1; (hName = conn.getHeaderFieldKey(i))!=null; i++) 
    		{
    		 	if (hName.equals("Set-Cookie")) {                  
    		 		cookie += conn.getHeaderField(i) + "; ";
    		 	}
    		}
    		*/
     
    		// Force any buffered output to be written to the stream and then close it to free the resources
    		out.flush(); 
    		out.close(); 
     
    		// This part will get the returned html data which can be checked if the login was successful
    		BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
    		String line = ""; 
     
    		// Use the FileWriter if there is a large amount of text
    		//FileWriter fstream = new FileWriter("out.txt");
    		//BufferedWriter fout = new BufferedWriter(fstream);
     
    		while((line=in.readLine())!=null) 
    		{ 
    			System.out.println(line);
    			//fout.write(line);
    			//fout.newLine();
    		}
     
    		//fout.close();
    		// Close out the buffered reader that is no longer needed
    		in.close();
     
    		// Done with the connection
    		conn.disconnect();
    	}
     
    	private static String MD5Password(String password) throws NoSuchAlgorithmException
    	{
    		MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(password.getBytes());
            BigInteger md5 = new BigInteger(1, messageDigest);
            String md5Pass = md5.toString(16);
     
            while (md5Pass.length() < 32) {
            	md5Pass = "0" + md5Pass;
            }  
            return md5Pass;
    	}
    }

    If this was successful the the returned html code with contain the text "Thank you for logging in, [YourUsername]". Thinking about it, I just want to make a glorified html scraper to automate checking threads in the background while I do w/e on my computer. Again, thank you for the replies


    - Michael

  5. #5
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Java Programming Forums Desktop App (Is that okay?)

    Just so you know there is an app that already checks for replies and is interconnected with Google Chrome [My favorite browser], which has an official label and works nicely with this forum and almost every other forum as well while being verified safe by Google. [Which is a big plus compared to a third-party program] Also has an iOS, Android, and Blackberry app already released at production-level.

    https://chrome.google.com/webstore/d...nflfofmahljkjj
    Last edited by Tjstretch; March 28th, 2012 at 02:31 PM.

  6. #6
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Java Programming Forums Desktop App (Is that okay?)

    Well, since the point of furthering this project is now moot it is time to look for something else to preoccupy my time. Thank you all for the replies.

  7. #7
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Java Programming Forums Desktop App (Is that okay?)

    Thanks for posting your code. I am going to test it out and possibly post it in the code snippets section. I will be sure to credit you.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Java Programming Forums Custom Software
    By macko in forum The Cafe
    Replies: 6
    Last Post: November 4th, 2011, 07:45 AM
  2. HAPPY 3rd BIRTHDAY JAVA PROGRAMMING FORUMS!!!
    By JavaPF in forum The Cafe
    Replies: 23
    Last Post: May 13th, 2011, 12:21 PM
  3. HAPPY 2nd BIRTHDAY JAVA PROGRAMMING FORUMS!!!
    By JavaPF in forum The Cafe
    Replies: 55
    Last Post: May 24th, 2010, 03:43 AM
  4. HAPPY BIRTHDAY JAVA PROGRAMMING FORUMS!
    By JavaPF in forum The Cafe
    Replies: 30
    Last Post: June 4th, 2009, 08:32 AM
  5. Hello java programming forums
    By DnB in forum Member Introductions
    Replies: 2
    Last Post: February 9th, 2009, 07:38 AM