Software Blog

In this space i will be adding posts about software solutions and common problems.  You can find my personal blog, blog.monstersoftwarellc.com also containing a few nuggets of software development truths!

Please feel free to comment on my postings, please let me know if you would like to see postings on other topics! 

Recent Posts

  • HttpsURLConnection Send/Receive Example Good example of how to create and user a HTTPS connection in JAVA6.  Also shows how you can get at the response and utilize it.Connection Example InputStreamReader streamReader = null ...
    Posted Apr 21, 2011, 10:35 AM by Nicholas Padilla
  • What it takes to be a software developer. I feel that many people go into software development without a clue as to what it means to be a "developer".  Having been in the service industry for over a ...
    Posted Apr 9, 2011, 5:38 PM by Nicholas Padilla
Showing posts 1 - 2 of 2. View more »

HttpsURLConnection Send/Receive Example

posted Apr 21, 2011, 8:12 AM by Nicholas Padilla   [ updated Apr 21, 2011, 10:35 AM ]

Good example of how to create and user a HTTPS connection in JAVA6.  Also shows how you can get at the response and utilize it.

Connection Example

		InputStreamReader streamReader = null;
		OutputStream out = null;
		HttpsURLConnection connection = null;
		BufferedReader bufferedReader = null;
		StringBuffer stringBuffer = new StringBuffer()		
                try {
			String urlString = "https://" + givenURL;
			
                        // add a security provider to system for https call
			Security.addProvider(new Provider());
                        // Create a Hostname Verifier that will validate the URL
                        // important since the connection will not work w/out this
			HostnameVerifier verifier = new HostnameVerifier() {
				@Override
				public boolean verify(String arg0, SSLSession arg1) {
					System.out.println("Url Host : "+arg0+" vs. "+arg1.getPeerHost());
					return true;
				}
			};
			// sets the hostname verifier
			HttpsURLConnection.setDefaultHostnameVerifier( verifier);
			HttpsURLConnection.setFollowRedirects(false);

			String usernamePass = "Username" + ":" + "Password";
			String encoding = new BASE64Encoder().encode (usernamePass.getBytes());

			URL url = new URL(urlString);
			connection = (HttpsURLConnection)url.openConnection();
                        // set basic request properties
			connection.setRequestProperty("Authorization", "Basic "+encoding);
			connection.addRequestProperty("User-Agent", "Some User Agent Id");
                        // xml content type, change if you are not sending an xml request.
			connection.addRequestProperty("Content-Type", "application/xml; charset=utf-8");
			connection.setRequestMethod("POST");
			connection.setDoOutput(true);
			connection.setInstanceFollowRedirects(false);

			out = connection.getOutputStream();
			out.write( "request string here"  ); 
			out.flush(); 
			out.close(); 

			int responseCode = connection.getResponseCode(); 
			String responseMsg = connection.getResponseMessage(); 			

			if(responseCode == 200){

				InputStream is = connection.getInputStream(); 
				streamReader = new InputStreamReader(is);
			        bufferedReader = new BufferedReader(streamReader);
			        String inputLine;
			    
			        while ((inputLine = bufferedReader.readLine()) != null){
			    	    stringBuffer.append(inputLine);
			        }
			        System.out.println(stringBuffer.toString());
			}else{
				throw new IllegalStateException("Should retry operation.");	
			}
		} catch (IOException e) {			
			e.printStackTrace();
		}finally{
			if(connection != null){
				connection.disconnect();
			}
			try {
				if(streamReader != null){
					streamReader.close();
				}
				if(out != null){
					out.close();
				}
				if(bufferedReader != null){
					bufferedReader.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}			
		}

What it takes to be a software developer.

posted Apr 9, 2011, 7:34 AM by Nicholas Padilla   [ updated Apr 9, 2011, 5:38 PM ]

I feel that many people go into software development without a clue as to what it means to be a "developer".  Having been in the service industry for over a decade now i can firmly say that to be a successful software developer you need a few personality traits that will make the road to success a bit easier.  

a. Willing to put in the time.  This is the most important aspect of being a successful programmer.  This means lots of time away from the other things in life you love, and also shows the next item.
b. Dedicated.  This has meaning on a few different levels, dedicated to keeping an open mind(another biggie), dedicated to sticking to good software principles(even in the face of heated opposition), dedicated to learning NEW software principles and technologies.  Of course there are times when you bend the rules, however never leave it as is.  Plan for how you want to upgrade the code later on, even going as far as half implementing the right code but limiting its functionality.  The later option is always preferred. 
c. Knowing what you Don't Know!  This is another biggie!  Do what I do if I am questioning something I am doing, ask a coworker or ask google.  Get some highly rates books so that you can have material to go over when your not online.
d. Being something of a perfectionist, also means you take pride in anything you do.  This will cause you countless hours of being frustrated that the GUI doesn't look juuuuust right.  Means that you spend twice the time to implement something just because you thought of a better way for things to work, even though your other solution worked as well. 
e. Self Confidence!  Don't feel bad when you make a mistake, though catch it in testing!  As long as you follow the other items you will learn from those failures and use them to grow your knowledge base.
f. Self Motivated!  If you can't bring yourself to take the time to really get into the nuts and bolts of whatever technology your thinking of working with, then it will be difficult to succeed in the software industry. 

These are some things to keep in mind when thinking about taking the plunge into software development.  As I think of more items I'll get this updated.  

1-2 of 2

Comments