Tuesday, December 26, 2006

SOAP Client: A simple Web Services testing tools for Mac

I was discussing with a friend about SOAP testing tools. We all know SOAP UI that is a very powerful one, but I am also using a very simple one developed on Mac for Mac (cocoa based application), this application is SOAP Client:

Saturday, December 23, 2006

VMWare finally on Mac (Beta)

As Mac user I sometimes need to use Windows (too often...) or Linux computer, and for this I have been using either my PC or Parallels. Parallels is great but in my daily job my coworker are mainly using VMWare images....

VMWare has now open the VMware Virtualization for Mac Beta Program. If you like me need virtualization jump on it and give feedback...

Friday, December 22, 2006

A nice christmas present for Groovy and Grails project

The groovy project gets funding for its development. Big Sky is hiring Jochen Theodorou one of the Groovy commiter. For the people that do not know Big Sky, Big Sky is the company behind the the No Fluff Just Stuff symposium tour. Talking about this symposium, in 2007, Groovy and Grails will have a dedicated track.

More about this funding:


In addition to this very good news, here some other activities around Groovy and Grails:
  • Releases of Groovy 1.0 and Grails 0.4
  • Two books on Groovy and one on Grails.
  • A dedicated Groovy and Grails website: aboutGroovy.com
  • Also a dedicated Groovy and Grails conference: the Grails eXchange 2007
  • And the third Groovy Developer Conference in Paris at the end of January

Tuesday, December 5, 2006

Web Conference: Groovy & Grails UG London

The London Groovy and Grails User Group will be holding their next meeting on Wednesday, 6th December 2006 at Skills Matter in London and for the first time ever the meeting will be available via a live web conference, so don't worry if you are not in London! Speaking at this month's meeting will be Graeme Rocher, Grails Project Lead and CTO at Skills Matter. During his talk entitled; Grails Dynamic Tags: Making Tag Libraries Agile, Graeme will discuss Groovy Server Pages and its support for the creation of dynamic tag libraries without the need for configuration. John Wilson, Groovy Committer, will also be presenting at this meeting. During his talk, entitled; The MetaClass: How Groovy works Under the Hood, John will shed light on the MetaClass so you can better understand its' function and see how to use it to get your Groovy programs smaller, clearer and faster. For more information on attending this meeting or signing up for the web conference, please go to: http://skillsmatter.com/groovy-grails-ug

Monday, December 4, 2006

Calling a Web Services Protected using HTTP Basic

WS-Security provides a way to protect Web Services at the message level (SOAP) and it is independent of the protocol used (HTTP, JMS, ...). However, some services are still using HTTP based authentication for protection. JAX-RPC and its Oracle implementation provides a way to set the username and password in the client (Stub) using some properties on the Stub.

             ((Stub)port)._setProperty(Stub.USERNAME_PROPERTY, "username");
             ((Stub)port)._setProperty(Stub.PASSWORD_PROPERTY, "password");           

That's it...

Theses properties are shortcuts to the standard JAX-RPC properties:

                javax.xml.rpc.security.auth.username
                javax.xml.rpc.security.auth.password

This code is the same when you are using the Call interface.

Tuesday, November 28, 2006

OC4J: Sending system level message in the console window

OracleAS 10gR3, so OC4J standalone, is using the standard Java logging framework. Some of the benefits are easy configuration, and extensibility. The configuration of the level of logging of the different loggers has been exposes in the Oracle Application Server Console. To see the logger configuration, click on the Administration Tab and then Logger Configuration, you can then configure the different loggers.

Oracle ASC Logger Configuration

By default the logger will write all the information in the default log.xml file, and for application lever logger it will go in the application.log. You may want to send the information in the console during development to debug/analyze your application. This is done using the configuration of the Handler. This information is currently not available in the Application Server Console, so I am documenting in the next steps how to send the information in the console (terminal window).

The configuration of the OracleAS Logging is saved in the $ORACLE_HOME/j2ee/home/config/j2ee-logging.xml file. In this file you  can see that Oracle has defined various handlers where information can be sent:
  • console-handler : Log the information in the console (the one we want to use in this sample)
  • oc4j-handler : the default handler for most of the loggers, saving the information in the $ORACLE_HOME/j2ee/home/log/oc4j/log.xml using the Oracle Logger formatting
  • oracle-webservices-management-auditing-handler : the handler used by the Web Services Auditing feature in the $ORACLE_HOME/j2ee/home/log/wsmgmt/auditing/log.xml 
  • oracle-webservices-management-logging-handler : the handler used by the Web Service Logging feature in the $ORACLE_HOME/j2ee/home/log/wsmgmt/logging/log.xml 
As you may know, OracleAS Web Service provides out of the box support for Auditing of the SOAP messages. You just need to go in the administration page of the Web Service and enable the auditing. By default the messages are logged in the auditing log pointed above. But during development it is really interesting to see the SOAP Messages in the console without having to configure a Proxy to capture the request/response. The easiest way to do that is to edit the j2ee-logging.xml file and associate the console-handler to the auditing logger using the following configuration:

      <logger name="oracle.webservices.management.auditing" level="NOTIFICATION:1" useParentHandlers="false">
         <handler name="oracle-webservices-management-auditing-handler"/>
         <handler name="console-handler"/>
      </logger>
by doing this you will see the SOAP Message in the OC4J console that is running in your system.

console-ws

You can also use this configuration with any loggers available in OC4J.

Monday, November 20, 2006

Download the The Oracle Technology Network (OTN) "Greatest Hits"

The Oracle Technology Network (OTN) "Greatest Hits" is a compilation of the most popular technical articles, software downloads, podcasts, sample code, and documentation, we've published in a given 12-month period. The compilation provides you with convenient access to the "best" of OTN as well as an insight into the interests of the Oracle developer and DBA communities. - Oracle Technology Network (OTN) "Greatest Hits" page.

Monday, November 13, 2006

IBM article: JAX-RPC vs JAX-WS

I was discussing with a customer not familiar with the JAX-WS standard. I was writing him a mail explaining the difference when I found this nice article on the IBM DeveloperWorks library: * Web services hints and tips: JAX-RPC vs JAX-WS It is an opportunity for me to remind OracleAS users that the 10.1.3.1 stack in addition to the JAX-RPC support also provides support for: * Attachments with MTOM, Soap with Attachment and DIME * Annotations based development (JSR-181) that is part of JAX-WS * WS-Security and WS-Reliability

Friday, October 13, 2006

Using HTTPS with Web Services

Prerequisites:
In this article you have

  • already a Web Service deployed in OC4J that is running on the default HTTP port. The WSDL and Endpoint are available. In my sample the non secure Web Service endpoint is: http://127.0.0.1:8888/math-service/MathServiceSoapHttpPort

Add HTTPS to OC4J

Creating of the Keystore

The first thing to do to secure OC4J would be to create a new keystore that will contain the different certificates. The easiest way to do that for a Java developer is to use SUN's keytool:
keytool -genkey -alias oracle-server -dname "CN=Tug Grall, OU=Blog O=Grall And Co L=Redwood Shores, S=CA, C=US" -keyalg RSA -keypass welcome -storepass welcome -keystore server.keystore
You can copy the server.keystore into the $ORACLE_HOME/j2ee/home/config to simplify the next steps.


Configuring OC4J

OC4J stand alone is using the notion of Web-Site to expose HTTP resources (Web Applications). The default-web-site is define is he $ORACLE_HOME/j2ee/home/config/default-web-site.xml. To secure an OC4J you can follow the steps describe in the OC4J Security guide that I have summarized in the following section.

What we want to achieve for the purpose of the demonstration is to have OC4J using HTTP and HTTPS, on port 8888 and 4443 for example.

1. Copy default-web-site.xml to  secure-web-site.xml

2. Edit the secure-web-site.xml:
    2.1. Change the web-site tag by changing the port to 4443 and adding the element secure="true"
    2.1. Add the ssl-config element and point this to the new created keystore.
    The file looks like:

<web-site   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/web-site-10_0.xsd"
            port="4443"
            secure="true"
            display-name="OC4J 10g (10.1.3) Default Web Site"
            schema-major-version="10"
            schema-minor-version="0" >
        ...
        <ssl-config keystore="server.keystore" keystore-password="welcome" />
        ...
</web-site>

3. Import the new Web site in your OC4J instance by editing the $ORACLE_HOME/j2ee/home/server.xml file. You need to add or replace the web-site tag. In my case I want to add the secure web site to my instance so the configuration looks like:

    ...   
    <web-site default="true" path="./default-web-site.xml" />
    <web-site path="./secure-web-site.xml" />
    ...

Since we have copied the file from the default-web-site, all applications are available using HTTP and HTTPS

Start OC4J and test the HTTPS port

Start OC4J using the standard Java command or shell script, I am adding the Java Network debug flag that would help you to see what is happening at the SSL level.

    java -Djavax.net.debug=ssl -jar oc4j.jar

You should be able to access the service WSDL using the HTTPS port for example in my case:
  •     https://127.0.0.1:4443/math-service/MathServiceSoapHttpPort?WSDL


Consuming the Service using HTTPS

Generate and configure a client Keystore

Event if this is possible to use the same keystore for the server and the client, I will guide you in the steps to create a client certificate and import the certificate from the existing -server- one. Here the command to create a new keystore:
keytool -genkey -alias oracle-client -dname "CN=John Doe, OU=Blog O=MyDummyClient, S=CA, C=US" -keyalg RSA -keypass welcomeClient -storepass welcomeClient -keystore client.keystore

The next step is to export the certificate from the server keystore to be able to import it in the client:
keytool -keystore server.keystore -export -alias oracle-server -file server.cer

You can now import the cerificate in the client keystore:
keytool -keystore client.keystore -import -file server.cer

Generate the proxy

You have now the client certificate so you can use the Oracle Web Service Assembler to generate the proxy. The only specific thing you have to do is to specify which key store to use when running the tool. The command to use when generating the proxy is:

java -Djavax.net.ssl.trustStore=/Users/tgrall/ssl/client.keystore
     -Djavax.net.ssl.keyStore=/Users/tgrall/ssl/client.keystore
     -Djavax.net.ssl.trustStorePassword=welcomeClient
     -Djavax.net.ssl.keyStorePassword=welcomeClient
     -jar $ORACLE_HOME/webservices/lib/wsa.jar
     -genProxy
     -wsdl https://127.0.0.1:4443/math-service/MathServiceSoapHttpPort?WSDL


Calling the Service using secure endpoint

Configure the Java Environment to use the client store is made using the following System properties:
  • javax.net.ssl.trustStore
  • javax.net.ssl.keyStore
  • javax.net.ssl.trustStorePassword
  • javax.net.ssl.keyStorePassword
       
This could be done using different approach, property file, -D command line parameter or programmatically. To simply the example I am using the programmatic approach, the following code is part of the main method of the Client class:
  ...
   System.setProperty("javax.net.ssl.trustStore", "/Users/tgrall/ssl/client.keystore");
   System.setProperty("javax.net.ssl.keyStore", "/Users/tgrall/ssl/client.keystore");
   System.setProperty("javax.net.ssl.trustStorePassword", "welcomeClient");
   System.setProperty("javax.net.ssl.keyStorePassword", "welcomeClient");
   ...
   // Adding Debug information
   
System.setProperty("javax.net.debug", "ssl");
   ...


It is possible to change the Endpoint dynamically in the Proxy using the setEndpoint method.
  ...
  democlient.proxy.MathServiceSoapHttpPortClient myPort = new democlient.proxy.MathServiceSoapHttpPortClient();
  ...
  String ep = "https://127.0.0.1:4443/math-service/MathServiceSoapHttpPort";
  myPort.setEndpoint(ep);
  System.out.println("Result of the operation is "+ myPort.add(2,2));
  ...


You should now be able to run the client and call the service using HTTPS. This would look like:

JDeveloper: What are my System Properties?

I have been using JDeveloper for many years, since the first release ;-). But I've never payed attention to a simple and very useful feature. When you click the Help > About menu you can access all the System properties of the Java VM used by Jdeveloper by clicking on the Properties tab

JDeveloper System Property Viewer

Thanks to Gerard for the tip....

Thursday, October 12, 2006

Come to Oracle Open World and watch Mr Spring and Mr Apache speak

Oracle Open World is getting very close... And I am very excited to go to lot of sessions, two of them looks very interesting in the Oracle Develop track:

  • Rod Johnson - Spring Update: What's New and Cool in Spring 2.0 (Monday 10/23/2006, 12:45 PM - 1:45 PM in the Hilton Hotel Grand Ballroom A)
  • Brian Behlendorf - Bringing Open Source Software Development Practices and Principles Into Your Company (Tuesday 10/24/2006, 1:15 PM - 2:15 PM in the Hilton Hotel Grand Ballroom A)

This is quite exciting to have Open Source gurus coming to present to the Oracle conference, and explain how to use the new Spring in their projects or leverage Open Source practices to improve development in house... Take a look to the full program of Oracle Develop.

Start to use the Oracle OpenWorld Schedule Builder to organize your week in SF, if you have not registered yet for OOW click here.

Wednesday, October 4, 2006

Configuring the SOAP Address in OracleAS Web Services

When a JAX-RPC service is developped using OracleAS 10g R3 stack, the service URL http://server:port/context/serviceName, provide access to a test page and to the WSDL by adding the ?wsdl parameter to the URL. You can then use this URL to create services client with your tools of choice.

If you take a look to the WSDL, the SOAP address of the SOAP HTTP Port is dynamically generated based on the calling URL, for example if you have a service running on your machine:

http://127.0.0.1:8888/math-service/MathServiceSoapHttpPort?WSDL
will generate the following information in the WSDL
<service name="MathService">
    <port name="MathServiceSoapHttpPort" binding="tns:MathServiceSoapHttp">
        <soap:address location="http://127.0.0.1:8888/math-service/MathServiceSoapHttpPort"/>
    </port>
</service>

But if you are using another URL, for example the name of the computer:
http://tgrall-computer:8888/math-service/MathServiceSoapHttpPort?WSDL
will generate:
<service name="MathService">
    <port name="MathServiceSoapHttpPort" binding="tns:MathServiceSoapHttp">
        <soap:address location="http://tgrall-computer:8888/math-service/MathServiceSoapHttpPort"/>
    </port>
</service>

However in some case you may want to hard code this value to a specific location,for example to be sure that user will use the internet visible name, (no IP or intranet name), to do such thing you can use the  oracle-webservice.xml file and th <web-site> tag. This deployment descriptor is used to configure the service at runtime. In the following example I am forcing the service to use a new hostname and port:

<oracle-webservices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      .... >
    <web-site host="www.grallandco.com" port="80" />
    <webservice-description name="MathService">
        ...
        ...
    </webservice-description>
</oracle-webservices>...

This element and all other Oracle Web Services configuration elements are documented in the Oracle Web Service Developer Guide.

Thursday, September 21, 2006

Accessing User Principal in a Web Service

WS-Security provides a standard way to secure Web Services. Since based on SOAP it is agnostic of the stack you are using. When using JAX-RPC implementation, you are running in a J2EE container. In this post I am giving a tip to access the Principal object.

I have a service service, and I need to access some user information in its implementation class ( org.tug.ws.sample.SimpleServiceImpl ). This service is secure with WS-Security, with for example simple authentication, the following screenshot, is the configuration of inbound security in OracleAS 10gR3:

em-ws-sec-001


So the service is secured, here the code that you have to add in your service implementation (or handlers) to access the Principal object.

  1. Implement javax.xml.rpc.server.ServiceLifecycle
  2. Implement the init(Object context) method to access the ServletEndpointContext, that you can for example put as a local member of your implementation class.
        public void init(Object context) {
            _servleContext = (ServletEndpointContext)context;
        }
  3. Then you can access the principal object using the getUserPrincipal() method:
            ...
            if (_servleContext.getUserPrincipal() != null ) {
                Principal userPrincipal = _servleContext.getUserPrincipal();
                ...
            }
            ...
     
You can find more information about the Security in J2EE 1.4 Web Services in the Designing Web Services with the J2EE 1.4 Platform tutorial. 
Update on Wednesday october 4th: Frank Nimphius, has use this entry to create a more detail article about End to End Security with Web Services Security.

Tuesday, September 19, 2006

Choose a scripting language? Groovy or JRuby?

Last week I discussed dynamic languages with some consultants. This discussion was done in the context of integration of scripting technologies into Java EE environment. So the integration to the VM is important, I also think that the learning curve is a thing to consider.

It is true that, like any developer Iike to learn things everyday, this is why I have done some development with PHP, with Ruby On Rails, and obviously with Groovy, Javascript and many other dynamic languages.

The discussion moved quickly to an argument about which language is the best... Hard to say, but I would expect that to be more productive in enterprise it is better to use a "Java Like" syntax that allows you to leverage the power of scripts. Based on this comment it is for me a no brainer to say that Groovy is more interesting to a core Java developer than JRuby (or other Jython, Jacl, ...). I do not even want to go in the details about VM integration, performances and so on...

So in this context, A. Sundararajan has posted a very interesting comparison of Java, Groovy and JRuby syntaxes.

Thursday, May 11, 2006

More Groovy at Javaone !

If like me you like scripting technologies and in particular Groovy and Grails, JavaOne 2006 will be a very good moment to learn more about it.

Beside the official sessions listed below, I would like to inform you of various events interesting for the Groovy community:

  • Informal “Groovy Community Meeting”, Thursday night 5pm around the Oracle Demobooth where Guillaume, Graeme and Dierk will give you an opportunity to learn more about these projects
  • Groovy presentations at the Oracle Booth in the pavillion
    • Intro do Groovy by Harshad Oak : Wednesday 17th at 3pm
    • Groovy In Action by Guillaume Laforge: Tuesday 16 at 5pm
    • Grails by Graeme Rocher: Thursday 18th at 3pm

The official sessions about Groovy and Grails are

BOF-0554 Dynamic Scripting Languages BOF  Tuesday
05/16/2006
10:30 PM - 11:20 PM
Moscone Center
Hall E 133
BOF-2521 Rapid Web Application Development With Grails  Thursday
05/18/2006
08:30 PM - 09:20 PM
Moscone Center
Esplanade 307-310
TS-1246 Simplify Enterprise Development With Scripting  Thursday
05/18/2006
11:00 AM - 12:00 PM
Moscone Center
Hall E 134
TS-3273 Groovy = Java™ Technology+ Ruby + Python for the JVM™  Wednesday
05/17/2006
02:45 PM - 03:45 PM
Moscone Center
Gateway 104
TS-3714 Flash-Gridding with Java™ Technology: Using Project GlassfishSM, Jini™/JavaSpaces™, and Groovy as an Environment for an Open Source, Self-Assembling Supercomputer  Thursday
05/18/2006
02:45 PM - 03:45 PM
Moscone Center
Gateway 104
TS-5386 Groovy Goes RFID with Smart Sensors for Real-World Control  Tuesday
05/16/2006
05:45 PM - 06:45 PM
Moscone Center
Gateway 104

Wednesday, May 3, 2006

Grails on Oracle (OracleAS and OracleXE)

OTN (Oracle Technology Network) Readers have noticed, that Oracle has published an article from Richard Monson-Haefel about Ruby On Rails on Oracle. This article introduces the Ruby On Rails framework and explains how to use it to access an Oracle database. (Oracle 10g Express Edition to be exact) If you are not familiar at all with Ruby On Rails, it is important to notice that it has nothing to do with Java, J2EE. It is a Ruby based framework. So yes Ruby On Rails is really interesting, powerful and so on... but for me as a Java developer I would like to do the same using Java (or equivalent) leveraging the investment that I have done in J2EE; also important I want to be able to deploy and manage applications that are developed this way using my tools such as Oracle Enterprise Manager Application Server Control. The paradigm "coding by convention" that is the driver of Ruby on Rails has been leveraged to developed a new framework: GRAILS. Grails uses Groovy as the underlying language, so it runs on a JVM and can leverage any existing Java API. If you are a Java developer you will find very interesting to use this framework to accelerate the development of Web applications. If you are not yet a Java developer but need to develop Web application faster, and deploy the to your J2EE application server, Grails is also a very good tools. Since I have started with Richard's article I will use the same application/database schema to develop my first GRAILS application, and also use the same structure in my article...(is it what we call lazy loading?)

What is Groovy? What is Grails?

Groovy is a dynamic language that leverage features from other languages such as Ruby, Jython, and Smalltalk. Groovy is running at the top of a Java VM and makes available any existing Java objects (so all the API) to Groovy. Groovy is currently under standardization with the JSR-241. You can learn more about Groovy on the Groovy site and is project leader's (Guillaume Laforge) blog. GRAILS is to Groovy what Ruby On Rails is to Ruby. Originally named "Groovy On Rails", this name has been dropped in favor of Grails to avoid confusion/competition. Like Ruby on Rails, Grails is designed to create CRUD (Create Read Update Delete) Web applications. You can learn more about Grail on the Grails site and is project leader's (Graeme Rocher) blog. Let's now dive in the sample application, for this, as stated earlier I am using the sample application described in the OTN articles.

Example: The product Catalog

Step 1: Set up the Oracle database

If you have not set up the schema and table from the article you just need to create the following objects:
CREATE TABLE comics (
id NUMBER(10) NOT NULL,
title VARCHAR2(60),
issue NUMBER(4),
publisher VARCHAR2(60),
PRIMARY KEY (id)
);
CREATE SEQUENCE comics_seq;
Based on the OTN article I have created this table in the ruby schema.

Step 2: Install Grails

Grails installation is straight forward and explained in the Installation guide, basically:
  1. Download the binaries (I used Grails 0.2)
  2. Setup the different environment variable (GRAILS_HOME, JAVA_HOME, PATH), I used Java 5.
You are done !

Step 3: create the Web Application

Now we have installed the product, the next step is to create the application itself. Create the application The create-app command is creating the full project, with the template with placeholder for the different components of your application such as configuration, MVC, and library and much more. To do it enter the following command, in your command line interface:
> grails create-app .... ..... create-app: [input] Enter application name: comics_catalog .....
As you will see, Grails uses Ant intensively, the create-app command will ask you for an application name, enter for example comics_catalog. The created application contains now a list of directory allowing developer to start to build the application using Groovy, Grails and any Web components. Add the Business Logic and Model: Domain Classes One of the biggest differences between Grails and RoR, is the fact that the main components of your application development is not the Table like you have in RubyOnRails but the "Domain Class". The domain class are the core of the business application, they contains the state and the behavior of your application. So the next step is to create a Domain Class for the Comics, to do that you just need to go in the home directory of your project, eg cd comics_catalog and run the create-domain-class.
> cd comics_catalog > grails create-domain-class .... create-domain-class: [input] Enter domain class name: comics ....
When the command ask you to enter the class name, enter comics. Grails, will not use the same naming convention that RoR has, so you need to use the same name for the class and the table you want to map your object on. The persistence layer is made using GROM (Grails Object Relational Mapping) that leverage hibernate. Note: In our case what we are doing is to leverage an existing database object and create the domain class at the top of it. Usually, Grails uses a different approach where everything is driven by the application, so you create the domain class first and then Grails will create the different database objects. The Comics class does not have any information related to the mapping itself, so you have to create the different attributes in the domain class. This is where you you start to use Groovy, the domain class is located in the following location:
  • ./comics_catalog/grails-app/domain/Comics.groovy
Note hat by default Grails create the class with 2 attributes: id and version, keep them in place, and add title, issue and publisher.
class Comics { @Property Long id @Property Long version // new properties for the Comics class @Property String title @Property Long issue @Property String publisher String toString() { "${this.class.name} : $id" } }
We are all set, we are ready to run the magic command that will create the different screens and flow. Create the different screens from the domain class You can now run the generate-all command to create all the different screens.
> grails generate-all .... input-domain-class: [input] Enter domain class name: comics ....
This command creates the different Views and Controllers, you can take a look to the directories:
  • ./comics_catalog/grails-app/controllers
  • ./comics_catalog/grails-app/views
Configure the database access What we have to do is now to configure the application to use the Oracle database and schema. Grails uses a configuration file for data source:
  • ./comics_catalog/grails-app/conf/ApplicationDataSource.groovy
Let's edit this file to connect to our Oracle database.
class ApplicationDataSource { @Property boolean pooled = true @Property String dbCreate = "update" // one of 'create', 'create-drop','update' @Property String url = "jdbc:oracle:thin:@localhost:1521:XE" @Property String driverClassName = "oracle.jdbc.OracleDriver" @Property String username = "ruby" @Property String password = "ruby" }
Nothing special concerning the properties such as URL, DriverClassName, username and password. The one that is interesting is the dbCreate, that allows you to configure the behavior on the schema to create or not objects.In our sample the table exists, so we want to reuse the object, but we want to be sure that we have all the mandatory objects, columns too, so I selected update. The next thing to do is to add the Oracle JDBC driver to the application, to make it available. To make it available you just need to copy the JDBC driver into the lib directory of your application. In my case I am using Oracle XE so I copy the file from the following location:
  • ORACLE_XE_HOME/app/oracle/product/10.2.0/server/jdbc/lib/ojdbc14.jar to
  • ./comics_catalog/lib/

Step 4: Run the application

Grails provide a way to run the application in stand alone mode, the command is run-app. This command starts an Web container (based on Jetty) with the application deployed.
> grails run-app
Note: Jetty will start on port 8080, in order to start in on a different port like e.g. 9090 use: grails -Dserver.port=9090 run-app You can now access the application using the following URL:
http://localhost:8080/comics_catalog/comics/
Your browser should show the list of comics from the Comics table.
List of Comics
You can create a new entry by clicking on the "New Comics" tab, and view/edit/delete existing record by clicking on the "Show" link.
Edit/Create entry
As you see the creation of an application is really easy. The next step is to deploy the application in your application server.

Step 5: Deploy the application

Grails provides a command to package the application as a WAR ready to be deployed, so in the root directory of your project you can run the following command:
> grails war
When you run this command you end with a WAR with the name of your application located in the root of your project, in our case: comics_catalog.war If you take a look to this WAR you'll see that it is quite big ~10Mb, this is because all the libraries are included in the Lib directory of the web application. You can see the exact structure of the WAR in the ./tmp (./comics_catalog/tmp/war) directory of the application. You can deploy the application as it is to Oracle Application Server 10g, but to avoid the issue with the class loader you should configure the Web application to load the local classes first. It can be done during deployment with the class loader configuration screen:
You can also save this configuration in a deployment plan to facilitate later deployment.
When the deployment is done you can access the application using the OracleAS host and port, something like:
http://localhost:8888/comics_catalog/comics/list
You can now administer and monitor the application like any other J2EE application deployed in OracleAS 10g. Better Deployment Options
  • I personally do not like the idea of shipping all the Jar files in the WAR file, so instead you can use the OracleAS Shared Libraries to create a Grails library by uploading and configuring all the Jars. And package the War without all these libraries.
  • Also you should be able to configure Hibernate/Spring to use a standard define Data source and use the JNDI name to lookup the connections.

Conclusion

GRAILS like Ruby On Rails are really interesting frameworks allowing developers to create quickly Web application that access relational database and especially the Oracle Database. Grails is quite new (release 0.2), but the documentation is really nice and complete. I will encourage all developers that are interested by such framework to use it and provide feedback to the development team. I will try provide other post about deployment of Grails on OracleAS, but also related to other interesting features of this framework, for example Ajax support, Validations etc etc.

Resources

Sunday, April 23, 2006

Oracle BPEL: Debugging "internal" SOAP Messages

When you develop applications that use SOAP based Web Services you very often use an HTTP proxy to capture the request and response that are exchanged between the clients and servers. For this you can use the Oracle HTTP Analyzer that is part of the toolset of Oracle JDeveloper, Axis TCP Monitor, or a packaged version of it that you have with Oracle BPEL Process Manager. BPELs are making extensive usage of SOAP messages, and it could be interesting to debug the different call to the partnerlinks. Oracle BPEL PM, to avoid HTTP calls and make optimized SOAP message when the partnerlink that you are invoking is deployed as a BPEL. So in the default configuration you do not see the different calls. In this article I explain how you can configure the server to be able to do it. For this I will be using:

  • Oracle BPEL Process Manager developer install running in an OC4J 10g Stand Alone (10.1.2.0.2)
  • obtunnel, that is a package version of Axis TCP Monitor located in <BPEL_HOME>\bin\obtunnel.bat
  • LoanFlow demo that you can install in 2 steps:
    • In a shell, go to <BPEL_HOME>\samples\demos\LoanDemo
    • Run the following command to deploy the LoadFlow BPEL and associated Web Services: > ..\..\..\bin\obant

Starting the Oralce BPEL Tunneling tool:

  • Just run the command <BPEL_HOME>\bin\obtunnel.bat You will see the following application:
By default the TCPMonitor launched from BPEL listens on the port 1234 and proxies for the default Oracle BPEL port 9700. So in this context you will capture all the requests is you access the server on the port 1234. It is not sufficiant here since the different partnerlinks endpoint are not dynamique and are set to the port 9700. So in this case you wont's see the request coming from the BPEL to a local partner link (and I am not talking about the SOAP Optimization yet). One way that I use to work around this issue in development --may be we have more simple solutions, but this is the one that I use-- is to change the port of the OC4J and make the proxy listening on the port 9700. In this case you will be able to capture the requests made from BPEL to its partnerlinks.

Changing the Port of OC4J and the TCP Monitor

I. Change the HTTP port of OC4J used by BPEL
  1. Open <BPEL_HOME>\system\appserver\oc4j\j2ee\home\config\http-web-site.xml
  2. Edit the port attribute of the root element web-site to enter a different value eg: <web-site port="9701"...
  3. Stop your BPEL Process Manager
II. Start a new TCPMonitor on port 9700
  1. In the TCPMonitor sceen click on the Admin Tab
  2. Enter 9700 for the "Listen Port #" field (since we want to be sure the partnerlinks are called correctly)
  3. Enter 9701 (or the value you entered for the HTTP port) for "Target Port #".
  4. Click Add
  5. Click on the new tab "Port 9700". If you have an error message like "java.net.BindException: Address Already in use: JVM_Bind" this is simply because your BPEL process manager is not stopped. In this case stop the BPEL server, and start the TCPMonitor by clicking the Start button.
III. Restart you BPEL Server Nothing special here you just need to start your server, and check that the BPEL PM is now listening on the HTTP port that you have entered, in my case 9701:
  • http://localhost:9701/BPELConsole
You can now go on the test page of the LoanFlow process (either on the port 9700 or 9701) and invoke the process. I am using 9701 since I want to capture the calls make by the Business Process to its partnerlinks. You can see some HTTP activities in your TCPMonitor, but if you look in details you only see request to the different WSDLs used by the LoanFlow... I was like you expecting to be able to see the different SOAP requests and response, but BPEL does some optimization around local SOAP calls. So to be able to capture these requests you just need to turn of this optimization.

Turning Off the SOAP Shortcut

  1. In the BPEL console, click on the "Manage BPEL Domain" link (top right)
  2. You arrive in the configuration tab, look for the optSoapShortcut property and set it to false.
  3. Click Apply
You can now go on the test page of the LoanFlow process (either on the port 9700 or 9701) and invoke the process. I am using 9701 since I want to capture the calls make by the Business Process to its partnerlinks. Now you can see all the SOAP requests and responses between the LoanFlow BPEL and its partnerlinks.
Click to Enlarge
Update on 08/02/2007 For people that are currently using Oracle BPEL 10.1.3.1 the optSoapShortcut is not visible anymore in the console, but it is still possible to configure this by adding it manually in the domain configuration file available at: $BPEL_HOME/domains//config/domain.xml

Wednesday, April 12, 2006

Grails on Oracle (OracleAS and OracleXE)

OTN (Oracle Technology Network) Readers have noticed, that Oracle has published an article from Richard Monson-Haefel about Ruby On Rails on Oracle. This article introduces the Ruby On Rails framework and explains how to use it to access an Oracle database. (Oracle 10g Express Edition to be exact)

If you are not familiar at all with Ruby On Rails, it is important to notice that it has nothing to do with Java, J2EE. It is a Ruby based framework.  So yes Ruby On Rails is really interesting, powerful and so on... but for me as a Java developer I would like to do the same using Java (or equivalent) leveraging the investment that I have done in J2EE; also important I want to be able to deploy and manage applications that are developed this way using my tools such as Oracle Enterprise Manager Application Server Control.

The paradigm "coding by convention" that is the driver of Ruby on Rails has been leveraged to developed a new framework: GRAILS. Grails uses Groovy as the underlying language, so it runs on a JVM and can leverage any existing Java API.

If you are a Java developer you will find very interesting to use this framework to accelerate the development of Web applications. If you are not yet a Java developer but need to develop Web application faster, and deploy the to your J2EE application server, Grails is also a very good tools.

Since I have started with Richard's article I will use the same application/database schema to develop my first GRAILS application, and also use the same structure in my article...(is it what we call lazy loading?)

What is Groovy? What is Grails?

Groovy is a dynamic language that leverage features from other languages such as Ruby, Jython, and Smalltalk. Groovy is running at the top of a Java VM and makes available any existing Java objects (so all the API) to Groovy. Groovy is currently under standardization with the JSR-241.  You can learn more about Groovy on the Groovy site and is project leader's (Guillaume Laforge) blog.

GRAILS is to Groovy what Ruby On Rails is to Ruby. Originally named "Groovy On Rails", this name has been dropped in favor of Grails to avoid confusion/competition. Like Ruby on Rails, Grails is designed to create  CRUD (Create Read Update Delete) Web applications.  You can learn more about Grail on the Grails site and is project leader's (Graeme Rocher) blog.

Let's now dive in the sample application, for this, as stated earlier I am using the sample application described in the OTN articles.

Example: The product Catalog

Step 1: Set up the Oracle database


If you have not set up the schema and table from the article you just need to create the following objects:
CREATE TABLE comics (
id NUMBER(10) NOT NULL,
title VARCHAR2(60),
issue NUMBER(4),
publisher VARCHAR2(60),
PRIMARY KEY (id)
);
CREATE SEQUENCE comics_seq;
Based on the OTN article I have created this table in the ruby schema.

Step 2: Install Grails

Grails installation is straight forward and explained in the Installation guide, basically:
  1. Download the binaries (I used Grails 0.2)
  2. Setup the different environment variable (GRAILS_HOME, JAVA_HOME, PATH), I used Java 5.
You are done !

Step 3: create the Web Application

Now we have installed the product, the next step is to create the application itself.

Create the application

The create-app command is creating the full project, with the template with placeholder for the different components of your application such as configuration, MVC, and library and much more. To do it enter the following command, in your command line interface:

> grails create-app
....
.....
create-app:
    [input] Enter application name:
comics_catalog
.....
As you will see, Grails uses Ant intensively, the create-app command will ask you for an application name, enter for example comics_catalog.

The created application contains now a list of directory allowing developer to start to build the application using Groovy, Grails and any Web components.

Add the Business Logic and Model: Domain Classes

One of the biggest differences between Grails and RoR, is the fact that the main components of your application development is not the Table like you have in RubyOnRails but the "Domain Class".  The domain class are the core of the business application, they contains the state and the behavior of your application.

So the next step is to create a Domain Class for the Comics, to do that you just need to go in the home directory of your project, eg cd comics_catalog and run the create-domain-class.
> cd comics_catalog
> grails create-domain-class
....
create-domain-class:
    [input] Enter domain class name:
comics
....
When the command ask you to enter the class name, enter comics. Grails, will not use the same naming convention that RoR has, so you need to use the same name for the class and the table you want to map your object on. The persistence layer is made using GROM (Grails Object Relational Mapping) that leverage hibernate.

Note: In our case what we are doing is to leverage an existing database object and create the domain class at the top of it. Usually, Grails uses a different approach where everything is driven by the application, so you create the domain class first and then Grails will create the different database objects.

The Comics class does not have any information related to the mapping itself, so you have to create the different attributes in the domain class. This is where you you start to use Groovy, the domain class is located in the following location:
  • ./comics_catalog/grails-app/domain/Comics.groovy
Note hat by default Grails create the class with 2 attributes: id and version, keep them in place, and add title, issue and publisher. 
class Comics {
    @Property Long id
    @Property Long version

    // new properties for the Comics class
    @Property String title
    @Property Long issue
    @Property String publisher

    String toString() { "${this.class.name} :  $id" }
}

We are all set, we are ready to run the magic command that will create the different screens and flow.

Create the different screens from the domain class

You can now run the generate-all command to create all the different screens.
> grails generate-all
....
input-domain-class:
    [input] Enter domain class name:
comics
....
This command creates the different Views and Controllers, you can take a look to the directories:
  • ./comics_catalog/grails-app/controllers
  • ./comics_catalog/grails-app/views

Configure the database access

What we have to do is now to configure the application to use the Oracle database and schema.

Grails uses a configuration file for data source:
  • ./comics_catalog/grails-app/conf/ApplicationDataSource.groovy
Let's edit this file to connect to our Oracle database.
class ApplicationDataSource {
   @Property boolean pooled = true
   @Property String dbCreate = "update" // one of 'create', 'create-drop','update'
   @Property String url = "jdbc:oracle:thin:@localhost:1521:XE"
   @Property String driverClassName = "oracle.jdbc.OracleDriver"
   @Property String username = "ruby"
   @Property String password = "ruby"
}
Nothing special concerning the properties such as URL, DriverClassName, username and password.

The one that is interesting is the dbCreate, that allows you to configure the behavior on the schema to create or not objects.In our sample the table exists, so we want to reuse the object, but we want to be sure that we have all the mandatory objects, columns too, so I selected update.

The next thing to do is to add the Oracle JDBC driver to the application, to make it available. To make it available you just need to copy the JDBC driver into the lib directory of your application. In my case I am using Oracle XE so I copy the file from the following location:
  • ORACLE_XE_HOME/app/oracle/product/10.2.0/server/jdbc/lib/ojdbc14.jar
    to
  • ./comics_catalog/lib/

Step 4: Run the application

Grails provide a way to run the application in stand alone mode, the command is run-app. This command starts an Web container (based on Jetty) with the application deployed.
> grails run-app
Note: Jetty will start on port 8080, in order to start in on a different port like e.g. 9090 use:
 grails -Dserver.port=9090 run-app

You can now access the application using the following URL:
http://localhost:8080/comics_catalog/comics/
Your browser should show the list of comics from the Comics table.


List of Comics

You can create a new entry by clicking on the "New Comics" tab, and view/edit/delete existing record by clicking on the "Show" link.


Edit/Create entry

As you see the creation of an application is really easy. The next step is to deploy the application in your application server.

Step 5: Deploy the application

Grails provides a command to package the application as a WAR ready to be deployed, so in the root directory of your project you can run the following command:
> grails war
When you run this command you end with a WAR with the name of your application located in the root of your project, in our case: comics_catalog.war

If you take a look to this WAR you'll see that it is quite big ~10Mb, this is because all the libraries are included in the Lib directory of the web application. You can see the exact structure of the WAR in the ./tmp (./comics_catalog/tmp/war) directory of the application.

You can deploy the application as it is to Oracle Application Server 10g, but to avoid the issue with the class loader you should configure the Web application to load the local classes first. It can be done during deployment with the class loader configuration screen:



You can also save this configuration in a deployment plan to facilitate later deployment.

When the deployment is done you can access the application using the OracleAS host and port, something like:
http://localhost:8888/comics_catalog/comics/list

You can now administer and monitor the application like any other J2EE application deployed in OracleAS 10g.

Better Deployment Options
  • I personally do not like the idea of shipping all the Jar files in the WAR file, so instead you can use the OracleAS Shared Libraries to create a Grails library by uploading and configuring all the Jars. And package the War without all these libraries.
  • Also you should be able to configure Hibernate/Spring to use a standard define Data source and use the JNDI name to lookup the connections.


Conclusion

GRAILS like Ruby On Rails are really interesting frameworks allowing developers to create quickly Web application that access relational database and especially the Oracle Database.

Grails is quite new (release 0.2), but the documentation is really nice and complete. I will encourage all developers that are interested by such framework to use it and provide feedback to the development team.

I will try provide other post about deployment of Grails on OracleAS, but also related to other interesting features of this framework, for example Ajax support, Validations etc etc.

Resources

Thursday, March 23, 2006

Google Data APIs

Google has published a new set of API (and format) to update and access data. It looks really interesing. These services are published using the REST paradigm and XML. Based on this protocol Google is now exposing its Calendar. I am currently playing around with it, really fun. A good opportunity for portlets and widgets developments... Note for Oracle JDeveloper 10g (10.1.3) users: I have define the GData and Calendar API as new library inside Oracle JDeveloper. But I had some issue compiling when I start to use any of the class coming from these library with the default configuration on Windows XP. I just switch from Oracle JVM to the standard JDK compiler in my project to avoid this "Error: Internal compilation error, terminated with a fatal exception". To do this it is quite simple. Double click on your project, choose compiler in the left tree, and check the "Use Javac" option to force JDeveloper to use the standard javac command. (I will have to find where this issue come from...)

Monday, March 13, 2006

Oracle Industrial Telnet Server (ITS): The OracleAS Hidden Treasure..

When I was working in Oracle Consulting I was surprised to see how many customers are using character mode applications, base on Oracle Forms. Lot of applications in wharehouses, harbour, ... are using telnet terminal, usually remote/mobile using RF networks.

Moving to Java on the server was very hard for them because of the lack of support for easy character mode development based solutions.

OracleAS 10g/ADFprovides such support with the Industrial Telnet Server (ITS). ITS is the telnet server running in a J2EE container as a J2CA adaptor, and uses JavaServer Faces to render the user interface. The advantage of using JSF for the UI, it allows developer to leverage automatically different renderers (HTML, Mobile and telnet) without changing the application.

Here an example of the different renderer provided by Oracle ADF Faces (Instant Messaging, PDA, HTML and Telnet) jsf-renderer.PNG

If you are looking for more information around Oracle ITS:

Thursday, March 2, 2006

Oracle Fusion Middleware and Microsoft Interoperability - Developer's Guide

Download the Beta version of the Oracle Application Server Developer's Guide for Microsoft Office Interoperability along with sample code (and other technical resources) from this new OTN page.

  • Windows Platform: Fusion Middleware is concurrently tested and delivered on Windows.
  • .NET/Windows Server System Integration: Fusion Middleware offers broad integration with Microsoft .NET and Windows Server System at multiple levels.
  • Office Interoperability: Fusion Middleware enables use of Office as the front-end for enterprise applications, as well as many ways to interact with enterprise information that can be read, parsed, and generated in Office-formatted documents.

Friday, February 10, 2006

SourceLabs SASH certified on Oracle Fusion Middleware

Oracle Fusion Middleware is now a certified platform for the SourceLabs "SASH" stack: Apache Struts, Apache Axis, the Spring Framework, and Hibernate. Visit this page to download free SASH software!

SASH is a distribution from SourceLabs that: 1. Reconciles library versions and dependencies across the entire stack. 2. Includes dependability fixes for the baseline open source projects 3. Is rigorously tested according to the CERT7 method. 4. Is commercially supported.

Friday, January 27, 2006

Is OracleAS Portal used on the Internet????

Just use google with a string used byOracleAS Portal URLs...


A little tip, but you will see that people are very creative with Oracle Portal 10g!

Wednesday, January 4, 2006

Javaworld: Jason Hunter's "New features added to Servlet 2.5"

Jason Hunter has published an interesting article about new features added to servlet 2.5. The focus of this article is like most of the JEE 5 goals all about simplification, easy of use, this is done by leveraging Java5 annotations (resources refences, life cycle support,...), some improvements around the web.xml, and cross context sessions support.