Thursday, July 22, 2010

HTTP 404 error -"A WebGroup/Virtual Host to handle <@contextroot@> has not been defined" in WebSphere AppServer

Have you come across the error "HTTP 404" in your Web Browser when you try to access your web application deployed in WebSphere?
But even though you may see this as the error in web browser this is a generic error code.The root cause to produce this error can be found by observing WebSphere server log files under WebSphere home directory. One root cause is " A WebGroup/Virtual Host to handle /AppName has not been defined" which i came across recently (In my case i used WebSphere 6.x).

In order to fix this particular error the Virtual Host of the deployed application has to be found in the first place.
Steps:
1. In Console Navigation Tree -> Applications -> Enterprise Applications
2. Click on the deployed application name
3. Web Module Properties -> Virtual Hosts

In my case it was "default_host" and this is the default host provided by the WebSphere application. If new virtual hosts are required other than the default host those can be added too.

Now we need to verify that the virtual host of deployed application has a host alias which is similar to our application urls' host and port.
Steps:
1. In Console Navigation Tree -> Environment-> Virtual Hosts
2. Click on the host defined for the application (In my case it is default_host)
3. Additional Properties -> Host Alias

In my case this was the issue. The host and the port in my application access url was not defined under host alias in default_host.
So a new alias has to be added to the particular virtual host which matches with the applications' host and port.Now WebSphere server need to be restarted to apply changes.
Then the web application should be able to access by using its access url (With the correct contextroot) without getting this error.

Tuesday, July 20, 2010

It is a New Day..New Hope

Being Independent..I don't know why i took so long to realize that the fact of every individual has to be independent. Yo may mislead. I am not telling you to break your relationships. It is about make your life more challenging, enjoying and meeting goals which make you feel proud & satisfied on your own perspective. Even though if we earn money somehow from somewhere we don't really feel happy spending them. But we feel more happy when we did something new to the world and get something in return.
I see my world with a new hope and in a new angle...I hope those who still didn't realize the value of life should follow me.
Have a great day!!!!

Sunday, July 18, 2010

Build an osgi service bundle and a consumer bundle using Maven Pax plugin and Equinox

In order to start Maven should be setup in your system.
In my machine i'm using Maven 2.2.1 and the OS is Windows XP.

Steps:
1. Go the parent directory where you want to creat the project in command prompt.
>cd\
>D:
>cd D:\NewBeginning\osgi

2. Generate the project

>mvn org.ops4j:maven-pax-plugin:create-project -DgroupId=example -DartifactId=com.xyz -Dversion=1.0-SNAPSHOT

You will find a folder which has a name simillar to provided artifactId above in your parent directory.

3.Go to the project folder in command prompt

>cd com.xyz

4.Start Equinox Container

>mvn pax:provision -Dframework=equinox

There you will get the Equinox prompt. Type "ss" to get a reports of summary status of all installed bundles.
Then type "exit" to get out of Equinox container.

5. Create OSGI service bundle

>mvn pax:create-bundle -Dpackage=com.myExample -Dname=service -Dversion=1.0-SNAPSHOT

There get created a bundle inside the current folder as "com.myExample" and inside you will see
a generated clsses of a sample service.
In order to make our own service bundle we will modify the code as follows:

• ExampleService.java ->(rename) MyFirstService.java

package com.myExample;

/**
* Public API representing an example OSGi service
*/
public interface MyFirstService
{
// public methods go here...

String sayHello( String text );
}

• ExamplServiceImpl.java ->(rename)MyFirstServiceImpl.java

package com.myExample.internal;

import com.myExample.MyFirstService;

/**
* Internal implementation of our example OSGi service
*/
public final class MyFirstServiceImpl
implements MyFirstService
{
// implementation methods go here...

public String sayHello( String text )
{
return("hi"+ text);

}
}

ExampleActivator.java->(rename)ServicePublisher.javapackage com.myExample.internal;

package com.myExample.internal;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.myExample.MyFirstService;

/**
* Extension of the default OSGi bundle activator
*/
public final class ServicePublisher
implements BundleActivator
{
/**
* Called whenever the OSGi framework starts our bundle
*/
public void start( BundleContext bc )
throws Exception
{
System.out.println( "STARTING com.myExample" );

System.out.println( "REGISTER com.myExample.MyFirstService" );

// Register our example service implementation in the OSGi service registry
bc.registerService( MyFirstService.class.getName(), new MyFirstServiceImpl(), null );
}

/**
* Called whenever the OSGi framework stops our bundle
*/
public void stop( BundleContext bc )
throws Exception
{
System.out.println( "STOPPING com.myExample" );

// no need to unregister our service - the OSGi framework handles it for us
}
}

• Change the osgi.bnd file found in com.myExample as follows:

Bundle-Activator: ${bundle.namespace}.internal.ServicePublisher

6. Delpoy OSGI bundle to OSGI runtime environment

>mvn install pax:provision -Dframework=equinox

Yo will get the Equinox prompt as follows:

osgi> STARTING com.myExample
REGISTER com.myExample.ExampleService

This means your service is deloyed. Do "ss" and look at the installed bundle summery

>ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.5.1.R35x_v2
1 ACTIVE com.myExample_1.0.0.SNAPSHOT

As you can see our service is deployed and in active state.
Now type "stop 1" to resolve our service and u will get

osgi> stop 1
STOPPING com.myExample

Type "exit" to return from Equinox container.

7. Create OSGI consumer bundle

>mvn pax:create-bundle -Dpackage=com.myExample.user -Dname=consumer -Dversion=1.0-SNAPSHOT

Since this is the consumer bundle we do not need a generated ExampleService and ExampleServiceImpl classes. Therefore these two classes need to be deleted.

• ExampleActivator.java->(rename)Consumer.java

package com.myExample.user.internal;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import com.myExample.MyFirstService;

/**
* Extension of the default OSGi bundle activator
*/
public final class Consumer
implements BundleActivator
{
/**
* Called whenever the OSGi framework starts our bundle
*/
public void start( BundleContext context )
throws Exception
{
MyFirstService myFirstService= getService(context);
System.out.println(myFirstService .sayHello(" world"));

}

/**
* Called whenever the OSGi framework stops our bundle
*/
public void stop( BundleContext context )
throws Exception
{

}

private MyFirstService getService(BundleContext context){

ServiceReference ref = context.getServiceReference(MyFirstService.class.getName());
MyFirstService myFirstService=(MyFirstService) context.getService(ref);
return myFirstService;

}
}

• Change the osgi.bnd file found in com.myExample as follows:

Bundle-Activator: ${bundle.namespace}.internal.Consumer


Before deloy the consumer bundle in OSGI runtime we need to add the Service bundle dependency to the consumer. TO do that you need to go inside the newly created consumer bunle.

>cd com.myExample.user

Then impot the service bundle as follows:

>
mvn pax:import-bundle -DgroupId=example.com.xyz -DartifactId=com.myExample -Dversion=1.0-SNAPSHOT

Now go back to the parent directory.

>cd..

8.Delpoy OSGI bundle to OSGI runtime environment

>mvn install pax:provision -Dframework=equinox


You will see “hi world” in your Equinox prompt.
That means our Consumer bundle has successfully communicated with the Service Bundle.
Type “ss” and you can get the deployed bundle summery.

Now it's your turn to try this.

Friday, July 16, 2010

Add new Dependencies to Maven pom.xml

If you want to add a dependency to your pom.xml in your Maven project how do you find these dependencies? You may remember some common dependencies. But for the other dependencies how do you find the appropriate groupId and artifactId.
For that you can use Sonatype Nexus Maven repository Manager.
So in your pom.xml add the dependencies you required for your project and run "mvn install" which will download all the dependencies to your local Maven repository.

Wednesday, July 14, 2010

Don't be a follower...Make others follow you

Every human being born to this worlds with lots of talent.
In the past I believed its the destiny which makes us feel good or bad.
But its not always the truth. We are responsible for what we already have
and what we will be getting in the future.
Most of the people in this world has similar daily routing to get up in the morning,go to office, comeback home, go to sleep and then again in the next morning follow the same routing again and again.
But we are here to serve the people and the world.
It may be just a one thought which could change our life and we may be the leader from that point onwards.We need to figure out what we want and need to work to achieve that, because nobody is there to get it for us. Our family members, friends and people who care for us can help when we are upset but to completely recover from it we need to find a solution within ourselves.
Otherwise people may see you as a useless fellow who is not just wasting her time but also others time as well. So we always need to be passionate about what we do and seek for positive areas which could improve our selves. If you feel like you don't get what you wanted then you need to rethink and make a decision to
get it on your own way.


I know some may laugh at me because of me saying this. But i am sure those who really there for me all the time will understand my thoughts.So be different from the others, do a different thing and you will become a Leader not a Follower.
Good Luck!!!

Spring Dynamic Modules

It is a moduler approach based on OSGI framework. Even though we talk about less coupled and highly cohesive applications its most of the time about the design. The design is done with less coupling and high cohesion. But its' outcome is a war/ear file which is again a single file. But with OSGI you can create bundles written in java programming language which are basically jar files which differes from ordinary jars because of the MANIFEST.MF that comes alone with each jar file. OSGI bundles has the capability of publishing and consuming services so that it considered as "SOA in a JVM". Spring DMs has all this handy features supported by OSGI framework.

Tuesday, July 13, 2010

New Beginning

Its me...Miss Punnadi Gunarathna. Its always about my name :D I hardly remember a person who for the first time pronounced my first name correctly. If I talk about me, I am a Computer Science and Engineering graduate from University of Moratuwa. Even though I wanted to start my own blog, I wondered what to post. This reason made me to leave my blog completely blank without any posts for more than an year. But today I suddenly remembered my blog and wanted to find out whether it is still there. So here it is still exists. So here we go..my very first post. Happy blogging Punnadi :)