Difference between revisions of "Glassfish"

 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Development]]
 +
 +
 
=Requirements=
 
=Requirements=
 +
 
* Glassfish 4 required '''Java 7'''. The version 4.0 is NOT compatible with Java 8, but the version 4.1 will be.
 
* Glassfish 4 required '''Java 7'''. The version 4.0 is NOT compatible with Java 8, but the version 4.1 will be.
 
    
 
    
 
* It's better to use the official '''ORACLE JDK''' as Glassfish is an Oracle product too.
 
* It's better to use the official '''ORACLE JDK''' as Glassfish is an Oracle product too.
 +
 +
  
 
=Installation=
 
=Installation=
 +
 +
==GF installation==
  
 
* Download the latest glassfish version from the official website: https://glassfish.java.net/
 
* Download the latest glassfish version from the official website: https://glassfish.java.net/
Line 11: Line 19:
  
  
=Issues=
+
==Firewall==
 +
 
 +
You need to open, at least, the following port in I/O:
 +
 
 +
<syntaxhighlight lang="bash">
 +
# Input
 +
$IPTABLES -A INPUT -p tcp --dport 8080 -j ACCEPT  # Glassfish4 application server
 +
$IPTABLES -A INPUT -p tcp --dport 1527 -j ACCEPT  # Glassfish4 security manager
 +
$IPTABLES -A INPUT -p tcp --dport 7676 -j ACCEPT  # Open MQ (bundled with Glassfish) - JMS broker
 +
 
 +
# Output
 +
$IPTABLES -A OUTPUT -p tcp --dport 8080 -j ACCEPT  # Glassfish4 application server
 +
$IPTABLES -A OUTPUT -p tcp --dport 1527 -j ACCEPT  # Glassfish4 security manager
 +
$IPTABLES -A OUTPUT -p tcp --dport 7676 -j ACCEPT  # Open MQ (bundled with Glassfish) - JMS broker
 +
</syntaxhighlight>
 +
 
 +
 
 +
==Issues==
  
==SocketPermission, port 1527==
+
===SocketPermission, port 1527===
 
If you have the following error:  
 
If you have the following error:  
 
''access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")''
 
''access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")''
Line 73: Line 98:
  
 
* Under '''resources''' / jdbc, create a new '''JDBC connection pool'''
 
* Under '''resources''' / jdbc, create a new '''JDBC connection pool'''
** Name:      myPoolName
+
 
** Type:      javax.sql.datasource
+
{| class="wikitable"
** Db vendorMySQL
+
|-
 +
! Setting !! Value
 +
|-
 +
| name || myPoolName
 +
|-
 +
| Type || javax.sql.datasource
 +
|-
 +
| Db vendor || MySQL
 +
|}
  
 
* On the next page, '''Datasource Classname''' must have been update automatically in: ''com.mysql.jdbc.jdbc2.optional.MysqlDataSource''
 
* On the next page, '''Datasource Classname''' must have been update automatically in: ''com.mysql.jdbc.jdbc2.optional.MysqlDataSource''
Line 118: Line 151:
  
  
==JMS==
+
=JMS=
  
===ActiveMQ===
+
==OpenMQ==
 +
Glassfish 4 is bundled with OpenMQ. This is the 1st Open-Source server to support JMS 2.0 specifications.
  
====Requirements====
+
The OpenMQ server starts with Glassfish4, but you still have to configure it.
 +
For full explanation see: http://gregorbowie.wordpress.com/author/gregorbowie/
 +
 
 +
===Create Destination resource===
 +
* Go to Glassfish administrator page: http://localhost:4848
 +
 
 +
* Under '''resources''' / JMS Resources, create a new '''destination Resources'''
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Setting !! Value
 +
|-
 +
| JDNI name || ''jms/''myApp
 +
|-
 +
| physical destination name || myApp
 +
|-
 +
| Type ||
 +
* '''javax.jms.topic'''  for publish / subscribe pattern. 1 message go to N listeners, but order is NOT guarantee.   
 +
* '''javax.jms.queue'''  end to end communication. 1 message go to 1 listener, order is guarantee.
 +
|}
 +
 
 +
Depending on your needs, you can choose either '''Topic''' or '''Queue'''.
 +
 
 +
 
 +
===Create JMS connection factory===
 +
* Under '''resources''' / JMS Resources, create a new '''Connection factories'''
 +
 
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Setting !! Value
 +
|-
 +
| JDNI name || ''jms/''myApp''Factory''
 +
|-
 +
| resourceType || Depending on your destination:
 +
* '''javax.jms.topicConnectionFactory'''  for publish / subscribe pattern. 1 message go to N listeners, but order is NOT guarantee.   
 +
* '''javax.jms.queueConnectionFactory'''  end to end communication. 1 message go to 1 listener, order is guarantee.
 +
|}
 +
 
 +
 
 +
===Management and monitoring of OpenMQ: imqadmin===
 +
You can manage and monitor OpenMQ using the provided Glassfish '''imqadmin''' utility, available in $GLASSFISH.
 +
<syntaxhighlight lang="bash">
 +
$GLASSFISH/mq/bin/imqadmin
 +
</syntaxhighlight>
 +
 
 +
====Add default broker====
 +
* Right-click on Brokers and Add…
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Setting !! Value
 +
|-
 +
| server || localhost
 +
|-
 +
| port || 7676
 +
|-
 +
| user || admin
 +
|-
 +
| password || admin
 +
|}
 +
 
 +
you can then click the ‘Physical Destinations’ under your broker and the topic(s) / queue(s) created earlier will appear.
 +
 
 +
 
 +
===Management of OpenMQ with ''QBrowser JMS''===
 +
 
 +
====Installation====
 +
* Download ''QBrowser MQ'' from the official website: http://sourceforge.net/projects/qbrowserv2/
 +
 
 +
* Just unzip the file in the target folder.
 +
 
 +
* Make the scripts executable
 +
<syntaxhighlight lang="bash">
 +
chmod 755 *.sh
 +
</syntaxhighlight>
 +
 
 +
====Connection to OpenMQ====
 +
 
 +
1.Execute run_open_mq
 +
<syntaxhighlight lang="bash">
 +
./run_open_mq.sh
 +
</syntaxhighlight>
 +
 +
2. Select [File] menu -> [New connection]
 +
 
 +
3. Specify credentials like that:
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Setting !! Value
 +
|-
 +
| server || localhost
 +
|-
 +
| port || 7676
 +
|-
 +
| user || admin
 +
|-
 +
| password || admin
 +
|}
 +
 
 +
 
 +
 
 +
==ActiveMQ==
 +
 
 +
===Requirements===
 
You have to setup your ActiveMQ server:  
 
You have to setup your ActiveMQ server:  
 
* The broker should listen on all interfaces
 
* The broker should listen on all interfaces
 
* Enable the web-console to improve debugging
 
* Enable the web-console to improve debugging
 +
 +
===Installation===
 +
see [[JMS server: ActiveMQ]]

Latest revision as of 17:17, 10 June 2014


Requirements

  • Glassfish 4 required Java 7. The version 4.0 is NOT compatible with Java 8, but the version 4.1 will be.
  • It's better to use the official ORACLE JDK as Glassfish is an Oracle product too.


Installation

GF installation

  • Register the server into your IDE (Netbeans, Eclipse, IntelliJ).


Firewall

You need to open, at least, the following port in I/O:

# Input
$IPTABLES -A INPUT -p tcp --dport 8080 -j ACCEPT   # Glassfish4 application server
$IPTABLES -A INPUT -p tcp --dport 1527 -j ACCEPT   # Glassfish4 security manager
$IPTABLES -A INPUT -p tcp --dport 7676 -j ACCEPT   # Open MQ (bundled with Glassfish) - JMS broker

# Output
$IPTABLES -A OUTPUT -p tcp --dport 8080 -j ACCEPT   # Glassfish4 application server
$IPTABLES -A OUTPUT -p tcp --dport 1527 -j ACCEPT   # Glassfish4 security manager
$IPTABLES -A OUTPUT -p tcp --dport 7676 -j ACCEPT   # Open MQ (bundled with Glassfish) - JMS broker


Issues

SocketPermission, port 1527

If you have the following error: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")

Then you have to adjust your security policy.

cd $JAVA_HOME/jre/lib/security
vim java.policy


  • Only open the required port

Add the following line:

grant {
    permission java.net.SocketPermission "localhost:1527", "listen";
};

=> just add the "permission..." around line 25


  • Open everything

This solution is NOT recommended, it can generate a massive security leak!

Anyway, if you're sure you can add the following line:

grant codeBase "file:${java.home}}/../db/lib/*" {
        permission java.security.AllPermission;
};


Datasource management

Database

MySQL

Requirements

You have to setup your MySQL server:

  • Allow remote access
  • Create dedicated database in UTF8-bin
  • Create dedicated user for the application

Driver installation

  • Extract and copy the mysql-connector-java-XXX-bin.jar into:
    • $GLASSFISH/glassfish/lib
    • $GLASSFISH/glassfish/domains/domain1/lib/databases
  • Restart Glassfish

Create JDBC connection pool

  • Under resources / jdbc, create a new JDBC connection pool
Setting Value
name myPoolName
Type javax.sql.datasource
Db vendor MySQL
  • On the next page, Datasource Classname must have been update automatically in: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
  • Then, click the enable ping option and fill up the connection details.
Setting Value
User myApp
ServerName localhost
DatabaseName myApp
Password myAppPwd
Url jdbc:mysql://localhost:3306/myApp
URL jdbc:mysql://localhost:3306/myApp


Create JDBC resource

A JDBC resource = JNDI datasource

  • Under resources / jdbc, create a new JDBC resources
  • Create a new connection using:
Setting Value
JNDI name jdbc/myApp
Pool name myPoolName

Now you can use that connection in your application with jdbc/myApp


JMS

OpenMQ

Glassfish 4 is bundled with OpenMQ. This is the 1st Open-Source server to support JMS 2.0 specifications.

The OpenMQ server starts with Glassfish4, but you still have to configure it. For full explanation see: http://gregorbowie.wordpress.com/author/gregorbowie/

Create Destination resource

  • Under resources / JMS Resources, create a new destination Resources
Setting Value
JDNI name jms/myApp
physical destination name myApp
Type
  • javax.jms.topic for publish / subscribe pattern. 1 message go to N listeners, but order is NOT guarantee.
  • javax.jms.queue end to end communication. 1 message go to 1 listener, order is guarantee.

Depending on your needs, you can choose either Topic or Queue.


Create JMS connection factory

  • Under resources / JMS Resources, create a new Connection factories


Setting Value
JDNI name jms/myAppFactory
resourceType Depending on your destination:
  • javax.jms.topicConnectionFactory for publish / subscribe pattern. 1 message go to N listeners, but order is NOT guarantee.
  • javax.jms.queueConnectionFactory end to end communication. 1 message go to 1 listener, order is guarantee.


Management and monitoring of OpenMQ: imqadmin

You can manage and monitor OpenMQ using the provided Glassfish imqadmin utility, available in $GLASSFISH.

$GLASSFISH/mq/bin/imqadmin

Add default broker

  • Right-click on Brokers and Add…
Setting Value
server localhost
port 7676
user admin
password admin

you can then click the ‘Physical Destinations’ under your broker and the topic(s) / queue(s) created earlier will appear.


Management of OpenMQ with QBrowser JMS

Installation

  • Just unzip the file in the target folder.
  • Make the scripts executable
chmod 755 *.sh

Connection to OpenMQ

1.Execute run_open_mq

./run_open_mq.sh

2. Select [File] menu -> [New connection]

3. Specify credentials like that:

Setting Value
server localhost
port 7676
user admin
password admin


ActiveMQ

Requirements

You have to setup your ActiveMQ server:

  • The broker should listen on all interfaces
  • Enable the web-console to improve debugging

Installation

see JMS server: ActiveMQ