Tuesday, May 13, 2014

Solution for wss4j module compilation failure while building WSO2 Carbon Kernel

Problem - Building WSO2 Carbon often ended up with the following error, if there is a mismatch in the JDK version.

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/rajkumar/workspace/Building-Carbon/kernal/4.2.0/dependencies/wss4j/1.5.11-wso2v6/src/org/apache/ws/security/kerberos/KrbTicketDecoder.java:[10,24] EncryptionKey is internal proprietary API and may be removed in a future release

[ERROR] /home/rajkumar/workspace/Building-Carbon/kernal/4.2.0/dependencies/wss4j/1.5.11-wso2v6/src/org/apache/ws/security/kerberos/KrbTicketDecoder.java:[11,33] EncTicketPart is internal proprietary API and may be removed in a future release

[ERROR] /home/rajkumar/workspace/Building-Carbon/kernal/4.2.0/dependencies/wss4j/1.5.11-wso2v6/src/org/apache/ws/security/kerberos/KrbTicketDecoder.java:[12,33] Ticket is internal proprietary API and may be removed in a future release

[ERROR] /home/rajkumar/workspace/Building-Carbon/kernal/4.2.0/dependencies/wss4j/1.5.11-wso2v6/src/org/apache/ws/security/kerberos/KrbTicketDecoder.java:[13,40] KeyUsage is internal proprietary API and may be removed in a future release

[ERROR] /home/rajkumar/workspace/Building-Carbon/kernal/4.2.0/dependencies/wss4j/1.5.11-wso2v6/src/org/apache/ws/security/kerberos/KrbTicketDecoder.java:[14,24] DerInputStream is internal proprietary API and may be removed in a future release

[ERROR] /home/rajkumar/workspace/Building-Carbon/kernal/4.2.0/dependencies/wss4j/1.5.11-wso2v6/src/org/apache/ws/security/kerberos/KrbTicketDecoder.java:[15,24] DerValue is internal proprietary API and may be removed in a future release

. . . . etc.


Solution - WSO2 Carbon supports Java 1.6, at this point of writing. Hence, if you build using Java 1.7, you will get the above error.
Install Java 1.6, set the environments variables accordingly and try to build.


Solution for java.lang.OutOfMemoryError: PermGen space error while building WSO2 Carbon

Problem - Building WSO2 carbon often ended up with the following error, if you haven't increase memory for Maven.

The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.codehaus.plexus.compiler.javac.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:56)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.codehaus.plexus.compiler.javac.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:56)
    at com.sun.tools.javac.main.JavaCompiler.(JavaCompiler.java:354)
    at com.sun.tools.javac.main.JavaCompiler.instance(JavaCompiler.java:88)
    at com.sun.tools.javac.main.Main.compile(Main.java:424)
    at com.sun.tools.javac.main.Main.compile(Main.java:353)
    at com.sun.tools.javac.main.Main.compile(Main.java:342)
    at com.sun.tools.javac.main.Main.compile(Main.java:333)
    at com.sun.tools.javac.Main.compile(Main.java:94)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:549)
 

Solution - Building WSO2 Carbon needs additional memory allocated to Maven. You can set it as below.

 

Step 1

Run the following command in your terminal to open .bashrc file, where you can set your environment variables.
 
sudo gedit ~/.bashrc

 

Step 2

Add the following line at the end of .bashrc file.
 
MAVEN_OPTS = "-Xms512m -Xmx1024m -XX:MaxPermSize=1024m"
export MAVEN_OPTS

Close the file.

 

Step 3

Reload/Restart the .bashrc file. Run the following command in terminal.
 
source ~/.bashrc

If you don't do this step, the effect will not be taken immediately . Maven will fail due to out of memory.

If you are still getting the same error, you need to increase the memory even more. Increase -XX:MaxPermSize=1024m parameter (like 2048m, 4096m etc.) in the Maven environment variable.


Saturday, May 3, 2014

Hello World Web Service - Apache Axis2


This post explains how you can develop, deploy and access web services using Axis2 from scratch. This is going to be a very basic tutorial. We are not going to use any IDE or building tools like Maven. But, by doing so, we can understand each and every aspects of developing, deploying and consuming web services. Next part of this tutorial explains how we can do the same thing easily using Maven.

We are going to develop a hello world web service using Apache Axis2. Apache Axis2 is nothing but a web service engine. You can develop, deploy and access web services using Axis2. 

 

Installation

1. Download the latest Axis2 binary distribution here.
2. Extract it to a convenient directory. Let's call it AXIS2_HOME.

You will get the following structure under your AXIS2_HOME.

 
That's it. You have installed it.

 

Running the Axis2 server

In your terminal, navigate to "AXIS2_HOME/bin" directory and run the following command.
sh axis2server.sh

If your server starts successfully, you will get something similar as below in your terminal.

 

Deploying services 

"AXIS2_HOME/repository/services" is the deployment directory in Axis2. You have to copy your axis2 service (yourService.aar) to this directory.

Point the browser URL to http://localhost:8080/axis2/services/
You will see all the deployed services.


If you click on one service, you can get access to it's WSDL.

 

Developing an Axis2 service

Okay, let's develop our hello world axis2 service and deploy it. 

Create a folder structure as bellow,



Create a class "HelloService.java" as bellow and save under "Service" directory.

Create a service descriptor "Services.xml" as bellow and save under "Service/target/META-INF" directory.

Run the following command from "Service" directory to compile the HelloService.java and move HelloService.class to target directory.
javac HelloService.java -d target/

 
Run the following command from "Service/target" directory to package your service.
jar -cvf HelloService.aar *

 
Let's deploy our service. Copy "Service/target/HelloService.aar" to "AXIS2_HOME/repository/service" directory.

Point the browser URL to http://localhost:8080/axis2/services/.
You will see that your HelloService is listed under deployed services.

Developing a client 

Having our service up and running, lets develop a client to consume our service.

Lets use wsdl2java tool to generate client stubs which will allow you to access the service.

You don't have to download wsdl2java separately. It is shipped with Axis2 itself. You can find it  at "AXIS2_HOME/bin/wsdl2java.sh".

Create a directory "Client".

In your terminal, navigate to "Client" directory, and run the following command to generate client stubs using wsdl2java.

sh AXIS2_HOME/bin/wsdl2java.sh -uri http://localhost:8080/axis2/services/HelloService?wsdl


 
 
Two classes (HelloServiceStub.java and HelloServiceCallbackHandler.java) will be generated inside your "Client" directory in the following package hierarchy.


These two classes allow you to access the service that we have deployed earlier. Lets create our client.

Create a class "Client.java" inside the same package as the above two classes,

Lets compile client codes. Create a directory "target" inside your "Client" directory. In your terminal run the following command from your "Client" directory. It will compile all java files and move .class files to target directory.
javac -extdirs AXIS2_HOME/lib/   src/org/apache/ws/axis2/*.java  -d target/
Please note that we are setting all required jars to our class path in the above command.

Lets run our client. In your terminal, navigate to "Client/target" directory and run the following command.
java   -Djava.ext.dirs=AXIS2_HOME/lib/   org.apache.ws.axis2.Client

You will get the following output in your terminal.
Response : Hello Raj

That's it. You have successfully implemented, deployed and consumed an axis2 service.

Thursday, May 1, 2014

Developing Web Application Using Jaggery - Part 2

This is part 2 of a series of Jaggery tutorials. This post explains the syntax of Jaggery and how to develop a simple application using Jaggery. 

Please go through part 1, Developing Web Application Using Jaggery - Part 1, if you don't know about Jaggery, how to install it, run it etc.

 

Jaggery Syntax 

Jaggery file extension is .jag (like Java file extension is .java)

The following is the syntax of Jaggery.



Everything wrapped between <% %> is Jaggery code. It means that everything wrapped by <% %> runs on server.

The print(msg); method outputs a server side variable to the document.

.jag file can contains HTML code. The above code can be written as below, 


Create a directory "myApp" and save the above file as "index.jag" inside "myApp" directory. 

You have successfully created your first Jaggery App.

Let's deploy it. If you don't know how to deploy it, please refer to part 1 of this series.

Copy myApp directory to Jaggery deployment directory which is JAGGERY_HOME/apps. 

Let's start the server. If you don't know how to start the server, please refer to part 1 of this series.

Run sh JAGGERY_HOME/bin/server.sh ( JAGGERY_HOME/bin/server.bat in windows) command to start the server.

Let's access your myApp application. Point the browser URL to http://localhost:9763/myApp/. You will have your myApp up and running.

Let's learn some more built-in functions as we need those functions in our part 3 of this series.

request

This is an object which holds properties and functions regarding the HTTP request that the client made to the server.

For example, 

getRemoteAddr() - returns client's IP
getMethod() - returns type of request

For more information, please refer here


session

This is an object which holds properties and functions regarding the current session of a client.

For example, 
invalidate() - destroy the session

For more information, please refer to here

application

This is an object which holds properties which are global to the entire application instance.

For example, 
put('propName', value) - saves the value in the name of probName.

For more information, please refer to here.

I guess these are enough for next part of this series.

Develop a sample e-banking application using Jaggery




Developing Web Application Using Jaggery - Part 1


Introduction

This series of tutorials gives you a basic understanding of Jaggery framework and its capabilities in web application development. This tutorial, part 1, explains a little bit about Jaggery and how we can install it.

Jaggery is a newly designed server side JavaScript framework. You might know about JavaScript that is used at the client side to control the interaction of the user with the browser. It controls the browser, decorate the page, validate fields and do more and more stuff at the client side. At the server side, you normally have your logic in programming languages such as Java or PHP. So JavaScript runs at your computer's browser. Java runs at your server.


Isn't nice if we can write the server side logic using JavaScript? Jaggery is the solution. So you can develop a web application using JavaScript only.

 
Installation


Download the latest Jaggery here
Extract it (jaggery-0.9.0-SNAPSHOT.zip in my case) to a directory you prefer. Lets call it JAGGERY_HOME 


You will get the following folder structure.


├── apps
├── bin
├── carbon
├── etc
├── INSTALL.txt
├── LICENSE.txt
├── modules
├── README.txt
└── release-notes.html



That's it. You have installed it.

 

Running the Server


In your terminal, navigate to JAGGERY_HOME/bin directory which contains all the Jaggery execution scripts.
Run sh JAGGERY_HOME/bin/server.sh ( JAGGERY_HOME/bin/server.bat in windows) command to start the server. It starts the default carbon server bundled with the framework itself.


If your server starts successfully, you will get something like below in your terminal, 

 

Deploy Jaggery Applications

JAGGERY_HOME/apps is the deployment directory. Deploy (copy) your Jaggery application to the deployment directory. You can find some sample application in the deployment directory including the taskmaster application.

 

Accessing Jaggery Applications

Point the browser URL to http://localhost:9763/taskmaster
You will have a web application, taskmaster application, running.

So if you deploy an application $myApp, you can access your application @ http://localhost:9763/$myApp

 

Developing Jaggery Applications

Please refer Developing Web Application Using Jaggery - Part 2