Java – Adams Bros Blog http://blog.adamsbros.org Thu, 06 Aug 2015 02:35:38 +0000 en-US hourly 1 https://wordpress.org/?v=5.2.2 SOAP vs REST http://blog.adamsbros.org/2015/08/05/soap-vs-rest/ http://blog.adamsbros.org/2015/08/05/soap-vs-rest/#respond Thu, 06 Aug 2015 00:12:29 +0000 http://blog.adamsbros.org/?p=589 I was recently asked the question about the conditions under which I would choose SOAP vs REST for writing a Web Service.  I was thoroughly intrigued by the question, because I was curious in which way the discussion would go, as that would tell me a lot about the other developer.

My reply essentially focused around the concept that some developer, or group of developers, decided that they would write a Web Service framework and do some programming for the sake of programming, instead of actually solving a problem.  I’ve always been curious as to why anyone would actually want to do that, but hey, some people like work more than I do apparently.  I enjoying designing software masterpieces, not working.  In other words, I don’t like work, I like to create art.

You know, people love creating solutions before there’s a problem.  Well, more specifically in this case, the problem of needing a way to deliver Web Services was already solved with a protocol that was created in the early 1990s called HTTP.  SOAP was just a useless wrapper for generic requests/responses, when HTTP was essentially already a superior wrapper protocol for the same.  I then proceeded to talk about how when REST came out I kind of chuckled, because I was thinking “Gee, you mean the standard web protocol HTTP is really more than enough? Who would have thunk?”

Apparently he liked that reply, lol.

]]>
http://blog.adamsbros.org/2015/08/05/soap-vs-rest/feed/ 0
OpenJPA Standalone Application Quick Start http://blog.adamsbros.org/2014/11/07/openjpa-standalone-application-quick-start/ http://blog.adamsbros.org/2014/11/07/openjpa-standalone-application-quick-start/#respond Sat, 08 Nov 2014 04:36:26 +0000 http://blog.adamsbros.org/?p=503 Finding a decent OpenJPA standalone example is very difficult. The one I’ve created on github does not provide any sort of complex example, but it at least shows how to get started with a standalone Open JPA application, with a maven build.

https://github.com/TrentonAdams/openjpa-quickstart

]]>
http://blog.adamsbros.org/2014/11/07/openjpa-standalone-application-quick-start/feed/ 0
Derby Command Line Quick Start http://blog.adamsbros.org/2014/11/06/derby-command-line-quickstart/ http://blog.adamsbros.org/2014/11/06/derby-command-line-quickstart/#respond Fri, 07 Nov 2014 03:10:12 +0000 http://blog.adamsbros.org/?p=498 While you can find this information on the derby website, in a grossly large Derby Basics document, isn’t it nicer to just copy and paste? I just don’t understand why developers like to write documents that make you take so much time to get started.

wget http://apache.mirror.gtcomm.net//db/derby/db-derby-10.11.1.1/db-derby-10.11.1.1-bin.tar.gz
tar -xvzf db-derby-10.11.1.1-bin.tar.gz
sudo mv db-derby-10.11.1.1-bin /usr/local/
export DERBY_INSTALL=/usr/local/db-derby-10.11.1.1-bin
export CLASSPATH=$DERBY_INSTALL/lib/derby.jar:$DERBY_INSTALL/lib/derbytools.jar:.

java org.apache.derby.tools.ij

Once you’re in, you can issue the following commands…

connect 'jdbc:derby:MyDbTest;create=true';
drop table derbyDB;
create table derbyDB(num int, addr varchar(40));
insert into derbyDB values (1956,'Webster St.');
insert into derbyDB values (1910,'Union St.');
update derbyDB set num=180, addr='Grand Ave.' where num=1956;
select * from derbyDb;

]]>
http://blog.adamsbros.org/2014/11/06/derby-command-line-quickstart/feed/ 0
apache tomcat 7 rpm http://blog.adamsbros.org/2013/02/27/apache-tomcat-7-rpm/ http://blog.adamsbros.org/2013/02/27/apache-tomcat-7-rpm/#respond Thu, 28 Feb 2013 04:55:13 +0000 http://blog.adamsbros.org/?p=442 So, I decided to get an apache tomcat 7 rpm going.  I ended up finding someone who had created one, and then made it work a little bit better.  I had one guy that used to be a fedora RPM contributor help out a bit as well.  The result is a repository on github.

If you want to help contribute, and make it better, by all means fork it and work away. 😀

https://github.com/TrentonAdams/apache-tomcat-rpm

]]>
http://blog.adamsbros.org/2013/02/27/apache-tomcat-7-rpm/feed/ 0
Upgrade Android SQLite Database http://blog.adamsbros.org/2012/02/28/upgrade-android-sqlite-database/ http://blog.adamsbros.org/2012/02/28/upgrade-android-sqlite-database/#comments Tue, 28 Feb 2012 20:37:33 +0000 http://blog.adamsbros.org/?p=431 After fiddling with a few different styles of coding a database upgrade implementation for Android, I’ve settled on a fairly simple method.  Basically, I take the old version, and increment a counter until I get to the current version.  Through each iteration, I use switch on the value of the upgradeTo variable, and upgrade each cycle.  If things get too complex for your application, you can always create individual upgrade methods, for each version.

Of course this method will only work if your database version is incremented by one each time you change the database.  And, this really should be the way you version it anyhow.

    public void onUpgrade(
        final SQLiteDatabase db, final int oldVersion,
        final int newVersion)
    {
        int upgradeTo = oldVersion + 1;
        while (upgradeTo <= newVersion)
        {
            switch (upgradeTo)
            {
                case 5:
                    db.execSQL(SQLiteSet.V5_ADD_LAST_CARD);
                    db.execSQL(SQLiteCard.V5_ADD_FAILED);
                    break;
                case 6:
                    db.execSQL(SQLiteSet.V6_ADD_IMPORT_TYPE);
                    break;
                case 7:
                    db.execSQL(SQLiteSet.V7_ADD_SHORT_FNAME);
                    break;
            }
            upgradeTo++;
        }
    }

Someone asked in a comment, why we do the upgrade in a loop.  I do this because I do not know what version they will be converted from or to. So, I must either put a bunch of logic for every possible upgrade variation, such as 1 => 2, 1 => 3, 1=> 4, 3=> 4, etc, etc, or, I can loop through and do one upgrade at a time, and increment the version through each loop.  This GREATLY simplifies the database upgrade.

]]>
http://blog.adamsbros.org/2012/02/28/upgrade-android-sqlite-database/feed/ 20
Send Email in your Android Application http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/ http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/#comments Sat, 31 Dec 2011 21:48:59 +0000 http://blog.adamsbros.org/?p=416 I’ve seen a lot of examples of how to send email from an android application.  All of them result in applications coming up in a chooser list that are not appropriate for sending email.  In this post, I’ll described the various solutions I found, and the solution that brings up only email clients.

If you want to skip the junk, and go straight to the solution, go to the last two code snippets at the end.

One variation, from stack overflow, goes something like this.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intent.putExtra(Intent.EXTRA_TEXT   , "body of email");
startActivity(Intent.createChooser(intent, "Send mail..."));

The reason this doesn’t work properly, is because it brings up pretty much any app that can handle text/plain content. To expect a user to send an email with bluetooth, or wifi, or evernote, is simply not appropriate. So, if your intention is to have them send an actual email, as opposed to sharing content in some other way, then this won’t work for you.

Another variation from stack overflow, is to replace the mime-type of text/plain with message/rfc822. This results in a list of applications that can handle “email message” content. As a result, if you have ever-note installed, it comes up in the list as well. It will happily store your complete RFC822 email message for you. However, this is a hack, and is totally not appropriate. That mime type implies that you have already constructed a complete and valid RFC822 email message, including headers and what not.

Finally, I was able to find an example on the IT Wizard website, that shows the almost proper way of doing this, using the mailto URI handling.  Theoretically, only valid email applications will ever come up in this list. It goes like this…

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:someone@example.com"));
intent.putExtra("subject", "my subject");
intent.putExtra("body", "my message");
startActivity(intent);

Unfortunately, that only works with gmail on my phone.  So, I revised it to include everything inside the mailto url.

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:someone@example.com?subject=" +
    Uri.encode("my subject") +  "&body=" +
    Uri.encode("My big long body with spaces, new lines, and all sorts of invalid URI characters"));
startActivity(intent);

Now the only activities that come up are email apps. 😀 Now, if you want the complete list of email applications to always come up for the user, whether they’ve chosen a “default” email app or not, then you need to start the activity like this…

startActivity(Intent.createChooser(intent, "your chooser title"));

I do not know how to attach files to an email, using this method; in fact I do not think it is possible, seeing the mailto: URL scheme is pretty limited.  So, unfortunately, if you want to attach files, you’re going to have to use one of the other methods, with the EXTRA_STREAM option to putExtra() and file URI pointing to a file on your android device.  As a result, you’ll just have to live with some non-email related applications coming up.

If someone has a way of making sure ONLY email apps come up, using the other methods, I’d sure like to hear about it.  Thanks.

]]>
http://blog.adamsbros.org/2011/12/31/send-email-in-your-android-application/feed/ 9
Conversion to Dalvik format failed with error http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/ http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/#respond Tue, 08 Nov 2011 05:28:58 +0000 http://blog.adamsbros.org/?p=411 I went looking, and looking, and looking, for a solution to this problem. None of them seemed to fit the bill. I tried…

  1. updating proguard
  2. not using libraries I shouldn’t be
  3. re-importing the project
  4. removing duplicate android jars
  5. removing all android jars
  6. a host of other “suggestions” from Eclipse Android users

Not one of the ones I found worked.  I suddenly right clicked the project, and happened to see a menu called “Android Tools“.  I wasn’t thinking it would do anything for my predicament, but was curious what was under it.  I then saw, and clicked, the item called “Fix Project Properties“, and voilà, the error disappeared.

Go figure, an Eclipse option to fix a problem that Eclipse caused.  KEWL!

Hope this helps someone through their pain.

IntelliJ folks, PLEASE add GUI support for android, so that I can ditch this piece of junk Java IDE called Eclipse.

]]>
http://blog.adamsbros.org/2011/11/07/conversion-to-dalvik-format-failed-with-error/feed/ 0
Eclipse Android Hello World Tutorial Video – Part 3 http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/ http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/#comments Sat, 23 Jul 2011 03:01:11 +0000 http://blog.adamsbros.org/?p=394 In third part of the android hello world video, we explain the different components of the application, and why things are done in a certain way.  This video is a bit raw.  However, rather than editing the videos, I’m going to try and improve my presentation skills as I go.

Before we get started, the code for part 3 is located on github under the tag “part3“.  You should be able to switch to that tag and download a tar.gz of the code.   Or you can simply clone it as follows.

git clone git://github.com/TrentonAdams/HelloAndroid.git HelloAndroid
cd HelloAndroid
git checkout part3

In this video, we will

  1. explain the various sections of code
  2. explain the semantics of the android R class for referencing resources
  3. explain the use of localized resource files

We have one new screenshot from this video in the series.  It is the French version of the application.

If this video fails to play, please check back later, it may still be processing.

]]>
http://blog.adamsbros.org/2011/07/22/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-3/feed/ 1
Eclipse Android Hello World Tutorial Video – Part 2 http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/ http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/#comments Sun, 17 Jul 2011 01:05:37 +0000 http://blog.adamsbros.org/?p=368 Part 3 – Code Explained

Okay, I’ve finished another android development demo video.  Sorry it took so long, I got really busy with a new computer and what not, and life in general.  In the next video in this series, I will explain the details of the hello android application.  So, if you do not understand some of what is happening, stay tuned for the next video in the series.

Before we get started, the code for part 2 is located on github under the tag “part2“.  You should be able to switch to that tag and download a tar.gz of the code.   Or you can simply clone it as follows.

git clone git://github.com/TrentonAdams/HelloAndroid.git HelloAndroid
cd HelloAndroid
git checkout part2

In this video, we do the following…

  1. an actual android application with a button that opens a dialog box. The dialog box has a Okay/Cancel button.
  2. Handling and implementing events
    1. onCreateDialog(int) – when a dialog is requested to be created in this activity, this method is called
    2. onClick(View arg0) – we tied the click event from the button to our activity rather than making a custom class for it
  3. log debug information to the android log
  4. use logcat to see the debug information

Below are the two screens that you will see in this application.

Hello Android Screenshot
Hello Android Okay/Cancel Dialog


This android demo was created using a software package under Linux called “recordMyDesktop”.  It’s terribly slow for encoding the video, which it does after the video has been recorded.  I think it’s recording my whole screen as a series of screenshots, which is probably what takes it so long.  I used it from the command line, as I have not yet attempted to use a GUI tool with it.  I found that I basically required 240 fps, because it did not capture all of my selections if I did not use a high frame rate.  This time I decreased the quality and the bitrate, as it did not seem to make a huge impact on quality.

recordmydesktop –pause-shortcut Control+Shift+P –fps 240 –v_quality 30 –v_bitrate 400 -o ~/Videos/newvideo

This is based in part on the Android Hello World documentation at http://developer.android.com/resources/tutorials/hello-world.html

]]>
http://blog.adamsbros.org/2011/07/16/eclipse-android-hello-world-tutorial-video-%e2%80%93-part-2/feed/ 1
Maven Test Debug Mode Profile http://blog.adamsbros.org/2011/07/09/maven-test-debug-mode/ http://blog.adamsbros.org/2011/07/09/maven-test-debug-mode/#respond Sun, 10 Jul 2011 05:14:49 +0000 http://blog.adamsbros.org/?p=352 I should have blogged about this long ago, as I feel that this is a very useful way of debugging unit tests with maven.  This is especially so if you’re primarily a command line sort of guy like myself.

All that is required to be able to debug a unit test is

  1. configure the maven surefire plugin from within a profile
  2. activate the maven profile from the command line

The following XML profiles section will work just peachy for you.

  
 
    
      dtest
      
        false
      
      
        
          
            org.apache.maven.plugins
            maven-surefire-plugin
            2.5
            
              once
              true
            
          
        
      
    
  

Now just run this.

  mvn -Pdtest package
]]>
http://blog.adamsbros.org/2011/07/09/maven-test-debug-mode/feed/ 0