How to Install GlassFish on CentOS RedHat Fedora

March 9, 2010 · Leave a Comment
Filed under: Featured, GlassFish, JAVA, Karmic Koala, Ubuntu, WebServers 

How to Install GlassFish ESB on CentOS / Red Hat / Fedora

I did my installation on a CentOS 5.4 and I confirm all works, just follow
step-by-step.

Download JDK 6u12
# cd /usr
# wget http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u12-linux-i586.bin?BundledLineItemUUID=wFlIBe.lB8gAAAElzSEadwyv&OrderID=8fxIBe.lQPoAAAEluyEadwyv&ProductID=1O1IBe.pLl4AAAEerDlTv_an&FileName=/jdk-6u12-linux-i586.bin

Download GlassFish 2.1
# wget http://dlc-cdn.sun.com/jbi/binaries/glassfishesb/v2.1/promoted/rc2/glassfishesb-v2.1-full-installer-linux.sh

Check current Java Version
# java -version
java version “1.6.0″
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK Server VM (build 1.6.0-b09, mixed mode)
# chmod +x /usr/jdk*
# ./usr/jdk-6u12-linux-i586.bin
Accept License, and enter

Adjust path
#vim /etc/profile
#OPENMQ_HOME=/home/mcf/MessageQueue/mq
JAVA_HOME=/usr/jdk1.6.0_12
PATH=/usr/jdk1.6.0_12/bin:$PATH
CLASSPATH=$CLASSPATH:.:$JAVA_HOME:$JAVA_HOME/lib:$OPENMQ_HOME/lib/jms.jar:$OPENMQ_HOME/lib/fscontext.jar:$OPENMQ_HOME/lib/imq.jar:$OPENMQ_HOME/lib
#CARBON_HOME=/home/mcf/wso2greg-3.0.0

#export OPENMQ_HOME CARBON_HOME
export PATH CLASSPATH JAVA_HOME
:wq
You may need to logout and login then:
# java -version
java version “1.6.0_12″
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Server VM (build 11.2-b01, mixed mode)

Create user
# adduser esb
# passwd esb
# mkdir /usr/local/GlassFishESBv21
# mkdir /home/esb
# chown esb:root -R /usr/local/GlassFishESBv21
# mv /usr/glassfishesb-v2.1-full-installer-linux.sh /home/esb
# chown esb:root -R /home/esb/GlassFishESBv21
# chmod 755 -R /home/esb/GlassFishESBv21

Add it to sudoers just for now
# vim /etc/sudoers

esb ALL=GRANT(ALL) ALL




:wq

Login into the Gnome interface localy (via VNC wont work)
with the esb user execute from /home/esb
# sudo bash glassfishesb-v2.1-full-installer-linux.sh

On the install GUI
Set NetBeans IDE to:
/usr/local/GlassFishESBv21/netbeans
Set Install GlassFish to:
/usr/local/GlassFishESBv21/glassfish

Now lets configure the service to autostart
# cd /etc/rc.d/init.d
# vim glassfish

#Script to start/stop/restart GlassFish
# chkconfig: 35 20 80
# description: GlassFish ESB 2.1 Daemon
GFPATH=/usr/local/GlassFishESBv21/glassfish/bin
case “$1″ in
start)
${GFPATH}/asadmin start-database
${GFPATH}/asadmin start-domain domain1
;;
stop)
${GFPATH}/asadmin stop-database
${GFPATH}/asadmin stop-domain domain1
;;
restart)
${GFPATH}/asadmin stop-domain domain1
${GFPATH}/asadmin start-domain domain1
;;
*)
echo $”Usage: $0 {start|stop|restart}”
exit 1
esac

# chkconfig –add glassfish
# chkconfig –level 35 glassfish on
# service glassfish start

Once the service start it Should Display:

Starting database in the background.
Log redirected to /usr/local/GlassFishESBv21/glassfish/databases/derby.log.
Command start-database executed successfully.
Starting Domain domain1, please wait.
Default Log location is /usr/local/GlassFishESBv21/glassfish/domains/domain1/logs/server.log.
Redirecting output to /usr/local/GlassFishESBv21/glassfish/domains/domain1/logs/server.log
Domain domain1 is ready to receive client requests. Additional services are being started in background.
Domain [domain1] is running [Sun GlassFish Enterprise Server v2.1 (9.1.1) (build b60e-fcs)] with its configuration and logs at: [/usr/local/GlassFishESBv21/glassfish/domains].
Admin Console is available at [http://localhost:4848].
Use the same port [4848] for “asadmin” commands.
User web applications are available at these URLs:
[http://localhost:8080 https://localhost:8181 ].
Following web-contexts are available:
[/web1 /__wstx-services ].
Standard JMX Clients (like JConsole) can connect to JMXServiceURL:
[service:jmx:rmi:///jndi/rmi://SERVERESB:8686/jmxrmi] for domain management purposes.
Domain listens on at least following ports for connections:
[8080 8181 4848 3100 3820 3920 8686 ].
Domain does not support application server clusters and otherstandalone instances.

To login via web go to

http://<serverIP>:4848

Notes:
Remeber to open firewall for ports required
Check with ps if service is running
Reference to official documentation at:
https://open-esb.dev.java.net/

Good Simple example with Glassfish and a RESTful webservice Using JMS

November 8, 2009 · Leave a Comment
Filed under: Featured, GlassFish, JAVA, WebServers 

In this little tutorial, we will create a simple MessageDriven bean. It will consume messages which are produced in a simple way by a RESTful webservice, We will also make use of Glassfish server and JMS. Let go!!

Preparation

Setup Glassfish

You need a clean installation of Glassfish (v2 or v3). I also recommend an IDE with Glassfish integration. Netbeans should be easiest as I’ve heard that it’s got the best Glassfish integration, but I am using Eclipse 3.5. I won’t cover the setup process in your IDE – if you’re having difficulties, please let me know.

The few basic steps you need to do is:

  1. Install Glassfish (e.g. /dev/glassfishv3/)
  2. Setup Glassfish in Eclipse via Window->Preferences->Server->Runtime Environments and point it to /dev/glassfishv3/glassfish. The result should look like this:
    serverconfig
  3. Add the “Server” view if it doesn’t show up yet and add a new Server (RMB->New->Server):serverconfig2
    You should get a server entry and be able to start and stop the instance.

    serverconfig3
    Please verify if that works, first. Now you can start up Glassfish.

Configure Glassfish

Open a command prompt or terminal in /dev/glassfishv3/bin/ and be sure that Glassfish is running. Then create the JMS queues in glassfish (works with v2 and v3) with the asadmin tool:

asadmin create-jms-resource –restype javax.jms.ConnectionFactory jms/SimpleConnectionFactory
asadmin create-jms-resource –restype javax.jms.Queue jms/SimpleQueue

The implementation

Now we need some code. We will use a MessageDriven bean to consume the messages and a RESTful webservice to produce them in a simple way. For the MessageDriven bean, create a “EJB project” (Eclipse: New -> Project -> EJB/EJB Project) and put the following class in there:


package de.tricoder.net.test.jms;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
* Simle message driven bean.
*/
@MessageDriven(mappedName = “jms/SimpleQueue”)
public class SimpleMessageDrivenBean implements MessageListener {

/**
* Default constructor.
*/
public SimpleMessageDrivenBean() {
}
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
try {
System.out.println(“Got message: ” + ((TextMessage)message).getText() + ” @” + System.currentTimeMillis());
} catch (JMSException e) {
e.printStackTrace();
}
}

}

simplejms1
Now we need a Web Project which contains the RESTful Webservice (Eclipse: New -> Project -> Web/Dynamic Web Project). Add the following class to that project:


package de.tricoder.net.test.jms;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.NamingException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

/**
* Example of a RESTful webservice producing messages for a JMS Queue.
* Call via http://localhost:8080/webservicetest/jms
* @author Matthias Fraass
*/
@Stateless // dependency injection won’t work without that
@Path(“/jms”) // path appended to context root -> http://localhost:8080/webservicetest/jms
public class SimpleJMSRestfulWebService {

@Resource(mappedName = “jms/SimpleConnectionFactory”) //= connection factorie’s JNDI name
private ConnectionFactory connectionFactory;

@Resource(mappedName = “jms/SimpleQueue”) //= Queue’s JNDI name
private Queue queue;

/**
* Our RESTful webservice
*/
@GET
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public String putMessage() throws NamingException, JMSException, NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
{
System.out.println(“called putMessage”);
javax.jms.Connection  connection = connectionFactory.createConnection();
javax.jms.Session        session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
long start = System.currentTimeMillis();
int i=0;
do
{
TextMessage message = session.createTextMessage();
message.setText(“Hello, JMS! #”+start);
messageProducer.send(message);
i++;
}
while (i < 1000);
long now = System.currentTimeMillis();
return “JMS produced 1000 messages within ” + (now-start) + “ms”;
}
}

simplejms2

Now you need to configure the Jersey Servlet in web.xml, so that it picks up the WebService. Put the following in betwen the display-name and the welcome-file-list tags.


<display-name>JMS1web</display-name>

<servlet>
<servlet-name>Jersey Web Application</servlet-name>

<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

<init-param>

<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>

</init-param>

<init-param>

<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>de.tricoder.net.test.jms</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>Jersey Web Application</servlet-name>

<url-pattern>/*</url-pattern>

</servlet-mapping>

<welcome-file-list>

This WebService will produce 1000 messages and output the time it took. We’ll use that to compare the performance of different distribution scenarios and message queue products during the course of the next articles.

Deployment

The last thing we need is the EAR project (New -> Project / JavaEE/Enterprise Application Project). Add the EJB and the Web project to the EAR project. The result will be:

simplejms3

You should now be able to deploy that in glassfish:

simplejms4

and then

simplejms5

The server.log (glassfish/domains/domain1/logs/server.log or in the Eclipse Console – be sure to switch to “server.log”) should output this:



INFO: DOL Loading time150INFO: endpoint.determine.destinationtype

INFO: Portable JNDI names for EJB SimpleJMSRestfulWebService : [java:global/JMS1/JMS1web/SimpleJMSRestfulWebService, java:global/JMS1/JMS1web/SimpleJMSRestfulWebService!de.tricoder.net.test.jms.SimpleJMSRestfulWebService]
INFO: Unknown loader org.glassfish.internal.api.DelegatingClassLoader@11b92ef class org.glassfish.internal.api.DelegatingClassLoader
INFO: Scanning for root resource and provider classes in the packages:
de.tricoder.net.test.jms
INFO: Root resource classes found:
class de.tricoder.net.test.jms.SimpleJMSRestfulWebService
INFO: Provider classes found:
INFO: Initiating Jersey application, version ‘Jersey: 1.1.0-ea 04/30/2009 06:59 PM’
INFO: Binding the EJB class de.tricoder.net.test.jms.SimpleJMSRestfulWebService to EJBManagedComponentProvider
INFO: Loading application JMS1#/C:/dev/glassfishv3/glassfish/domains/domain1/eclipseApps/JMS1/JMS1web_war/ at JMS1web
INFO: Deployment of JMS1 done is 992 ms

Then, point a browser to e.g. http://localhost:8080/JMS1web/jms/ and you should see “JMS produced 1000 messages within XYms” in your browser (doesn’t work with Chrome) The server.log should look like this:

INFO: called putMessage ..
INFO: Got message: Hello, JMS! #1257518116879 @1257518117079
INFO: Got message: Hello, JMS! #1257518116879 @1257518117089 …

Vóila! Your first JMS enterprise project is running! It is using the internal OpenMQ instance of Glassfish, which is running on port 7676 by default. That’s not *remote* messaging yet, but it can already enable you to asynchronously process tasks. That’s good for most smaller projects or local development and testing We will use that simple example as a starting point for the following, more demanding ;) tutorials which will do remote messaging.

Original Post : http://www.tricoder.net/blog/?p=128

Sun Publishes Glassfish vs. JBoss Comparison Guide

October 21, 2009 · Leave a Comment
Filed under: Featured, GlassFish, JAVA, JBoss, Weblogic, WebServers 

Poor Redhat.  First SpringSource declares war and now Sun is joining in.  Today Sun made available a 14 page Glassfish vs. JBoss Comparison Guide, (Sun login required to download).  Check it out.  It actually makes for pretty interesting reading and if I was eager to see Redhat/JBoss’s response to SpringSource, they’ve now got me besides myself with excitement waiting to hear how they respond to both SpringSource and Sun!  It’s going to be epic!!

Or if you are not a Sun USER, you can download the PDF from here Glassfish vs Jboss.PDF

How to change Glassfish server default ports

September 17, 2009 · 1 Comment
Filed under: FaceBook Integration, Featured, GlassFish, JAVA, WebServers 

Very simple steps

  1. Open (in notepad or other text editor) domain.xml located in /glassfish/domains/domain1/config folder.
  2. Search for 8080 (there should be one occurance only ideally)
  3. Change it to 80 or 8088 or 8090 – whatever port no. you like and start the server.
  4. There is no step 4 :-)

All your calls to glassfish server now do not require 8080 in your url. This should work same on other platforms as well though I have not tested it. This way you should be able to change glassfish server other ports as well.