Tug’s Blog

My journey in Big Data, Hadoop, NoSQL and MapR

Netbeans : OC4J Support Available

| Comments

It has been a long time that I did not look in the update center and development wiki of Netbeans. And I have been very pleased to see that it is possible now to register OC4J 10g as a server in Netbeans 5.5 (and 6.0). To add it in your environment just do a :

  • Tools > Update Center
  • Select “Netbeans Update Center Beta”
  • Select OC4J 10gYou can then configure a new Server and run/stop the server from your IDE.

You can follow the development of this plugin directly in the Netbeans Wiki OC4J Support page.

Spring and Oracle: I21 Blog Entry About Oracle Contribution to Spring

| Comments

Rod Johnson in the Interface21 team blog entry named “Oracle Contributing Oracle Application Server Integration Code to Spring Framework” described the contribution of Oracle to Spring framework.

This contribution allows Spring applications to leverage the OracleAS transaction manager and its features. In addition to this contribution and some previous investments of Oracle in Spring, see the Oracle and Spring page of OTN; Oracle continues to invest more and more in Spring, as contributor or as user since, as stated by Rod, Spring has an important roles in Oracle Fusion Middleware, and its upcoming Services Component Architecture offering.

OC4J Tip: Changing the Server Information

| Comments

When you are running OC4J in stand alone mode you are using the HTTP server that is bundle with it. This HTTP server returns by default for the HTTP information the following information: Server: Oracle Containers for J2EE

If you want to change that you just need to set the http.server.header property. For example,

1
java -Dhttp.server.header="My blog on Oracle" -jar oc4j.jar

will now look like:

1
2
3
4
5
6
7
8
HTTP/1.1 200 OK
Date: Mon, 26 Feb 2007 21:52:53 GMT
Server: My blog on Oracle
Last-Modified: Mon, 09 Oct 2006 19:17:10 GMT
Accept-Ranges: bytes
Content-Length: 19882
Connection: close
Content-Type: text/html

Thanks to James Kirsh for this very useful tip…

The First International Grails eXchange 2007

| Comments

Packed with presentations on Grails, Groovy, Ajax & Web 2.0 and JavaEE and the core technologies that support the Grails technology, the first Grails eXchange conference (London from May 30th to June 1st) will be the place to be for any member of the Groovy/Grails community… You can already register on the conference web site: http://www.grails-exchange.com

Come to see speakers including Grails project lead Graeme Rocher, Groovy project lead Guillaume LaForge, creator of Spring Rod Johnson, Dojo’s Alex Russel and Dylan Schieman as well as speakers from technology-leading organisations such as Google, Interface 21, JBoss, Oracle & Sun Microsystems

Groovy 101: Extracting XML From Your Database

| Comments

In the previous entry I showed how you can easily take an XML feed and insert the content in the database. Let’s do the opposite now, meaning taking the data out of your database as XML. In this post I am using the Sql Dataset again but to create an XML document, using the Groovy MarkupBuilder.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import groovy.sql.Sql;
import groovy.xml.MarkupBuilder;

def sql = Sql.newInstance("jdbc:oracle:thin:@//tgrall-linux:1521/XE",
"HR", "HR", "oracle.jdbc.driver.OracleDriver")
def set = sql.dataSet("EMPLOYEES");

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)

xml.employees() {
  set.each { emp ->
    employee(first: emp.first_name , last: emp.last_name) {
      email( emp.email )
    }

  }
}

println writer.toString();

As you can see, I use the builder to create XML Elements and attributes employee(first: emp.first_name , last: emp.last_name), I do reference the current record of the dataset (emp), and all this in very simple and concise code. This will give a result like:

1
2
3
4
5
6
7
8
9
10
11
12
<employees>
  <employee first="'Steven'" last="'King'">
    <email>SKING</email>
  </employee>
  <employee first="'Neena'" last="'Kochhar'">
    <email>NKOCHHAR</email>
  </employee>
  <employee first="'Lex'" last="'De">
    <email>LDEHAAN</email>
  </employee>
  ...
</employees>

So once again quite simple.

Groovy 101: Importing XML in Your Database

| Comments

A friend of mine was looking for an easy way to import some XML content in his database. You have many ways to do it. But the easiest for a Java/Groovy developer is to use Groovy, and I have create this small example for him.

Groovy provides really simple solution to parse XML and manipulate your database. The following sample reads an RSS new feed and import the title and link in a table named NEWS that contains two columns TITLE and LINK.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import groovy.sql.Sql;

def rssFeed = "http://www.javablogs.com/ViewDaysBlogs.action?view=rss";
def xmlFeed      = new XmlParser().parse(rssFeed);

def sql = Sql.newInstance("jdbc:oracle:thin:@//tgrall-linux:1521/XE",
"GROOVY",
"GROOVY",
"oracle.jdbc.driver.OracleDriver")
def set = sql.dataSet("NEWS");

(0..&lt; xmlFeed.channel.item.size()).each {
  def item = xmlFeed.channel.item.get(it);
  def title = item.title.value[0];
  def link = item.link.value[0];
  println("Importing $title ...");
  set.add(TITLE: title, LINK: link);
}

First I create a Groovy SQL object and a DataSet to manipulate my data sql.dataSet("NEWS"). Do not forget, if like me you are using Oracle database, to add the Oracle JDBC driver to your classpath ;-)

Then I create a loop on each items of the RSS feed I am using: (0..&gt; xmlFeed.channel.item.size()).each {...}. As you see, Groovy XML help me to parse, and navigate the XML document.

Like any Groovy iterator you have access to an implicit object available in the loop “it”, so I can get the item using the Groovy XML : xmlFeed.channel.item.get(it)

Then you can get the different values you want of the item element.Using the dataset.add method, you can insert them in the table.This is done using the value pairs notation column:value, this looks like: set.add(TITLE: title, LINK: link)

Oracle Web Services: Sharing Session Between Client Calls

| Comments

OracleAS Web Services Runtime provides a support for stateful Web Services that is based on HTTP /Servlet session. Some people will probably say that Web Services should not be stateful, or at least not based on the protocol… However, today most of Web Services are using HTTP, and in some specific cases it is very useful to be able to have a state.

In this post, I am not explaining how to enable stateful services and clients, since it is documented in the Java Classes and Stateful Web Wervices chapter of the developer guide. Here I am show you how you can using client side programming share the same state (session) between different web services calls (even different services running in the same server side application).

The tip used here is about the association of cookies to the client instance (JAX-WS Stub or Call object). Here the code you have to write to do that using DII, will be very similar when using static Stub

1- Enable the state management

1
2
3
4
5
6
...
Service service = sf.createService(qName);
QName port = new QName("CartService");
Call call = service.createCall(port);
call.setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.valueOf(true));  // this is necessary to be able to manipulate cookie
...

2- Create a Map that contains the Cookies and assign it to the call (or Stub)

1
2
3
4
...
 Map cookieMap = new HashMap();
call.setProperty(ClientConstants.COOKIE_MAP, cookieMap);
...

This specific step associates a map that will contains all the cookie with the call/stub instance. You will be able then to manipulate the Map to get or set the cookies.

3- How to get the JSESSION cookie

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private Cookie getJSessionCookie(Call call) {
  Map cookies = (Map)call.getProperty(ClientConstants.COOKIE_MAP);

  if (cookies != null && !cookies.isEmpty()) {
    Iterator it =  cookies.values().iterator();
    while (it.hasNext()) {
      Cookie cookie = (Cookie)it.next();
      if (cookie.getName().equals("JSESSIONID")) {
        return cookie;
      }
    }
  }

  return null;
}

Note that the Cookie object is an instance of Oracle HTTPClient.Cookie.

4- Utilizing the Cookie

So now you have all the information to be able to get the Session information when the stateful conversation has started;

In this example each time the call.invoke() is done, a counter is incremented on the server.

1
2
3
4
5
6
7
8
9
10
Call call = service.createCall(port);
call.setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.valueOf(true));  // this is necessary to be able to manipulate cookie
Map cookieMap = new HashMap();
call.setProperty(ClientConstants.COOKIE_MAP, cookieMap);
... // The session will only be created after the first invoke
call.invoke(...); // counter = 1 call.invoke(...); // counter = 2 since on the same session

... // the session is now created so you can get the cookie
Cookie mySession = getJSessionCookie(call)
...

You can now use the cookie in another call using the following code:

1
2
3
4
5
6
7
8
9
10
11
mySession ..  // was extracted from the call #1
...// now I am creating a new call instance (myNewCall) that could be in another class
Call myNewCall = service.createCall(port);
myNewCall.setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.valueOf(true));  // this is necessary to be able to manipulate cookie
Map cookieMap = new HashMap();
// add the cookie to the map this will add the cookie to the HTTP request so it will be associated to the same session (/state)
cookieMap.put(mySession,mySession);// associate the cookie Map to the call
myNewCall.setProperty(ClientConstants.COOKIE_MAP, cookieMap);
...
myNewCall.invoke;  // counter = 3 since we share the same session
...

Using this sample you have 2 instances of a client calling a service and reusing the same session -state-. You can also use the same approach to have 2 different clients talking to different services and share the same session. To do that you will have on the server side to use the HTTP Session directly to store your data between calls, and share it between services.

Oracle Application Server 10gR3: iHat

| Comments

When preparing a complex topology, where you have multiple HTTP servers ,talking with many OC4J instances, it is sometimes hard to understand what is going on. Oracle Application Server Control provides the complete view of your topologies in different pages. If you want to have a quick overview of your topology, you may want a more graphical view of your Oracle Application Server instance.

One of the tool that I use a lot to present OracleAS and its components is OracleAS Hi-Av Tool 10g (10.1.3) also known as iHat. This utility uses Oracle Process & Notification Manager (OPMN) to gather information of all the components used in your topology, representing it in a nice graphical viewer. In addition to use iHat to show the different components, I do also use that to validate my configuration.

In this case I am showing a specific instance, that contains 3 OC4Js instance, with 2 of them that are in the same group. When using iHat you will notice that you can, in addition to have some monitoring information start, stop, restart the different components directly from the view.

How do you install and start iHat?

1- Download iHat from Utilities for Oracle Application Server 10_g_ OTN page

2- Unzip it, and this becomes the $IHAT_HOME

3- You have an ORACLE_HOME that is pointing to one of the OracleAS instance, so you can start iHat using the follling command:

1
java -cp $ORACLE_HOME/opmn/lib/optic.jar:$IHAT_HOME/ihat.jar oracle.ias.opmn.ihat.WebServer 8181 $ORACLE_HOME

Using this command, iHat is starting an HTTP server on port 8181, and use the OPMN configuration of the $ORACLE_HOME that I you have entered as parameter. iHat provided other parameters such as the host-name and OPMN port if you want to connect remotely without dependency on the $ORACLE_HOME. All this, is documented in the readme file located in the iHat folder.

Grails 0.4 Released…

| Comments

The Grails developer team is pleased to announce the release 0.4 of Grails. The release can be obtained from the downloads page.

Notable improvements include:

  • ORM enhancements with support for more relationship types, easy transactions and criteria building, constraints to SQL schema mappings, and upgrade to Hibernate 3.2
  • All-new non-invasive plugin system for writing reusable plugins for Grails applications
  • Greater Spring integration thanks to a new syntax for scripting Spring (http://grails.org/Spring+Bean+Builder) and an upgrade to Spring 2.0
  • Easier unit testing of controllers and custom taglibs
  • Validation improvements, including support for inherited constraints and simplified size constraint handling
  • Automatic encoding of unsafe HTML characters and URL parameters in all scaffolding and taglibs
  • Fixes to support Grails on more containers such as GlassFish and over 200 issues and bugs resolved in JIRA
  • Grails now ships with Groovy 1.0!