Another exciting Java event from our beloved JHUG, featuring sessions from Dr. Heinz Kabutz, Roman Strobl, Αlef Arendsen, Jonas Boner and Alexis M-Pouchkine (in order of appearance).
You can find the full program here.
Hope to see you there 🙂
Helping dev teams adopt new technologies & practices || InfoQ, QCon
“The Taming of the Stack Trace” by Dionysios Synodinos
Everything you ever wanted to know about the Java Stack Trace, but were afraid to ask.
(I’m thinking of posting all my Java related thoughts on java.net so you can check out my blog there or subscribe to it too.)
By definition Web Services (WS) have been designed to support interoperable Machine to Machine interaction over a network. In order to promote interoperability of Web Services, in 2002 the Web Services Interoperability Organization (WS-I) was founded which basically is an industry consortium that publishes profiles. A profile is a set of core specifications (SOAP, WSDL, etc.) in a specific version (SOAP 1.1, UDDI 2, etc.) with some additional requirements to restrict the use of the core specifications.
One of the three profiles you can actually find in their deliverables is the Basic Profile (official abbreviation is BP), which uses Web Services Description Language (WSDL) to enable the description of services as sets of endpoints operating on messages. Almost everybody is BP compliant: Glassfish Metro (JAX-WS RI), IBM WebSphere, Apache Axis 1.2+, JBossWS, ASP.NET 2.0.
The keyword here is “almost”…
There is a team at my workplace that administers the Greek School Network Directory Service which currently contains more than 170,000 entries including school accounts for email and dialup access, teacher accounts and several student accounts. For various reasons that you can find at my colleague’s blog there was a need to perform LDAP operations over WSs – in fact we had to “Move LDAP writes to Web Services”.
The server-point would actually perform the LDAP “writes” to the Directory Server and have a PHP WSs interface. For the PHP implementation, NuSOAP was chosen. NuSOAP is probably the most popular PHP SOAP implementation and is widely used, eg. in Amazon Web Services.
It is a group of PHP classes that allow developers to create and consume SOAP web services. It does not require any special PHP extensions. The current release version of NuSOAP at the time supports much of the SOAP specification. It can generate WSDL and also consume it for use in serialization. Both rpc/encoded and document/literal services are supported.
Here follows the skeleton of the PHP configuration for our deployment:
<?php // The library require_once('lib/nusoap.php'); // The services exposed require_once('myinterface.functions.php'); $server = new soap_server(); $server->configureWSDL('Interface',"http://server/interface.php"); $server->wsdl->schemaTargetNamespace="http://server/interface.php?wsdl"; $server->register('ExistsUser', array('SubsystemID' => 'xsd:integer', 'UserNumber' => 'xsd:string'), array('Status' => 'xsd:integer', 'ErrorMessage' => 'xsd:string', 'UserName' => 'xsd:string'), "http://server/interface.php",false,false,'literal', 'ExistsUser will return Status=0 if user does not exist, Status=1 if user exists and set UserName accordingly, Status=-1 and set ErrorMeessage if an error occurs. It should be used to check if user exists before creating username. UserNumber is the number the user has in the subsystem. SubsystemID is the numerical ID of the subsystem'); $server->service($HTTP_RAW_POST_DATA); ?>
NuSOAP was not BP compliant until a few days ago when CVS revision 109 of nusoap.php was introduced. The motivation for this article was the hard way we had to find out…
The system my team was responsible for was the client which would have to wrap the WS related code into Java POJOs that would either be used as library code or through portlets. Implementing the functionality we needed in Jetspeed portlets was another issue but it goes beyond the scope of this post.
For the Java WS framework there were several candidates like Apache Axis and JAX-RPC but we choose JAX-WS 2.1, both because of its elegant programming model and the fact that in the newly published Java EE 6 proposal JAX-RPC will be proposed for future deprecation.
Our development platform was NetBeans 5.5 which provided a powerful wizard that starting from the WSDL that NuSOAP published, created the necessary Java stub code for our operations.
This is a small portion of the WSDL for the operation ExistsUser:
… <message name="ExistsUserRequest"> <part name="SubsystemID" type="xsd:integer" /> <part name="UserNumber" type="xsd:string" /> </message> <message name="ExistsUserResponse"> <part name="Status" type="xsd:integer" /> <part name="ErrorMessage" type="xsd:string" /> <part name="UserName" type="xsd:string" /> </message> … <operation name="ExistsUser"> <soap:operation soapAction="http://server/interface.php/ExistsUser" style="rpc"/> <input> <soap:body use="literal" namespace="http://server/interface.php"/> </input> <output> <soap:body use="literal" namespace="http://server/interface.php"/> </output> </operation> …
Of course to debug Web Services you need tools like:
Of course the fact that the above development stack was found appropriate for our project doesn’t mean that it is suitable for every WS project. BTW a nice introduction on making similar technical decisions for Java projects can be found in the book Expert One-on-One J2EE Design and Development (AKA “The J2EE Bible”) by Rod Johnson in chapter 2 entitled “J2EE Projects: Choices and Risks”.
Java Web Services make use of the Holder concept that was introduced since WSDL can specify interfaces that return multiple parameters (rather than just one single return value). In Java you can only return directly a single new object through a return value. To return multiple objects you have to return a collection object (which is still only a single object) or some other "container" object. To return a new object through a parameter, you need a holder object. Java’s object reference parameters only allow the modification of existing object instances.
Holders are necessary because the Java language designers stuck with the "pass-by-value" semantics of the C-family of languages. If a parameter is a simple type its value is copied, if it is an object instance the reference (value) to it is copied. As a result you are unable to modify the value in the original simple type or the reference (value) to the object from the called method (while you can change the passed instance, you cannot replace the passed instance). The holder mimics "pass-by-reference" semantics which in C/C++ is is done with a pointer-to-a-pointer and in C# directly through the ref keyword.
Some consider attempts to imitate call by reference in OO languages a sign of poor object-oriented design. Dale King points out that attempts to fake call by reference are usually a sign of poor object-oriented design: “a function should not be trying to return more than one thing”. He uses the term thing because it is proper to return more than one value (e.g. returning a Point that contains two values). If you are trying to return two values, the test he like to apply is whether you can come up with a logical name for the values as a group. If you can’t, you had better look to see if maybe you what you have is really two functions lumped together. WSDL never strived towards OO so that is where this mismatch comes from. It may have been a better idea for Java to wrap the WSDL method return value and all of the OUT parameters into a single wrapper object which becomes the return value of the Java interface method.
For our implementation we had the WS method:
@WebMethod(operationName = "ExistsUser", action = "http://server/interface.php/ExistsUser") public void existsUser( @WebParam(name = "SubsystemID", partName = "SubsystemID") BigInteger subsystemID, @WebParam(name = "UserNumber", partName = "UserNumber") String userNumber, @WebParam(name = "Status", mode = Mode.INOUT, partName = "Status") Holder status, @WebParam(name = "ErrorMessage", mode = Mode.OUT, partName = "ErrorMessage") Holder errorMessage, @WebParam(name = "UserName", mode = Mode.OUT, partName = "UserName") Holder userName);
This method would return the status in the client:
BigInteger status = new BigInteger("0", 10); Holder statusHolder = new Holder(status); … // Actual call of the WS port.existsUser(subsystemID, userNumber, statusHolder, errorMessage, userName); … status = statusHolder.value System.out.println(status);
If you fire up the JAX-WS wizard in NetBeans and feed it with the WSDL you get 100% of the necessary code for an “almost” working demo.
Again the keyword is “almost”…
If you have Java SE 6 installed and start of with NetBeans and JAX-WS there is a big chance you’ll run into problems. Java 6 ships with JAX-WS 2.0 API in rt.jar (so as we had to find out) you need to download the latest stable version of JAX-WS (2.1.1) and copy jaxws-api.jar and jaxb-api.jar into JRE endorsed directory. Obviously you still need other JAX-WS jars in your classpath.
The above problem was relatively simple to solve compared to the fact that statusHolder.value would not alter after the WS invocation no matter what!
Although the WS would get invoked properly on the server and we would receive a SOAP response:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope …> <SOAP-ENV:Body> <ExistsUserResponse xmlns="http://server/interface.php"> <Status>1</Status> <ErrorMessage></ErrorMessage> <UserName>john</UserName> </ExistsUserResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
the @$%$# statusHolder.value would remain the same!
Weeks of debugging passed during which we had to dig into specs, JAX-WS RI code and forums to find out that:
Number one (1) has been reported to NuSOAP mailing list and we can confirm that it been fixed in CVS revision 109 of nusoap.php that should now conform to the WS-I Basic Profile (thanks Scott).
Number two (2) has been filled as an “enhancement” of JAX-WS RI for the version 2.1.3: “Ignore rpc/lit part accessors’ namespace, there are quite a few implementations that do not obey BP”.
At this point I cannot help but to quote Dave Podnar’s Five Stages of Dealing with Web Services:
Social Bookmarks:
Start counting:
The basic Javascript syntax fairly resembles C and since this language is an integral part of Computer Science curriculums all over the world, this means that developers are familiar with it, hence an easy leaning curve.
Again because Javascript was designed to have a similar look to Java, but be easier for non-programmers to work with its syntax is (fairly) understood by the vast majority of programmers.
I use the word “mimics” because the prototypical nature of JavaScript makes it very-very different from languages with class based inheritance (like Java or C++). Actually JavaScript is the only prototypical language that has managed to become mainstream, so JavaScript mastery is actually quite hard and requires lots of work!
You know it for more than a decade: if you want even the simplest form of dynamic functionality on a web page you need to write some Javascript. For a pop-up window, for client-side form validation, for a calculation, everything melts down to Javascript. There is the alternative of VBScript on IE but since it is not compatible with all the browsers its application is minimal.
The fact that Javascript has been ubiquitous for a decade in web development means that its basic syntax can be considered a common knowledge for developers, and the advanced features have an easy learning curve.
In the world of Web2.0 it is essential for a developer to understand advanced Javascript. There might be various other approaches for RIAs but still Javascript and XMLHttpRequest is king.
Currently there is a big effort to provide web developers with tools that ill allow them to build lightweight desktop applications, blurring the line between the two realms. In that direction Adobe has released AIR (Adobe Integrated Runtime) formerly code-named Apollo which is a cross-operating system runtime that allows developers to use their existing web development skills to build and deploy rich Internet applications to the desktop. Although you can use Adobe Flex for AIR applications my guess is that developers will favor the Javascript approach.
As I have pointd out in an older post, Google has rolled out Google Gears their open source browser extension that enables web applications to provide offline functionality using…. what else? JavaScript.
While many sweat to develop their scripting interfaces to Java, Mozilla Rhino has been there for ages and works! Again Rhino uses Javascript.
It just listened to a podcast this weekend from the founder of Alfresco the Open Source Alternative for Enterprise Content Management (ECM), that emphasized on the fact that they are slowly abandoning their direct Java development model and are increasingly using Javascript (Rhino) for scripting and interfacing with Java libraries.
Javascript has a robust, time proven implementation of DOM that makes it a worthy candidate for handling all kinds of XML vocabularies that a developer encounters.
Although nowadays you can find language specific implementation of this elegant data interchange format in many languages, it was originally used in Javascript and still most applications involve Javascript-based AJAX applications.
Even though it was the child of Netscape and its name “Javascript” is a Sun trademark, it enjoys acceptance by most vendors and has several implementation in various domains. Even MS has an implementation that bears the name JScript in order to avoid trademark issues
For all the above reasons I suppose it would be a good investment for a developer to brush up on his Javascript knowledge, going beyond basic syntax and applying methodologies like unit testing.
UPDATE: More stuff from Stevey’s Blog Rants: Rhino on Rails:
“Rhino, in contrast, has a great deal of momentum. It’s been around even longer than Jython; it began life as a port of the SpiderMonkey (Netscape/Mozilla) JavaScript C engine, and it was written with an eye for performance. The Rhino code base reads almost like C code: it avoids allocation and does as much as possible with jump tables to avoid the overhead of virtual method lookups. It has two code paths: a bytecode interpreter that runs in a tight loop, and an optimizing Java bytecode compiler that turns many expensive-ish JavaScript property lookups into Java local or instance-variable lookups.”
Unlike ALL mainstream scripting languages like Perl, Python, etc.Ruby Javascript actually has a real specification.
Bundled in Java 6 it will be javax.script.
UPDATE #2: While going through the book “Understanding .NET” (by David Chappell) I found out something I didn’t know:
Visual Studio also supports JScript .NET and because it’s based on the CLR, the .NET version of JScript also implements CLR-style classes, which can contain methods, implement interfaces, and more. JScript can be used for creating essentially any .NET application!
Social Bookmarks:
While recovering from mild surgery, I stumbled upon a post from Paris Apostolopoulos regarding the fact that the name Javascript is a bit misleading. I know there is a lot of media driven support towards Ruby, Groovy and similar “new” scripting languages, but I still find it natural to use Javascript as my preferred scripting language if I need Java libraries.
For this I use Mozilla Rhino, an open-source implementation of JavaScript written entirely in Java. Basically with Rhino you can import Java classes in your in your scripts and create objects.Here is a piece of Javascript (Rhino) code that uses the JasperReports (java) libraries:
importPackage(Packages.net.sf.jasperreports.engine); importPackage(Packages.net.sf.jasperreports.engine.data); importPackage(Packages.net.sf.jasperreports.engine.xml); importPackage(Packages.net.sf.jasperreports.engine["export"]); … var jasperDesign = new JRXmlLoader.load(getInputStream(documentURI)); var jasperReport = new JasperCompileManager.compileReport(jasperDesign); var jasperPrint = new JasperFillManager.fillReport(jasperReport, new Packages.java.util.HashMap(), dbConn); new JasperExportManager.exportReportToHtmlFile(jasperPrint, “myreport.html");
There are a lot of things to consider when choosing a scripting language and I’m sure that there will be people saying that Ruby is better in this way or Groovy in another way but Javascript/Rhino feels natural and has the minimal learning curve due to the similar syntax.
BTW the Rhino engine is an integral part of Apache Cocoon that supports continuations.
UPDATE: Read Stevey’s blog on “Rhino on Rails”
In an era where everybody has to offer something shiny for the development of the next generation rich internet (or rather networked) applications Google has released the beta version of Google Gears, their open source browser extension that enables web applications to provide offline functionality using JavaScript.
At first their product seems to have similar target audience with Java Web Start, that as we know never really took off. It is also interesting that Google’s proposal for offline apps is based on the traditional web development paradigm with:
You can either install Google Gear beta and check out the samples or visit this blog that features a nice set of screen shots.
Delving into the 3 separate sub-APIs (1, 2, 3) my overall impression is that Google Gears seems like a wining product. Actually I have no doubt that we’ll see several implementations. What I cannot predict is whether Google will choose to develop a Gear’s version of GMail that will shift the balance in the Email client market, inevitably hurting Mozilla’s Thunderbird.
Today (1st of June) is “Amalia’s Day” for Greek bloggers.
“Before dying, she managed to document her experience and share it with us in her blog http://fakellaki.blogspot.com. The promising literature graduate named in there each and every one of the doctors she had to bribe, praising at the same time the ones that honoured the Hippocratic Oath. Her testimony moved thousands of people that stood by her side all the way to the end.”
“Amalia passed away on Friday, May the 25th, 2007. She was just 30 years old.”
Recently I had an interesting discussion with a colleague of mine about the dangers of importing dynamic content in your web pages with AdSense.
Google suggests that since AdSense crawls the content of your pages it delivers ads that are relevant to your audience and your site content—ads so well-matched, in fact, that your readers will actually find them useful. My colleague was worried about the cases where the bot didn’t work as efficiently as it should and the ads that are included are irrelevant or even “damaging”.
Visiting mqseries.net a couple of minutes ago reminded me of this conversation:
… and sometimes it’s scary!
UPDATE: As a colleague of mine pointed out there are no references what so ever to the sources of these numbers and many of them would be very hard to calculate with statistics
… somebody has gone into the trouble of defacing them.
What can I say… it happens to the best families 🙂
With JavaOne heating up the news of yet another RIA product TM from Sun hit us. Only a short period of time after MS announced Silverlight, Sun seems to have rebranded the internal F3 project into something that looks like a declarative scripting language that will target desktop, web, and mobile devices.
Frame { visible: true content: Canvas { content: Mouse1d { width: 200 height: 200 } } }
There is an article on infoworld with more details.
The battle for RIA is raging and for the first time since the launch of Java and the introduction of applets in the ’90s, that Sun has something new to offer.
As a small update on an earlier article about how XML-based front ends favor the adoption of XML technologies throughout the stack, I would like also to mention a newcomer: Silverlight from Microsoft.
Silverlight is a cross-platform, cross-browser web client runtime which facilitates a lightweight subset of XAML for building rich media experiences on the web.
For a demo visit Silverlight homepage and install the demo plugin.
What will be the answer from Sun? Here is an interesting suggestion from Yakov Fain…
It is a fact: Google is using alien technology or I have just had a vision from the future.
Let me explain:
One of the Google services I use is Google Alerts to track newly published material in a variety of fields that interest me. As advertised on their page: “some handy uses of Google Alerts include: monitoring a developing news story, keeping current on a competitor or industry, getting the latest on a celebrity or event, keeping tabs on your favorite sports teams”.
Egocentric as it may seem, I also keep an alert on my name. Most results come from articles published or cross-published. Usually it takes days or at best several hours from their publication time, for new web pages to appear.
When I just posted my last article on Flex and saw it online, I visited my Gmail page and clicked on the tag for the Google alerts. Guess what:
In less than 90 seconds from posting to WordPress, Google Alerts had managed to find out about my new post and send me an email about it!!!
How the #@%&*% can you index the web so fast?!?
Social Bookmarks:
In older posts (or rather comments) I have mentioned that one of the biggest turn-offs for me regarding Flex was the fact that it was completely proprietary and closed… water-tight!
It seems that I wasn’t the only one with a problem so I just found out that Adobe plans to release source code for Flex as open source!
I don’t know how well this will work but it looks promising and as Yakov Fain mentions on his blog “there is already a decent number of developers who are interested in Flex and Adobe hopes that open sourcing Flex will bring more developers on board“
Some years ago we witnessed the spur of XML frameworks that aimed to accommodate XML front ends for WAP enabled application. This trend passed as the “multichannel dream” faded away but I see this fashion forming again.
Today RIAs either using Javascript–based AJAX or Flex front-ends have become heavy XML consumers and there are many that advocate that the use of XML technologies throughout the development stack gives a competitive advantage, as long as there are no serious performance issues. This involves the use of native XML DBs, XML aware protocols and XML based frameworks like Oracle’s XSQL or Apache’s Cocoon.
I have experimented with a “full XML stack” and found that there are certain benefits like the fact that you avoid the typical domain mismatch etc.
Will we see again an XML frenzy like back in 2001? I’m not sure…
With the new baby and all it almost slipped my mind but last week saw the JHUG leaders Paris and Panos joining the Java Champion Community. Congratulations guys and keep up the good work!
Delivered at Marika Iliadi maternity hospital on Tuesday 2007-03-27, 11:40pm
… and btw using the clone() method is always tricky 😉
For one more time the Java Hellenic User Group (JHUG) has provided the Greek developer’s community with an excellent event, where we had the opportunity to hear and learn from leading java experts. It was held in the “Park Hotel” and the facilities proved adequate even though the turnout was significant. The event was kindly sponsored by i-docs (IDEAL), which also held a lottery for an iPod at the end.
For those that couldn’t make it I will try to give an outline of the presentations using my notes. Since one of the things that stood out in this event was the authority of the speakers, the format will try to focus both to the subject and the presenter himself. I would like to notice that it is not feasible to write about everything that a speaker said, not to mention about the discussions that emerge during Q&A or the dialogs that take place during the breaks. That is why attendance to these kinds of events is irreplaceable! Posts like mine can only scratch the surface and give you a vague overview of the subjects presented.
Paris Apostolopoulos opened the event and spoke on behalf of the JHUG.
Summury was:
this.is.the.end(); [by Paris]
Dr. Heinz Kabutz is a Java Champion living in Greece. He consults, holds courses, programs, and – writes a weekly newsletter in which he shares some rather unconventional insights about Java. Things that push the envelope; make Java do things you thought it could not; dirty tricks and such. In other words, stuff you do not usually find in Java periodicals or newsletters.
You can find his newsletter at: http://www.javaspecialists.co.za/
It is always valuable to hear from Heinz. Every time I learn something new:
The speakers gave a very interesting presentation in Greek regarding the various products, technologies and technical decisions they had to take to implement the i-docs product. Although at the beginning I feared that this presentation might end up a marketing hoax, as it went along, it kept my interest high and actually it gave me a motive to check out a couple of things they have used. I would like to see more of this kind of presentations from the Greek developer’s community.
Tom Baeyens is the founder and lead of JBoss jBPM.
You can find his blog at: http://blogs.jboss.com/blog/tbaeyens/
-“Aaaaare youuu ready for some W O R K F L O W ?”
-…”yep”…
-I travelled all the way from Belgium to talk about workflow, and all I get is a “yep”??????
Patrick Linskey is also a Java Champion that has been working with Java Data Objects for over 3 years and has been involved in object/relational mapping for 5+ years. As the founder and past CTO of SolarMetric, Patrick drove the technical direction of the company. Patrick has been the primary evangelist for JDO, having publicly spoken to rave reviews in numerous cities worldwide over the past three years. He is an active member of both the JDO 2.0 and EJB 3.0 expert groups. He has also worked for TechTrader, MIT’s Media Lab, Bank One, and MIL 3 in various technical roles. Under Patrick’s leadership, SolarMetric has developed the market leading JDO implementation with over 300 customers throughout the world spanning all industries. Now at BEA.
You can find his blog at: http://www.jroller.com/page/pcl
You can find more information on “Using the Java Persistence API” presentation (video) by Patrick Linskey and Mike Keith.
Rod Hardwood is a lead developer and evangelist for the IntelliJ IDE “the most intelligent java IDE” as advertised by JetBrains.
UPDATE: Photos from the event (thanks papo)
UPDATE #2: Event got mentioned in java-champions.dev.java.net: “Dr. Heinz Kabutz ‘busy’ preparing for his talk at Hellenic JUG sponsored ‘Enterprise Java Tech Day’ in Athens Greece – Mar 10th, 2007 “
.
This is a list of some facilities the current NetBeans editor offers, that help me reduce the number of keystrokes I have to do when typing code. Basically it consists of my favorite abbreviations that generate code from templates, plus some shortcuts to commands and actions available in the source editor. Some of these abbreviations and shortcuts are ubiquitous in contemporary java IDEs and some are specific to NetBeans.
These type of tools along with some macros that suit your specific needs (either from within NetBeans or from an external macro utility), can speedup the task of getting the stuff from your head to the computer. Usually I have a bunch of cheetsheets printed on small pieces of paper and pinned on the frame of my monitor so there are available whenever I need them with out having to loose focus from the window I’m working on.
dowhile | do {} while (condition); |
forc | for (Iterator it = collection.iterator(); it.hasNext();) {Object elem = (Object) it.next(); |
ifelse | if (condition) {} else {} |
sout | System.out.println(“|”) |
trycatch | try {} catch (Exception e) {} |
!cd | <![CDATA[|]]> |
Ctrl-G | Jumps to any specified line. |
Ctrl-Minus (-) | Collapses the block of code the instertion point is on. |
Ctrl-Plus (+) | Expands the block of code the instertion point is next to. |
Ctrl-E | Deletes the current line. |
Ctrl-Shift-T | Comments out the current line or selected lines. |
Ctrl-Shift-D | Removes comment from the current line or selected lines. |
Ctrl-F2 | Sets or unsets a bookmark at current line. |
F2 | Goes to next bookmark. |
Social Bookmarks:
For those who might not know it, there is a game called “blogtagging” going around the blogosphere in which bloggers are sharing five things about themselves that relatively few people know, and then “tag” other bloggers to continue in turn.
I’ve been blogtagged by ppkp so here’s 5 things you (probably) didn’t know about me:
Now I pass the ball to Thodoros G. Karounos, Dimitris Andreadis and Spiros Tzavellas and Andreas Andreou…
Social Bookmarks: