Weblog

Out of Container EJB3 with OC4J

One big improvement in EJB3 is that you can test your entity beans outside the EJB container. You can find a description how to do this with oc4j (10.1.3) here: Using EJB 3.0 outside the container and here: How-To Build out-of-container example using EJB 3.0.

One thing these articles fail to document is how to use EJB3 out of container when you also have a container configuration file ejb3-toplink-sessions.xml. For out of container testing you don’t need this file, it is used by oc4j when deploying the application. I made a project which uses the out of container method for unit tests, but when i added the ejb3-toplink-sessions.xml file, the unit tests stopped working. In my case i got the following error:

Omschrijving uitzondering: Er is een fout opgetreden bij het opzoeken van de resource van de externe transactie onder de JNDI-naam [java:comp/pm/TransactionManager].
Interne uitzondering: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
	at oracle.toplink.exceptions.TransactionException.errorObtainingTransactionManager(TransactionException.java:112)
	at oracle.toplink.transaction.JTATransactionController.<init>(JTATransactionController.java:53)
...
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)

You can avoid these errors by setting the property EntityManagerFactoryProvider.EJB30_SESSIONS_XML_NAME_PROPERTY to some non existing file name like not-there.xml when you create an EntityManager. So the resulting code will be something like this:

public static EntityManager getEntityManager() {
    Map conf = new HashMap();
    EntityManagerFactory emf;
    conf.put("toplink.session.name", "hotel");
    conf.put("java.persistence.setup.config",
             "nl.hva.hotel.model.tests.TestEntities");

    conf.put("javax.persistence.provider",
             "oracle.toplink.ejb.cmp3.EntityManagerFactoryProvider");
    conf.put("jdbc.driver", "com.mysql.jdbc.Driver");
    conf.put("jdbc.connection.string", "jdbc:mysql://localhost/hotel");
    conf.put("jdbc.user", "hotel_owner");
    conf.put("jdbc.password", "hotel_owner");
    conf.put("toplink.platform.class.name",
             "oracle.toplink.platform.database.MySQL4Platform");

    conf.put(EntityManagerFactoryProvider.EJB30_SESSIONS_XML_NAME_PROPERTY,"not-there.xml");

    emf = Persistence.createEntityManagerFactory(conf);
    return emf.createEntityManager();
}

Oracle Forms performance testing

Do you want to know what the maximum number of users is that your Oracle Webforms application can support? Do you need to know how your application will perform with 100 users? A coworker just showed me a tool which will help you answer these questions: forms2test. With this tool you can performance test oracle forms applications.

Forms2test is a utility which enables you to record an Oracle Forms session and replay it with any number of users. It records the data communicated between the Forms applet and the Forms server. This data is used to replay your session. So it doesn’t actually start 20 applets when simulating 20 users, it just starts 20 threads resending the data to the server. This will quickly give you an indication of the maximum number of users your server will support.

JDeveloper performance

Shay Shmeltzer’s post: Is your JDeveloper Slow? it shouldn’t be! just made my day. Just an hour ago i asked a co-worker if he also experienced problems when running jdeveloper on a laptop on battery power. And now Shay already posts the solution: -Dsun.java2d.ddoffscreen=false. Thanks! This is a bug in swing btw. More info can be found here: bug 5095398.

His first point is also very true, don’t run JDeveloper on 256Mb. I would like to add: don’t even run it on 512Mb if you’re using the visual editors. I’ve given two presentations at Universities this week on building webapplications using EJB3,and JSF. After the presentation the students used JDeveloper to build a simple web application. The first part of the practicum, implementing the model layer using ejb3, was no problem on 512MB, but once the students started to use the visual JSF editor in JDeveloper things got very slow. The visual editors eat a lot of memory, and you also need to run oc4j to test your application.

Brian Duff has some useful tips on using JDeveloper with limited memory: Memory and JDeveloper Performance: change startup option AddVMOption -Xmx512M. Another useful tool can be found on Gerard Davidsons weblog: KeepResident 0.2 for JDeveloper 10.1.3 EA, which will make sure windows doesn’t swap out jdeveloper when memory gets tight.

Integrate the Oracle BPEL WorklistService with Portal/SSO

Oracle BPEL release 10.1.0.2 contains a BPEL Worklist portlet that you can deploy in the same OC4J container where the BPM is running in. You can subscribe the portlet provider with your Oracle portal installation and use the portlet in your portal page to browse the worklist tasks and view the statistics in a portal page where the security is controlled by SSO. This all works perfectly.

When you try to make your custom worklist application that can be used as portlet in Portal behind SSO, you think that you have to use the same piece of code Oracle used to makes things work.
Oracle uses an authenticated HttpServletRequest object to login to the WorklistService and retrieve a context for it:

IWorklistService client = WorklistService.getInstance();
IWorklistContext ctx = client.createContext(request);

However, when you try to deploy your custom worklist application in the same way you deployed and configured the Oracle BPEL worklist portlet, you will discover that it will not work for your custom application. The application complains about the fact that it can not find a RemoteUser object in the HttpServletRequest object.

After decompiling the WorklistService class, you will discover that the createContext methode expexts a RemoteUser object in the request object. Apperently, Oracle Portal doesn’t set the RemoteUser in the HttpServletRequest object that is passed to the application. Why this all works for Oracle’s implementation of the BPEL worklist portlet is for me still a miracle.

When you further exam the code of the WorklistService class, you will see that only the SSO username is used from the RemoteUser to create the WorklistService context. But wait a minute..if the username is the only thing we need, we can also make it available in a different way. You can retrieve the SSO username also from the PortletHttpServletRequest object. The tric to make things work is to define your custom WorklistService application, which is an exact copy of the native WorklistService class expect the methods createContext and
the private method createContextFromUser. These methods you have to change so that the username is retrieved from the Portal request object instead of the RemoteUser object.

In april 2006 BPEL 10.1.3 will be released, which probably will solve this problem in the changed Worklist API. Till that moment, you can use this workaround to integrate your worklist application with Oracle Portal and SSO.

Finally, I want to thank Sarah Chen from edmunds.com for supplying the solution on OTN BPEL forum

CVS improvements in JDeveloper 10.1.3

This post on Living Photoshop: Macintosh and the Intel switch, discusses some problems with xcode(Apple’s IDE) which might sound familiar to jdeveloper users.

According to Scott Byer the Visual Studio and Metrowerks IDE’s are more mature than xcode. One thing these IDEs do better is:

… to having stable project formats that are text-merge-able in a source control system.

This is also one of the biggest problems when using Jdeveloper 10.1.2 with a source control system like CVS. Quite often, after a cvs update, you’d have to close jdeveloper, open some “hidden” jdeveloper files with a text editor and manually solve the conflicts. So how do you deal with this? You don’t. Most people would just postpone commiting changes and getting updates, which actually increases the problem, because your sources will diverge more and more from the cvs repository. And then when you really can’t postpone any longer, you have a huge number of conflict.

Jdeveloper 10.1.3 solves a lot of these problems. Many of the files you could not edit manually in 10.1.2 can now be edited in a text editor within Jdeveloper, for example the adf data control and page definition xml files. Other files have been simplified to cause less conflicts. Another big improvement in JDeveloper 10.1.3 is the resolve conflicts window. This window really is a big help when resolving conflicts.

Netapps NFS-mount and 10GR2

While installing a 10G R2 database on redhat enterprise edition 3 I encountered a “ora-27054 – NFS file system where the file is created or resides is not mounted with correct options” while creating a new database. Browsing though metalink and the Database installation guide it appears that Oracle checks the options with which a NFS mount is mounted on the filesystem. This is new in 10G R2 and is done to ensure that no corruption of the database can happen.

Metalink note 338086.1 details the changes needed, these can also be found in the database installation guide. Be aware however that allthough some options that Oracle requires, like hard, are defaults they have to be set explictly! Failing todo so will stop the database creation.

Having thought to solve the problem by changing the mounts of the databasefiles I restarted the creation off the database only to fail near the end. Remember that Oracle creates by default the spfile on the software mount, so be sure to set the options for the software mount point the same as the database mountpoints. After thats everything else went smoothly giving me a nice clean database to work with.

The options below are needed for a NFS ,netapps, mount (/etc/fstab) for a non RAC database. rsize and wsize are offcourse changeable, however I have seen metalink notes that 8k size might give problems.
defaults,hard,tcp,nfsvers=3,suid,nointr,actimeo=0,rsize=32768,wsize=32768 0 0

Installing the Oracle Business Intelligence Suite (rough guide)

This post takes a step back from all the BI concepts and describes just how to get your own Oracle BI demo up and running.

When you’re new to Oracle and / or the Business Intelligence suite the sheer number of options and variety of tools might prove a bit daunting. This article tries to shed some light on which tools to download from technet.oracle.com and install them in the right order. I know these guides have a limited time in which they are useful and never entirely complete but it will help so set up the most important parts of the BI system.

Because Oracle supplies so many different tools I’ll just stick on a basic system using Oracle Warehouse Builder and Discoverer.

To start, download the following installation files (for windows):

- Oracle Application Server 10g release 2 (3 files)
- Oracle Warehouse Builder 10g release 1 (1 file)
- Oracle Database 10g Release 2 (1 file)
- Oracle Database 10g Client Release 2 (1 file)
- Business Intelligence Tools CD (1 file). This one is hidden in de Application Server download page, look for ‘ business intelligence ‘.

This download contains the Discoverer Desktop and Administrator which you’ll need to create EUL’s

- Alternatively you can also download the AS companion CD for extra data.

So when everything is downloaded proceed in the following order:

1. Install the Oracle Database and create your own database
2. Install the Oracle Database client tools
3. Install the Application Server in two runs (in this order):
a. The first install will be the infrastructure into a new AS database
b. The application server main installation

If installing on your laptop make sure you’re not connected to the network! Write down all your settings or make screenshots.

4. Install OWB
5. Install the BI Tools

The next things to do are to reshuffle your Oracle homes from the Universal Installer and set all the TNS settings right. When you can connect to all your schema’s from the Oracle client or any SQL Client you’re set to create runtime, metadata and target schema’s from the OWB installation programs (runtime assistant). Remember to create the target schema’s from there as well since OWB creates some tables for auditing and logging purposes.

All in all a very quick run through the installation but I hope it gives some sense of direction through all the different options.

Implement, deploy and call an EJB 3.0 webservice using Glassfish and JAX-WS

Playing around with EJB3.0 for a while, I decided to try the special webservice annotations set of EJB3.0 for deploying an EJB as a webservice.Looking at the documentation, I discovered that that this feature is based on the new Java XML webservice API called JAX-WS (JSR-224), which is in real JAX-RPC 2.0. I decided to build a EJB3.0 with special webservice methods in JDeveloper and deploy it on the Glassfish application server. Next, I developed a client for the webservice in Netbeans 5.0 using JAX-WS. I could have used JDeveloper for building the client, but I used Netbeans 5.0 for just trying a different IDE then the one I’m daily using ;) .

I chose JDeveloper 10.1.3 for developing the EJB3.0 webservice, because it has, as one of the few IDEs , build-in support for EJB3.0 development. The code below shows the stateless session bean with a single webservice method that returns a message.

@Stateless
@WebService(serviceName = "MyFirstEJB3Service")
public class WebserviceEJBBean implements WebserviceEJB {
    public WebserviceEJBBean() {
    }

    @WebMethod(operationName="HelloWorld")
    public String getHelloMessage(String s)  {
        return "Hello " + s + "\n" +"This is my first EJB3.0 webservice developed in JDeveloper and deployed on the glassfish platform";
       }
}

After you have generated a jar file for your EJB module, you login into the administration console of your Glassfish installation and deploy the jar file as an EJB module in the console (Applications -> EJB modules). After successfully deployed the module, you can test your webservice in the console (Webservices -> WebserviceEJBBean )

Ok, now we have implemented and deployed an EJB3.0 webservice on the Glassfish application server. It’s now time to make a client that consumes the webservice. Start your Netbeans 5.0 installation and make a new basic application project. Now you have to download the JAX-WS API binaries to you local drive and add them a s a library to your project. Now we have to generate artifacts to make the actual webservice call. JAX-WS contains a tool, called wsimport, to generate artifacts from a given WSDL file. You can integrate this tool as an ANT-task in your build file by inserting the following code in your project build file:

<!-- Overrides -pre-compile target
         java artifacts that will created and compiled to build/classes directory. -->
    <target name="-pre-compile">
        <mkdir dir="build/classes"/>
        <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
            <classpath path="${javac.classpath}"/>
        </taskdef>

        <echo>running wsimport</echo>
        <wsimport
            debug="true"
            keep="true"
            destdir="build/classes"
            package="wsimport.generated.myfirstejbws"
            wsdl="http://localhost:8080/MyFirstEJB3Service/WebserviceEJBBean?WSDL"/>
    </target>

Finally, add the following code to the main method of the application’s main class and run the application to see the message returned by the webservice.

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Response from the webservice: "+"\n"+Main.testService());
    }

    public static String testService(){
        //Use the generared artifacts to make the webservice invocation.
        MyFirstEJB3Service service = new MyFirstEJB3Service();
        WebserviceEJBBean proxy = service.getWebserviceEJBBeanPort();

        return proxy.helloWorld("Tom Hofte");
    }

I think with JAX-WS developing webservices and building clients for them becomes really easy by using annotation and the supplied tools like wsimport. Sun has done a great job with this new standard XML webservice API!

Technology
Ben jij slim genoeg voor IT-eye