Wednesday Oct 10, 2007

NetBeans YouTube Videos

In addition to, Sherry has been busy working on some You Tube Videos for NetBeans. There are several recent videos, one of which I participated in making. You can find a videos on:

I realized how difficult it is to produce one these videos!




Saturday Aug 25, 2007

NetBeans 6 Web Service Designer

NetBeans has introduced a Web Service designer, as you may have seen in Geertjan's blog. In addition to the ability to graphically view and modify operations for implementation first web services (WSDL is generated based on the JAXWS annotations), the web service designer provides the ability to work incrementally starting from a WSDL document. This represents a significant enhancement to the development experience as the WSDL document can become a first class source artifact, while the developer experience remains the same as the Web service designer provides the same implementation
 view. The add operation feature has also been extended to support the direct addition of XML schema. Direct addition of schema elements will perform an on demand generation of JAXB to provide a Java binding.


 Having the WSDL generated as part of deployment presents makes it difficult for composite application assembly tools, such as  the NetBeans CASA editor, to take advantage of the abstract WSDL binding capability of the openESB runtime. A composite application provides code composition based on well defined WSDL based interfaces. Since all the modules are deployed together and each WSDL interface is exposed on the service bus, developers can rely on bus endpoints instead of the concrete endpoints exposed in WSDL, thus achieving loose coupling as only the abstract WSDL is needed. The WSDL document can also be modified using the NetBeans WSDL editor to enhance the generated information such as adding documentation.

You will also notice the ability to see sample input and output messages. This is useful when working from Java types to see  how changes to the structure of Java classes will affect the XML messages.

This new feature is worth a look, you can find this in NetBeans 6.  

Tuesday Aug 21, 2007

Unit Testing HTTP Calls

I have been working with RESTful web services and had the need to verify the HTTP messages I was sending were appropriate. Since I am doing this work using Java SE 6, I was able to take advantage of the httpserver package. This package provides a lightweight HTTP server and is used for things like publishing web services and displaying memory graphs based on jmap.

The code to take advantage of this is easy. As you can see below, my strategy was to get an arbitrary open port on the local machine, bind a test handler to a context where the message is directed, and then verify what was sent matches what was expected.

 InetSocketAddress address = new InetSocketAddress(0); // get free port on local machine
HttpServer server =HttpServer.create(address, 1); // create a server on the arbitrary port
int portNumber = server.getAddress().getPort(); // get the port where this is bound for the invocation
MockHttpHandler handler = new MockHttpHandler(); // create a mock handler to capture the HTTP input
try {
    server.start(); // start the server
    server.createContext("/test",handler); // create a context with the mock handler
        } finally {
            server.stop(0); // stop the server after the test is complete

Sunday Aug 12, 2007

Free Open Source Desktop project management tool

I saw a link to an interesting free and open source desktop project management tool called OpenProj. The site mentions the tool available on Windows, Mac, and Linux is a compatible replacement for Microsoft project. 

Friday Aug 10, 2007

Working with Facebook Web APIs

I have recently been working with the Facebook APIs. I wanted to see how to incorporate Facebook data in a widget. By widget I am referring to reusable UI behavior which is driven by a set of services available via http. In contrast to the typical Facebook enabled web application, I wanted investigate the feasibility of using Facebook services as part of a mashup. Specifically, I wanted to ensure that without full page control (iframe embedding), it is possible to interact with Facebook services.

Here is what I did:

  1. From my Facebook account, I added the developer application. The developer application lets you create new Facebook applications. Creating a Facebook application generates a public and private key set which is required for invoking the APIs.
  2.  In order to start calling the API's to access Facebook profile information, authentication must be performed. The Facebook platform authentication mechanism is similar to the OpenId mechanism, whereby the Facebook platform actually performs the authentication and provides user information to the application. Since the target use case is to embed the widget within a Mashup and hence the reusable widget would not know the semantics of the page, the callback mechanism for web applications (after authentication on facebook, facebook redirects the browser to the provided URL) is not really appropriate. Facebook also provides a desktop authentication mechanism where a token can be generated, once the user is authentication (perhaps by launching a dialog or another browser window) the token is activated. The application can then obtains a session lease where the user id, the session id, the expiration time, and a session secret are provided. The widget can use the approach to generate the token before launching a facebook login. One problem with this approach is the exact order of obtain token, user authentication, get session must be preserved. If getSession is called before the user actually authenticates, then the token is invalidated and get session returns an error. This is a normal challenge with distributed authentication. The message signing is similar to other web APIs such as flickr, so that will be second nature to most people.
  3. Following, this I used the Facebook Query Language to start extracting data. This allows flexible queries (there are some limitations where the query must contain an index and there are no joins allowed) on different data sets.
Overall, the developer experience was positive. Developing a web application is very easy given the authentication callback mechanism, where a widget is more challenging.

Wednesday Aug 08, 2007

JavaScript code coverage tool

I came across this link to a tool for measuring JavaScript code coverage( I haven't yet had a chance to check it out but sounds interesting. 

Thursday Jul 26, 2007

Presentations about scalable web architecture

I came across the meta-presentation( on scalable web architectures. The lessons learned are interesting. 

Saturday Jun 16, 2007

Workaround to get more information for the JPA exception: During synchronization a new object was found through a relationship that was not marked cascade PERSIST.

I was getting a bit frustrated dealing with the JPA exception During synchronization a new object was found through a relationship that was not marked cascade PERSIST. The issue is that the message doesn't display the object in question. I wanted to grab the code and fix this issue, so here is what I did

  • download the persistence source from I am working with V1 so I used that version.
  • I copied the class I wanted to modify to my unit test area using the same package structure as in the persistence jar file. I am using NetBeans for unit testing so I adjusted the unit test classpath to put the test classpath ahead of the toplink essentials jar file which effectively replaces the class.
  • Looks like this is just a bug where the IllegalStateException thrown in RepeatableUnitOfWork line 115 (as we all know and love) is passing the object, so all that needs to be done is to fix the error message. I found ExceptionLocalizationResource where the error messages are stored and added a parameter to the new_object_found_during_comment message. I changed it to: "During synchronization a new object was found through a relationship that was not marked cascade PERSIST. {0}." This will provide the output of the toString method for the object where EntityManager.persist was not invoked. Since the toString is in the user space, this allows me to add any additional information to help figure out where to add CascadeType or call persist.

After doing this, additional information on which class (and the toString) is now contained within the exception message.

The glassfish tracking issue has been filed as 

Saturday Jun 02, 2007

Create Screencast from your browser

There is an interesting site offering screencast creation and hosting from your browser. Sounds like an interesting alternative.

Friday Jun 01, 2007

Unit Test Mantra

I just came across an interesting short and funny document on unit testing. I think the message is a good one. 

Thursday May 10, 2007

Interesting Class in J2SE 6

I was looking at the Javadoc for Java SE 6 recently and I came across the SchemaLoaderFactory javadoc. The javadoc mentions this class was not supposed to be part of Java SE. 

Friday May 04, 2007

NetBeans REST support

Given that Java One begins next week, I wanted to mention some really interesting technology which is available in  NetBeans 6.0 (milestone 9 build). This preview release provides the ability to generate REST services based on a set of JPA entity beans, which you can also generate using NetBeans. The REST services are annotated using the annotations proposed in JSR-311 (so this will change by the time the JSR is finalized). JSR 311 removes the need for service developers to use the Servlet or JAX-WS and instead provides a runtime and a set of annotations to handle dispatching of requests to your REST enabled resources. This feature also requires installation of the Sun Web Developer Pack which contains Phobos (JavaScript application server), JMaki, and of course the RESTful web services supported.

The wizard determines the set of entity beans available in a project and allows a set of beans to be selected and exposed as resources. In addition to generating the rest resource code, the wizard generates a converter layer which provides the ability to marshal and unmarshal to and from the wire protocol. Currently, the converters are using custom XML to serialize data; however, JSON and ATOM publishing protocol are also being considered. Finally, the converter layer translates object references (such as JPA references) into URI references. All the code generated by NetBeans is freely editable (no guarded blocks) and only relies on the JSR-311 annotations.

Accompanying the wizard is the ability to generate a test client to exercise the generated resources. The test client supports interaction with resource collections as well as individual resources through GET, PUT, POST, and DELETE (depending on the options available via the resources). The test client is generated locall and uses XHR for communicating with the resources, which should mimic most common architectures.

This is best to see in action, check out the video

Tuesday Apr 24, 2007

JavaScript documentation generator

I came across the JSDoc project recently which extends Javadoc like concepts into Javascript. The documentation and the procedure for using this are straightforward if you are used to javadoc. 

Sunday Apr 08, 2007

Blueprints article about using JPA in a web module

I came across this article about using JPA in a web module. Using JPA in a web only module is more difficult than using JPA in EJB because of the differences in the threading models. Using a request scoped managed bean makes things a bit easier as the injection model is similar to EJB. 

Friday Mar 16, 2007

Unit Testing using the Java Persistence API

I have been using the Java Persistence API  recently and I wanted to create some unit tests which did not run against the target database. Java Db which is bundled with both Glassfish and Java SE 6 is ubiquitous in my environment and supports running in embedded mode. This combination makes it ideal for mocking the database environment for unit tests.

If you look at the persistence.xml (NetBeans has a wizard to generate entity classes from a database), you will notice some properties (the properties will vary depending on the provider you are using) of the following form:

      <property name="toplink.jdbc.user" value="app"/>
      <property name="toplink.jdbc.password" value="app"/>
      <property name="toplink.jdbc.url" value="DataBaseConnectionString"/>
      <property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>

 The properties shown above are based on the TopLink provider and specify how to connect to the database. I wanted to override these properties to use an embedded database connection in my unit tests. The Persistence class provides two static methods for getting an EntityManagerFactory one of which takes a Map. The properties in the map can be used to override the properties defined in the persistence.xml file. I used a different set of properties for the connection string, user, password, and driver to support an embedded database. I also added the following property to the map:


Which will create recreate the database using the annotations. As part of the JUnit test's setup method, I would override the persistence properties, then establish a known database baseline before executing the unit tests. The combination of the ability to override the persistence manager and use an embedded database provides a nice mechanism for a cleanroom testing environment.





« June 2016