Thursday, February 25, 2010

Just so we can get on with it. Go here to see how to add a realm to your Glassfish server. Once you've added the realm you'll need to create some groups. For the best method, give each group a specific task as it is easier to focus on a limit set of permissions than code for roles.

You may have a task like add a product, review a shopping cart, delete an account, or add a bank transaction. Roles are more like Super users, accountants, managers, etc.

Focus on task in your groups and then add triggers or EJB beans that focus on roles, which in turn aggregate your tasks.

Tuesday, February 23, 2010

Where have I been? Sorry I've just not had the time to post code samples here. Car had some issues, got them fixed, house had issues, cot those fixed, work has issues, not a damn thing I can do about those.

Friday, February 05, 2010

Okay, so here is a quick example of using the FedEx WSDL to build a simple tracking application. To get the FedEx WSDL you just go over to their developer website at http://www.fedex.com/us/developer. You will need to sign up to get a key and password to use their service. When you do sign up give it a couple of days for the key and password to be activated. If it takes longer than two days for the key and password to come online, just give the FedEx number a call.

So download the WSDL and add it to your web services on the services tab of NetBeans. Start a new Java Project and drag the track service from the services tab into the main method in your project.

You should now see some code that looks like this:



package javaapplication34;

/**
*
* @author Me
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

try {
com.fedex.ws.track.v4.TrackRequest trackRequest = null;
com.fedex.ws.track.v4.TrackService service = new com.fedex.ws.track.v4.TrackService();
com.fedex.ws.track.v4.TrackPortType port = service.getTrackServicePort();
// TODO process result here
com.fedex.ws.track.v4.TrackReply result = port.track(trackRequest);
System.out.println("Result = " + result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}


We are going to change that code to look like this:



package javaapplication34;

import com.fedex.ws.track.v4.ClientDetail;
import com.fedex.ws.track.v4.Notification;
import com.fedex.ws.track.v4.NotificationSeverityType;
import com.fedex.ws.track.v4.TrackDetail;
import com.fedex.ws.track.v4.TrackIdentifierType;
import com.fedex.ws.track.v4.TrackPackageIdentifier;
import com.fedex.ws.track.v4.TrackRequest;
import com.fedex.ws.track.v4.TransactionDetail;
import com.fedex.ws.track.v4.VersionId;
import com.fedex.ws.track.v4.WebAuthenticationCredential;
import com.fedex.ws.track.v4.WebAuthenticationDetail;
import com.fedex.ws.track.v4.TrackService;
import com.fedex.ws.track.v4.TrackPortType;
import com.fedex.ws.track.v4.TrackReply;

/**
*
* @author me
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

try {
TrackRequest trackRequest = new TrackRequest();
VersionId verId = new VersionId();
verId.setServiceId("trck");
verId.setMajor(4);
verId.setIntermediate(0);
verId.setMinor(0);
//The WSDL does not say that this is required but it is.
trackRequest.setVersion(verId);

WebAuthenticationDetail auth = new WebAuthenticationDetail();
WebAuthenticationCredential cred = new WebAuthenticationCredential();
//This is the key.
cred.setKey("XXXX");
//This is the password
cred.setPassword("XXXX");
auth.setUserCredential(cred);

ClientDetail detail = new ClientDetail();
//This is the test account number
detail.setAccountNumber("XXXX");
//This is the test meter number
detail.setMeterNumber("XXXX");

TransactionDetail trans_detail = new TransactionDetail();
trans_detail.setCustomerTransactionId("Tracking with Java");

TrackPackageIdentifier packId = new TrackPackageIdentifier();
packId.setType(TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG);
//This is some tracking number that you already have.
packId.setValue("XXXX");

trackRequest.setWebAuthenticationDetail(auth);
trackRequest.setClientDetail(detail);
trackRequest.setTransactionDetail(trans_detail);
trackRequest.setPackageIdentifier(packId);
trackRequest.setIncludeDetailedScans(Boolean.TRUE);

TrackService service = new TrackService();
TrackPortType port = service.getTrackServicePort();

TrackReply result = port.track(trackRequest);
if (result.getHighestSeverity() != NotificationSeverityType.FAILURE && result.getHighestSeverity() != NotificationSeverityType.ERROR) {
System.out.println("----RESULTS----");
if (!result.getTrackDetails().isEmpty()) {
for (TrackDetail d : result.getTrackDetails()) {
System.out.println("Tracking Number " + d.getTrackingNumber());
System.out.println("Tracking Description " + d.getStatusDescription());
}
}
} else {
for (Notification n : result.getNotifications()) {
System.err.println(n.getMessage());
}
}
} catch (Exception ex) {
ex.printStackTrace();
}

}
}


Ta-da! Simple example of the FedEx tracking Web-Service in action. If your account has not been enabled yet you will receive an "Authentication Failed" message. Otherwise you should start seeing some detail about the package. I suggest that you give the TrackDetail class a quick glance since that will be where most of the information you need to access will be. Remember to read those pesky annotations in the WSDL for more information and the PDF on the FedEx developer's website.

Tuesday, February 02, 2010

Best Description of today's computer reporting

With all the tech buzz that is going on these days, there is no end to the number of "reporters" that generate "news" stories about said tech buzz. However, while looking over one of the news stories on a site I found a comment that justly defines what is really going on here.


If next week Steve Jobs called a press conference and sliced his dick off with a silver scalpel in a room full of stunned reporters, I have no doubt that -- not to be outdone -- Sergey Brin would cut off his with a chainsaw on nation-wide TV seven days later.

And no one in the tech punditry -- all happy just to have jobs and something to write about besides the latest PC graphics card -- would question *WHY* these idiots are emasculating themselves, they'd just write tedious "thought" pieces contrasting the metaphors of Job's elegant, shiny castration versus Brin's use of loud horsepower.


--RobotRunAmok

Absolutely classic.

Monday, February 01, 2010

The world of apps. There's an app for that.

Warning, I am a Java fanboi (even if they sold out to Oracle)

A few years ago a platform was made called Java. It promised to allow people to write and compile their code once and run it everywhere. Of course real life set in an everyone realized that a VM just made software run slow. Basically you had two computers running in the space of one, the OS and the VM. However the idea was that a program could run anywhere and the idea was incredibly huge.

Microsoft tried their hand at Java and found out quickly that Sun meant business when it meant Java compliance. Microsoft would go on to make their own version of Java called .NET eventually. Most other players, IBM / Oracle / Apple / RedHat / Novell played fine with Sun and Java. However, without support from the MS desktop world, Java slowly migrated to business applications and middle-ware. Seeing who were the big players it's no surprise.

Then came along a thing called XML. Now the Internet was hot, but XML made it more flexible, more robust, and more friendlier. With XML, JavaScript, and Asynchronous HTTP you had AJAX. With XML, XSLT, and scripting you had blogs and walls. With XML and SOAP you had web APIs. For the first time the web was becoming a platform and not just a presentation layer. Add in the Open Source movement and MySOL / Linux / PHP / Apache and the web was becoming more and more about sites that provided services and tools for others.

Enter Google. Google has been the driver of the Web Platform, MS tried with ASP, then ASP.NET, and so forth, but all has not been about giving to people but instead just a platform of putting stuff on the web (I'm sorry I dropped my GeoCities account back in '97). MS has created an API to end making APIs. Google embraced the idea of taking an API an making an API out of it.

With the web becoming the cross platform application and presentation layers, Java slowly started grinding towards that goal, of making Java and web work together. Well, happily, no one was going to sit and wait for Sun Microsystems to get off their tush and start making stuff transpire. Struts was born, Spring was born, Tomcat was born, and so on... Sun was quickly loosing their driver's seat to Open Source projects that ran on Java. And to an extent Sun was begrudgingly accepting of the change.

Then the mobile generation started, and that brings me to my muse.

Apple pushed a web central platform with a native SDK as a last option for their phone platform.
Google is pushing a web central platform with a native SDK as a last option for their phone platform.
Microsoft is pushing their .NET platform, yadda yadda yadda, it does some web stuff too for their phonelaptopcomputerservertoasterXbox360sink platform.
Oh yeah and Palm is doing something web centric for their phone platform.

However, sans Palm, all have made big markets in their native application space. The HTML5 platform has been somewhat missing in all of their market software.

Wasn't the idea of Java to build apps that would run on the iPhone, Droid, Pre, and whatever monster MS puts out? Wasn't JavaFX to make apps so easy that people wouldn't think of native?

What went wrong? The what I call "70's mindset" has dominated the cell phone market. That hardware dictates software is the 70's mindset. Vendors do this because of two reason:

1. Control
2, Ease

Apple has a very tight grip over their API, in fact they take in very little input as to what the next SDK will have. Pretty much the same over at the Google camp. They have it open sourced, but very little is changed by outsiders as far as the standard API goes. Do I need to even mention the amount of control MS has over .NET?

Control makes Ease. Picture if you will how absolutely easy it would be to build a platform if you design the platform to run only your specs! That in is the problem with Java on the phone. There are (were, give it a couple of more years) many Java phones out in the world (unless you have Verizon). But Java has gotten away from Sun, quite literally now thanks to Oracle, and control is now anyone (and everyones) game.

HTML5 may prove to be the ultimate winner, but the road ahead is long. The W3C may have the final say but a lot of players, like Apple and Google, are in a big tug of war with the standard that HTML5 for mobile may be out of reach to be a real goal anytime soon.

Thus, we have hardware specific (er, platform) applications that could have used Java but chose not to. We must muse, why is HTML5 better than Java on mobile phones?

Cheers

Trying out Blokkal

Since I'm a big KDE user, yes that means KDE 4 as well. I decided that I would try an actual KDE client to write to my blog.

So this is a test of that.

Also I want to try out pre:


public class Hello {

public static void main(String [] args) {
System.out.println("Hello, World");
}

}


Cheers!

Secure Simple EJB Bean making the DB tables.

Alright, it has been awhile but I swear I've been away for very good reasons.

So if you remember our basic EJB HelloBean, let's look at how to add security measures to provide a login for people to run our EJB code.

First we need to setup our JDBC realm. To do that we need an actual database. I'll be using MySQL as it is a wonderfully simple database to use and maintain, at the same time MySQL scales nicely and can be used for very big projects. So let's say you have your MySQL server up and running. Let's create a database called helloDB. To do that from the MySQL prompt (hereafter known as the sql prompt (since I hate having to hit the shift key for SQL)) type in:


CREATE DATABASE helloDB


Now let's create two tables, one to hold user names and passwords, the other to hold user names and groups. We'll call these tables USERTBL and GRPTBL.


CREATE TABLE USERTBL (
USERNAME VARCHAR(13) NOT NULL,
SHAPASSWD CHAR(64) NOT NULL,
PRIMARY KEY (USERNAME)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE GRPTBL (
ENTRYID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
USERNAME VARCHAR(13) NOT NULL,
GROUPING VARCHAR(20) NOT NULL,
PRIMARY KEY (ENTRYID),
UNIQUE KEY (USERNAME, GROUPING),
CONSTRAINT FOREIGN KEY (USERNAME) REFERENCES USERTBL (USERNAME) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Here we've created the two tables we need to start a security realm using the JDBCRealm module. The SHAPASSWD field of the USERTBL is to store our passwords in SHA-256 encoded strings. You can use any kind of hash function that is known to Java, like MD-5 or SHA-1, I'm going with SHA-256 because I like it among other things.

Also note that I did not make a composite primary key for the GRPTBL but instead created a unique key for the user name / group name pair. I don't like composite primary keys, I don't know many DB admins that do, they have a purpose but just using them anywhere is not really a good idea.

Well there you have the DB side of it. I'll look at the Glassfish end of it in the next post. Cheers!