Tuesday, December 13, 2005

Converting Arrays to Lists in Java 5

I'm trying to write some Java 5 (or 1.5, whatever) code for the first time. This is how I used to convert an array to a List in 1.4:
List list = Arrays.asList(intArray);
However, Java 5 gives me an error as Arrays.asList(intArray) actually returns a List<int[]>. That's right, a list of int arrays with a size of 1 instead of a List<Integer>, List of ints with size intArray.length.

So is this correct? Does Arrays.asList(intArray) no longer work for my needs?

For now I am forced to use the following, unless someone can show me the light:

List<Integer> list = new ArrayList<Integer>();
for (Integer i : intArray) list.add(i);


Update:
j yu has helped me to understand the issue at hand, as I have noted in the comments below. Here is the logic for easier viewing...

Under 1.4, you will receive a compile time error for asList(int[]), but under 1.5 asList(int[]) is acceptable with the varargs implementation. 1.5 accepts the array as an object and creates a List<int[]> instead of the List<Integer> that I had expected through autoboxing.

Try this for yourself:
int[] intArray = new int[] { 1, 2, 3, 4, 5, 6 };
System.out.println(Arrays.asList(intArray).size());

Integer[] integerArray = new Integer[] { 1, 2, 3, 4, 5, 6 };
System.out.println(Arrays.asList(integerArray).size());


Your output will be:
1
6

Since the asList works very differently with int[] and Integer[].

Maybe this should be a warning in Eclipse? It is confusing for both expert and novice users. Or should this even be the correct approach? Shouldn't the Arrays.asList(int[]) autobox the int's into a Integer[] for you?

Or is there still an easier solution for me? Maybe through casting or generics? I stumbled upon this while converting int[] to List during a Topcoder event, after updating my jdk from 1.4 to 1.5


Update #2:
In a normal app, it would be easy for me to import the Apache Lang jar, and use ArrayUtils.toObject(intArray). However I'm trying to do this inside of the Topcoder arena applet, so I can't include any external jars. That's why I was looking for an api level solution.

Friday, December 09, 2005

Trying new Code Review Tool

I've been wanting to better organize a structured code review on our project. So today I'm looking at the CSDL Jupiter Code Review Tool.

It looks promising, in that no external DB is required. It stores all review info in xml documents that are shared through our normal CVS project. It's an Eclipse plugin, which will make it easy to install and get our developers up to speed.

And they have a nice user's guide.

I'm hoping it fulfills our needs, and I'll post the results of my review after a day or so of use. It should be a big improvement over the print / distribute / highlight review!

Thursday, December 01, 2005

Eclipse.org redesign... Very Nice!

After complaining in the past about the Eclipse website, I'm really impressed with their site redesign. I especially like how easy it is to download the Eclipse SDK now from their new downloads area! Finally, a person unfamiliar with the umbrella Eclipse organization can simply download the Eclipse SDK IDE without stumbling through the maze of projects.

Nicely done! It's much more elegant and far lower on the confusing scale.

Wednesday, November 30, 2005

Tomcat Remote Debug with Windows Service?

Does anybody know how to start tomcat for remote debugging when using the windows service that comes with tomcat? I can do it in unix and non-service windows, but can't figure out how to work in with the NT service running on XP.

Any ideas? Please help!

Monday, November 28, 2005

Re: Why I Hate PayPal

A post on Marginalia describes his position on Why I Hate PayPal.

My position is much simpler. Paypal has a large inbound phone center here in Omaha, and their local 402 area code phone number is one off from my work number. So I answer around 5 calls a week from people complaining about their Paypal account. I even had someone leave their credit card number on my voicemail once.

So that's my reason to hate Paypal.

(Please notice: I actually love their service, so this is just me venting about an annoyance, and it really has nothing to do with Paypal directly.)

Thursday, October 13, 2005

Bloglines New Keyboard Shortcuts

As a follow up to Google Reader (and possibly pressured by them), Bloglines has added Keyboard Shortcuts!

This is nicely done, and it is the one feature from Google Reader that I had really wanted. I really like the j/k/s navigation. One little nitpick though is to allow j or s to start the browsing, so I don't have to click on a link to start the browsing.

Monday, October 10, 2005

Google Reader - First Impressions

Here's my thoughts (pros/cons) on the new Google Reader, as I use my past few years with Bloglines as comparison.

First, I love the clean Web 2.0 look! This is a big improvement of the frames of Bloglines. It was easy to export my feeds from Bloglines and import them into Google Reader, although Google seemed to hang on the import. I just returned later to find all of my feeds running. I love the keyboard navigation (using j/k to go down/up the list).

But there are reasons that I'm sticking with Bloglines. Bloglines makes it easier for me to see all of my feeds at once by clicking on the "N updated feeds" link. They also make it easier for me to mark all of my feeds as read this way. In Google it seems I have to scroll using j/k through each link, but in Bloglines I can pull them up and skim through the list. I really prefer seeing them all at once and skimming.

So Bloglines for now, and I hope that Bloglines picks up on some of Googles Ajax-ian tricks...

Monday, September 12, 2005

Fixed Weblogic Apache Bridge CSS Mimetype

After switching our jsp pages to render in w3c transitional mode (by adding the doctype to our pages), the css files stopped working in firefox. I found that the css files were being served with an incorrect mime-type of text/html instead of the required text/css from the firefox page info. (IE apparently guesses the mimetype for you, which is against the w3c spec but get's your pages to show correctly.)

Our first check was the Apache config, which appeared correct. Next was a web search where I found some links to the apache weblogic bridge. The bridge incorrectly places a text/html mimetype on everything. We fixed this by putting the mime mapping into the web.xml file of our webapp. Everything works beautifully again!

Here's the mapping that needs to be added:

<mime-mapping>
  <extension>css</extension>
  <mime-type>text/css</mime-type>
</mime-mapping>

Monday, July 18, 2005

No Fluff Iowa - Day 3 (Selenium Rocks!!!)

Day 3 at No Fluff Just Stuff at the Central Iowa Symposium in Des Moines was a great way to end (even though I didn't win the Sony PSP). I started off the morning by attending "Give the DB a Break! Peformance & Scalability" from Dion Almaer. Dion had some awesome content in this session, and I was most interested in the caching architectures for taking load off of our db. I'm very interested in Tangosol Coherence after he built it up so much. Distributed cluster caching is something we must get deployed soon on our app.

My second session was Neal Ford's "Advanced Enterprise Debugging Techniques". The "Advanced" word didn't really play in, as he covered debugging from the ground up. His bits about jdb and classloader hierarchy were ok. Then he showed us ThoughtWorks' Selenium testing product... WOW!!! It's an open source testing engine, that runs in JavaScript! This means it tests in any browser that you tell it to. It actually tests from the user's point of view! I'm very excited, because we didn't want to throw down the cash for Silk or Mercury. You really have to see the demo for Selenium. It's going to change our user acceptance processes very quickly (from manual to automated). I downloaded and played with Selenium for 2 hours today, and it was even easier than I had predicted. The only shortfall I could find was it doesn't handle mouse moving, so it doesn't fully test things like dynamic menus that only work on hover, but this is a small limitation that could be fixed as Selenium is only in a 0.5 release.

That ended our weekend in Des Moines (after a quick Web Tier BOF with Neal Ford & Scott Davis). I would have attended Scott's Testing the Web Tier sessions, but we had to get back to Omaha. I've talked a little to Jay Zimmerman, and hopefully they can bring NFJS to Omaha next year! Great conference, I totally recommend it to everyone, and I'll be going again next year!

Saturday, July 16, 2005

No Fluff Iowa - Day 2 (Ruby--)

This is the second post in attempting to cover my time here at the No Fluff Just Stuff Central Iowa Symposium in Des Moines.

If day one was about testing, and death to java - long live ruby, then day 2 is about "Now that you know about Ruby, why don't we give you the Java info that you came here to see." Or, "Here's the reasons that Java can be seen as Ruby--".

To start the day, I saw another terrific session by Venkat Subramaniam, this time covering "Good, Bad, & Ugly of Java Generics". He started out with a well covered overview of Generics, Auto Boxing, and ForEach features of Java 1.5. Good stuff. Then he dove in to show us that "Generics were created to solve type safety, yet they don't even solve type safety!" Basically it came down to generics being overly complex that solved only the trivial issue of casting from a collection. Most of the problem relies in Generics being syntactic sugar: Implemented only in the language, and not in the JVM. So, as Venkat correctly puts it, "Sun employs a wonderful marketing department. Selling us 'type erasure' as being cool, when it is really a huge hinderance". I'm very greatful for this talk, and plan to look at Groovy and Ruby (dynamic typed languages) to solve some issues that I was hoping Generics would solve.

Next I attended a couple of sessions by Justin Gehtland, the first being Advanced Hibernate, and the second Principles of Service Oriented Architecture. I really enjoyed the first, as it moved quickly, and hit the main areas that I needed to improve my knowledge in: Lazy Loading, Interceptors, and Events. The Lazy Loading talk was great, and really just asserted some ideas that I have had. Event handling was interesting. It made me think of a system where we could send JMS messages when certain fields or objects are created/updated in the database (to update displays, caches, etc...).

His second talk, about SOA, felt a little more long-winded. I appreciate his knowledge on the subject, as he did a decent job at explaining a roughly boring and genericized topic. I wish I had more detail about actual implementations of SOA walking away from this session, but he did cover the "Principles" that he said he would. Maybe there was just too much time spent per slide on the generalities and politics, which left not enough time for implementations. I was hoping to hear details about Mule ESB and REST services, but they were only given a passing glance.

Oh, and I didn't win the mini iPod raffle today (not even a T-Shirt), but that means I'm still in the running for the Sony PSP tomorrow! Now we're off to find some good sushi in this land of hog farms (spoken from an Omaha resident, no less).

No Fluff Iowa - Day 1 (Java's Dead, Ruby Lives)

I'm at the No Fluff Just Stuff Central Iowa Symposium in Des Moines this weekend, and Day 1 was a great start. First I saw a great Test First session hosted by Venkat Subramaniam. He quickly covered the top points of Test First development by creating a TicTacToe app on the fly. He's a great presenter, and even mentioned JUnitPerf for performance testing that I wasn't aware of. He also showed well how test first enforces service layer abstraction just by better coding.

Then I saw a couple of Bruce Tate sessions, the first titled Lightweight Dev Strategies, and the second was Politics of Persistence. I really enjoyed the first of these, as it delved into agile methods, testing, dependency injection, REST, and other hot topics of the moment. It was great to get Bruce's impression of these. The second session also covered great topics like JDO, Hibernate, iBatis, and Entity Beans, and he did a good job of covering the political history of these. I was a little disappointed that more detail wasn't covered about the specific implementations of each, but was happy with the sessions details overall at a higher level. I'm also feeling the urge to investigate KODO JDO, iBatis, and Spring JDBC in more detail now.

Now to the interesting part... It was capped by an "Expert Panel" consisting of Venkat, Jason Hunter, and Dave Thomas (what happened to Bruce Tate?). Good discussion, but focused mainly on testing, and the other hot button: Ruby on Rails. Ruby has been the hidden underlining to both of Bruce's sessions, and now obviously with Dave. It does feel a little awkward to be at a Java conference, and have each session finish with "But if you really want to do it well, then you have to use Ruby on Rails". They keep preaching that we are at the death of Java, and Ruby on Rails is here to save us. Do they really expect the three of us to return to Omaha to tell our director, "Sorry but we're ditching everything from the past few years for Ruby"? They say there are no vendors at the NFJS symposiums (in the JavaOne mindset), but some of this feels like they are actually open source vendors building a product that they hope to support and live off of. How much kool-aid can we drink?

So Day 1 has been a great start, and spending the evening at Rock Bottom Brewery couldn't hurt either. I do wish this conference was in Omaha instead of Des Moines though, as Omaha has nearly 850,000 (over 1 mil if you count Lincoln) compared to Des Moines at half of the size. Omaha also has 5 fortune 500 companies (as of last year) with a couple of other large Java shops on top of these, but Des Moines has been a great host so far... But the Old Market would be better then Suburban W. Des Moines, don't you think?

Friday, June 17, 2005

There is no spoon

So.... It's been more than a month since my last post? I really can't believe it, which is why I'm writing this now!!!

The main thing happening in my last few months is my change of employer from Raytheon to West Corp. Still in Omaha, and still doing J2EE, but I received a large promotion so I can detail more in design and decisions than merely implementation. Don't get me wrong, I'm still writing code most of my day. I'd go crazy if I didn't...

This means I'm not heavily invested in the Jetspeed portal engine, which is a bit sad considering I've been working with it as it has grown to maturity. I'm now mostly engrained with Weblogic, and experimenting with every "latest buzzword technology" that floats by.

Having done AJAX work, long before it was called AJAX, I'm happy to explore more code in that direction. Along with my attempts to push for more JMS, Spring, unit testing, agile approaches, and anything else to make life easier at my new position.

On a personal note, our daughter, Madison, turned 1 in the past couple of weeks. What an amazing experience the first year has been for Shayla and I! Our family really is the greatest blessing in my life...

Oh, and I can't forget, Go Huskers! Our baseball team just won their first game EVER in the College World Series here in Omaha!!!

Thursday, May 19, 2005

nullpointer on weblogic fixed

I have fixed the problem from my last post, and put the answer here:dev2dev Online

It seems that weblogic was not noticing the changes so it was not redeploying. This is because we are exploding our ear in development. I changed our ant script to always overwrite the META-INF directory containing the application.xml file. This is forcing weblogic to refresh the application correctly (like it would if an entire ear file had changed), and the problem is now gone.

Wednesday, May 18, 2005

Deploy error after recompiling with struts on weblogic

I have posted the same question at BEA's dev2dev Online

We are getting the following stacktrace when hitting the application for the first time after a redeploy. We are running on Weblogic, and the problem goes away after restarting the app or redeploying throught the console. Has anyone seen this before?


java.lang.NullPointerException
at org.apache.struts.action.RequestProcessor.getServletContext(RequestPr
ocessor.java:1136)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(
TilesRequestProcessor.java:180)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(Ti
lesRequestProcessor.java:309)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:148
2)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:402)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
va:27)
at com.proprietary.LoggingFilter.doFilter(LoggingFilter.java:69)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
va:27)
at com.proprietary.SecurityFilter.doFilter(SecurityFilter.java:159)

at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
va:27)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:6356)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)


Edited 5/19/2004:
I have found a fix, and posted a new entry about it. It dealt with our development deployment using an exploded ear.

Friday, April 15, 2005

Fix for JAAS Auth in Jetspeed

I've finally found a fix for our Jetspeed JAAS Authentication issue with Weblogic (thanks to help from a BEA consultant).

The problem occurs when using the JAASSessionValidator in Jetspeed to authenticate through the Weblogic app server, along with using the struts bridge from the apache portals project. After logging in as the same user in more than one session (by first logging in, and then opening another browser to log in again with the same userid), and going from one page to another in the same mode (view mode, for example), the server throws up this error:
Included resource or
file "/action/edit.jas;jsessionid=C7QZxyGkX0pm6Sp9ckM6vyfxTRJ4p1Tn0Ph3bdz
g3TJQX4pyDxwC!-2002059013" not found from requested resource "/jetspeed/portal/_
ns:YTIxMzQ4fGMwfGQwfGVfa3JhPTE9MXxlX3NwYWdlPTE9L2VkaXRfb2JzLmphcztqc2Vzc2lvbmlkP
T1DN1FaeHlHa1gwcG02U3A5Y2tNNnZ5ZnhUUko0cDFUbjBQaDNiZHpnM1RKUVg0cHlEeHdDIS0yMDAyM
DU5MDEzfGVfbW9kZT0xPXZpZXc_/".


This appears to be a problem with how Jetspeed will rewrite URL's, and maybe it is more specifically related to the struts bridge. I say Jetspeed, and not Weblogic, because the problem can be resolved by telling Weblogic to only use cookies to relay session data instead of also rewriting url's. So we fixed this by placing this next configuration into the weblogic.xml file of ALL of our war files:

<session-descriptor>
<session-param>
<param-name>URLRewritingEnabled</param-name>
<param-value>false</param-value>
</session-param>
</session-descriptor>


At least we found a work around!

Friday, April 08, 2005

Using Struts multibox and radio tags

I've found a great way to use both the Struts multibox and radio tags, and just want to document it here for my future use.

The multibox is a tag to output multiple linked checkboxes, so the user can select multiple items at once. The radio is the same idea, but for a single select.

My jsp piece looks like this, and it generates a table with a radio button as the first field:

<c:forEach var="data" items="${MyForm.dataList}">
<tr>
<td><html:radio property="selectedData" value="${data.id}"/></td>
<td><c:out value="${data.name}"/></td>
<td><c:out value="${data.location}"/></td>
</tr>
</c:forEach>


Now, you can change it to a multiselect version using the multibox by replacing the html:radio tag with this one:
<html:multibox property="selectedData" value="${data.id}"/>

In my MyForm, I have a public List getDataList() and a public String getSelectedData() for the single select with the radio button. For the multiselect with the multibox you have to use public String[] getSelectedData() instead. (of course, both need the corresponding setSelectedData() method...)

[edited to remove confusing custom rowColor tag, 2/20/2006]

Thursday, March 31, 2005

Jetspeed on Weblogic FAQ

Wow, I've been linked from the Jetspeed Wiki as a source for information on running Jetspeed on Weblogic!

Because of this, I have updated my Problem Deploying Jetspeed 2 on Weblogic post that they link to. I have modified it to include links to other posts that I have had about Jetspeed on Weblogic, so that I really do contain a FAQ instead of just rambling on the subject.

So here is my complete list of posts on the idea, from first to last:
Problem Deploying Jetspeed 2 on Weblogic
Jetspeed 2 on Weblogic - part 2
Jetspeed 2 on Weblogic - Finally
Jetspeed 2 on Weblogic - update again
Jetspeed Fusion, Struts, and Weblogic

Thursday, March 10, 2005

MVCPortlet Framework

I have just finished reading about the MVCPortlet Framework. This seems like a great framework for developing portlets! Like struts (or WebWork, or Spring MVC, or whatever) it is a MVC model for presentation data. But unlike all of the others, it is made specifically to work in a JSR-168 portal. We have been using the struts-bridge from apache jetspeed to write struts applications to work in a portal. While the bridge is nice, it has a key bug that seems to arise because the struts-bridge is a hack to get it working in a portal (specifically the "edit" mode button is broken). MVCPortlet seems like a much cleaner portal development MVC model.

Friday, February 18, 2005

Gmail finally being rolled out to everyone

As many could predict from the GMail invitation surplus of late, Gmail is finally opening up registration to just about anyone. Although the front page of gmail.com doesn't mention it, the notification service sent an email to my old account today. I've been using GMail for months, but originally I signed up on their website so I could hear when they would allow me to register. That email finally came direct from google today, to invite me to use gmail.

Thursday, February 10, 2005

Sending HTML email with gmail

Finally, someone shows us how to Send HTML email with gmail!

Great work! Hopefully gmail will turn this hidden feature on soon!

Friday, January 21, 2005

Agreed, throw exception instead of return null

Blaine tells us Don’t use null or -1 in your unwritten methods, and I have to agree. He's pointing to Tim Bray's error in unit testing.

I have to say this is a great idea, and should be used by everyone. That is, instead of returning null or -1 for an unimplemented method, you should throw a RuntimeException ("Method has not been implemented"). Even better would be to create your own UnimplementedMethodException and throw that.

Good stuff to read for breakfast!

Friday, January 14, 2005

Multiple Firefox Session

I found some posts about creating multiple firefox sessions. But they all require you to set MOZ_NO_REMOTE=1 in your environment before starting a window. This forces each window to use a different profile. All I want is each window to use separate session cookies, or even allow this in separate tabs (could be very hard to get right).

Sunday, January 09, 2005

Legit Tivo web server

Wow, it is great to here that Version 7.1 of the TiVo service update installs and enables a web server!

Now I just have more pressure on myself ot get that wireless adapter for my Tivo. Apparently you can download video straight from the box, without having to use Tivo Desktop software. Sweet.