Secure Glassfish v3 Admin Console

Friday, September 18th, 2009

By default, the admin console can be accessed by the outside world. I prefer to have it accessible to localhost only (so I can ssh tunnel it only).

Open the admin console, and on the menu, Configuration -> Network Config -> Network Listeners -> admin-listener, and edit the IP to state 127.0.0.1, hit save, then restart Glassfish.

Feeding marshalled JAXB data to Jersey

Thursday, August 20th, 2009

Although Jersey supports eating JAXB’ed classes fine, sometimes you want to manually alter the data, such as including a processing instruction for XSL stylesheets. There probably should be a less verbose way to do this.

The object should be an @XMLRootElement annotated object.

@GET
@Produces("application/xml")
public static StreamingOutput outputXMLwithXSL() {
  return new StreamingOutput() {
    public void write(OutputStream output) throws IOException,
    WebApplicationException {
      Object object = yourJAXBObject();

      JAXBContext jc = null;
      try { jc = JAXBContext.newInstance(object.getClass()); }
      catch (JAXBException e) { e.printStackTrace(); }

      Marshaller m = null;
      try { m = jc.createMarshaller(); }
      catch (JAXBException e) { e.printStackTrace(); }

      PrintStream ps = new PrintStream(output);
      ps.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      ps.println("<?xml-stylesheet type=\"text/xsl\" href=\"your.xsl\"?>"); 

      try { m.setProperty(Marshaller.JAXB_FRAGMENT, true); }
      catch (PropertyException e) { e.printStackTrace(); }

      try { m.marshal(object, output); }
      catch (JAXBException e) { e.printStackTrace(); }
    }
  };
}

EclipseLink JPA in Eclipse dumb error message

Tuesday, August 11th, 2009

Sometimes you’re developing an app along with a new database schema to go with it, but you get this: Schema "null" cannot be resolved for table "XXXX".

Window -> Preferences -> Validation, JPA Validator, turn off for Build.

This probably shouldn’t be on by default anyhow, people are most likely going to build new apps from scratch than build new apps to fit old databases; and even if they do build from old, Eclipse’s JPA Tools has a build entities from tables function.

Here Men From The Planet Earth First Set Foot Upon the Moon, July 1969 A.D. We Came in Peace For All Mankind

Tuesday, July 21st, 2009

Here Men From The Planet Earth First Set Foot Upon the Moon, July 1969 A.D. We Came in Peace For All Mankind

Java development outpaces C# development on all platforms

Thursday, July 9th, 2009

Behold, the most FUD-filled pro-C# article in the few months.

“Mono is clearly more popular than Java. I’ve been using desktop Linux as my primary desktop for three to four years, and use just a handful of Java apps day to day,” O’Grady said.

According to the “Normalized Comparison” and “Normalized Discussion Site Results” on LangPop, the Internet’s largest programming language survey, Java is #2 on those two categories, C holds the #1 spot both, C# holds the #6 on “Normalized Comparison” and #7 on “Normalized Discussion Site Results”.

In other words, Java is the second most used programming language in existence. A language that is 37 years old and 23 years older than Java beats it and is the only one to beat it. C# does not even come close.

I’ve been using Linux as my primary desktop OS for over a decade, I use a handful of Java apps, however I use no C# apps and I do not even have Mono currently installed.

Ubuntu, a Debian-based operating system that is among the most popular desktop Linux distributions, currently packages version 3.1 of the Eclipse IDE along with MonoDevelop 2.0, the most current build. Eclipse 3.5 was released by the Eclipse Foundation on June 24, but it is not packaged by Debian.

Eclipse 3.1 lacks features that MonoDevelop has, including code completion, integrated debugging, refactoring, and unit testing capabilities, Hargett claimed. “I’ve found in my consulting that people who install Eclipse 3.1 through the [Debian] package manager say, ‘This is terrible.’ ” He said that customers that have installed a version of Eclipse beyond 3.1 like it.

The article is really shooting itself in the foot. It compares two Linux distros (Debian and it’s child, Ubuntu) and says they have an outdated Eclipse. I use Debian, Eclipse is written in Java, and all I do is download Eclipse off Eclipse’s website and run it instead of using the packaged version. No compiling needed; it runs correctly out of the box. I use the copy of 64-bit OpenJDK 6 that is already packaged in Debian.

If Matt Hargett has a bug to report (such as the Eclipse package being outdated), then I suggest he files it instead of trying to slur Debian or Java.

3.5 does include integrated debugging, lots of refactoring functions, and it has unit testing via the ever popular JUnit, and Eclipse has had such functionality for awhile. 3.1 was released in Jan 2006, or over 3 years ago. MonoDevelop wasn’t even usable 3 years ago

“The Java community has taken Linux for granted,” Hargett said. “The assumption is, ‘What else is Linux going to do for managed code?’ and the answer is Ruby on Rails and .NET. Anecdotally, I’m not seeing people developing new Java Web applications. I’m seeing ASP.NET and Ruby.”

The more I read this article, the more I wonder if this is just thinly-veiled anti-FOSS FUD instead of simply anti-Java. Most custom enterprise and web service software is written in either Java or Perl. I’ve never seen Ruby used at a major company that didn’t do it just to blow their own horn about being different, and I’ve never seen an ASP.NET web app that ran on Mono on Linux instead of .NET on Windows.

I would also like to state that according to The Computer Language Benchmarks Game (aka Shootout), a popular synthetic languages benchmark that measures how slower a language is than C, Java scores an average of 1.68x slower, C# in Mono scores an average of 2.76x slower.

I’d rather use a managed language that is 2/3rds the speed of C than one that is 1/3rd. Mono development still seems to be very behind, despite articles like the one on SD Times claiming otherwise.