Glassfish V3.1 running embedded ActiveMQ for JMS (Updates)

Last year I described all steps to get running with ActiveMQ embedded in Glassfish:

Some updates :
The current version of ActiveMQ is 5.7.0. Here some updated download links
activemq-web-console-5.7.0.war (link)
activemq-rar-5.7.0.rar (link)
activemq-ra-5.7.0.jar (link)
activemq-all-5.7.0.jar (from the main package)

Note: you need to re-deploy the resource adapter with version 5.7 and check all connector settings.

It works fine with Glassfish 3.1.2.2 and Java JDK 1.7.07

I had issues with the firewall due to fact ActiveQM uses a fix registration port for JMX but dynamic ports for the communication port. The web-console was not accessible.
“Exception occurred while processing this request, check the log for more information!”

Web Console

[#|2012-10-18T07:42:09.249+0000|WARNING|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=73;_ThreadName=Thread-2;|StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)

There are ways to configure this for a standalone ActiveMQ instance with the parameters connectorPort and rmiServerPort but I didnt find out yet how to do this with the embedded version.
As a workaround I changed this setting -Djava.rmi.server.hostname from my hostname to localhost.
-Djava.rmi.server.hostname=localhost

JVM Settings

EC2 Server on demand without elastic IP

or ‘Saving totally the most while using EC2’

We use a couple of EC2 servers which are not permanently running, rather on user-demand only. Without wasting money for elastic ip addresses (you are charged while they are NOT attached), we make use of the random public IP provided by AWS and update our Dyndns addess for this server.

  • Create a DynDNS account if you dont have one
  • Create a hostname (eg. sample.mydomain.net)
  • Install Inadyn
    sudo apt-get install inadyn (for Ubuntu or debian)
  • Add this line to a start-up script
    inadyn –username myuser –password mypwd –iterations 1 –alias sample.mydomain.net
    ( with iterations the command is executed only once)
    inadyn makes use of http://checkip.dyndns.com/ to retrieve the ip address

On top of it the server switches off automatically at nighttime (see blog entry)  and the user uses a little web frontend to start the server again on his/her own.

Create a JIRA client application with Netbeans

I want to embed the creation of JIRA issues into my web application. There are 2 option, as XML-RPC or SOAP client. I decide for the latter one as being the more-up-to-date technology.

Using Netbeans it is usually quite simple to create a WS client, just give the WSDL address and NB will create all required code for you. Btw, you need to install the JAX-RPC plugin, NB out-of-the-box only supports JAX-WS.
Add the “latest” build to your Netbeans plugin settings and you will find the plugin. (http://deadlock.netbeans.org/hudson/job/nbms-and-javadoc/lastStableBuild/artifact/nbbuild/nbms/updates.xml.gz)

Update Center

JAX-RPC Webservices

But in the case of the JIRA WSDL (you can test with http://jira.atlassian.com/rpc/soap/jirasoapservice-v2?wsdl or your own JIRA server) it fails.
While creating the WS client code it duplicates a number of variables.

/media/NetbeansProjects/Webservices/JiraDemo/build/generated-sources/jax-rpc/jiraws/JiraSoapService_deletePermissionScheme_Fault_SOAPSerializer.java:30: ns1_fault_QNAME is already defined in jiraws.JiraSoapService_deletePermissionScheme_Fault_SOAPSerializer
private static final javax.xml.namespace.QName ns1_fault_QNAME = new QName("http://xxxxxxx/rpc/soap/jirasoapservice-v2", "fault");

Errors

My temporary workaround: I create the Java application in Eclipse, add the WS there and import the project afterwards into NB. This works, but you loose the extra functions to handle WS in Netbeans. So on the long way, I hope someone can fix the plugin.

JIRA WS in Eclipse

JIRA WS in Eclipse

JIRA WS in Netbeans

WS Client

I recommend playing with the sample code from below references.

References:

 

 

Update DynDNS hosts with Java and HttpComponents

I was looking for a way to update the DynDNS hosts pointing to my EC2 instances that run only on demand (controlled by an web application). Yes, there are apps and tools to let the server itself update his DynDNS hosts, but I want to do it from a central application. The DynDNS API description you find here, unfortunately there are no samples. But if you familiar with REST calls, shouldn’t be a big issue. For those who to get running quick, here the key code. To experiment, just create a simple Java application with Netbeans (or any other IDE), download the HttpComponents from Apache and add the library files to your project.

Libraries

commons-codec-1.4.jar
commons-logging-1.1.1.jar
httpclient-4.1.1.jar
httpclient-cache-4.1.1.jar
httpcore-4.1.jar
httpmime-4.1.1.jar

Sourcecode to update an IP address

void updateDynDNS() {
...
// replace with your own data !
String hostName = "whateveryourdomainnameis.selfip.org";
String hostIP = "1.2.3.5";
String userName = "user";
String userPassword = "password";
int responseCode;

try {

// Encode username and password
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = userName + ":" + userPassword;
String encodedAuthorization = enc.encode(userpassword.getBytes());

// Connect to DynDNS
URL url = new URL("http://members.dyndns.org/nic/update?hostname=" + hostName + "&myip=" + hostIP);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", "Demo DynDNS Updater");
connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);

// Execute GET
responseCode = connection.getResponseCode();
System.out.println(responseCode + ":" + connection.getResponseMessage());

// Print feedback
String line;
InputStreamReader in = new InputStreamReader((InputStream) connection.getContent());
BufferedReader buff = new BufferedReader(in);
do {
line = buff.readLine();
System.out.println(line);
} while (line != null);

connection.disconnect();

} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

}
...

Up to you to embed into your application and do proper exception handling.

In a separate tutorial I will describe the basics of an EC2 controlling application using the AWS SDK for Java.

Glassfish 3.1 – Clustering Tutorial Part2 (sessions)

In the previous part (link) I get you running with a simple Glassfish 3.1 cluster setup with 2 instances running on 2 nodes. Now we have a cluster setup and can deploy an application one time and it will run on both nodes, no big deal, it doesn’t get us anywhere. So in part 2 we will do some modifications to our virtualbox server setup and create a web application with sessions replicated to both instances.

Prerequisites:

  • The server and cluster setup from part 1 (link)

Preparation of host and Virtualbox guests:

In part 1 we used n1 and n2 as hostname, this creates trouble for this part. A key information for the sessions is the server-hostname (domain) and we cannot share sessions between totally different hosts.

  1. Update guest server hostname
    Change etc/hosts and /etc/hostname
    Server n1 becomes n1.test.com

    127.0.0.1    localhost
    127.0.1.1    n1.test.com
    127.0.0.1    n1.test.com
    192.168.56.102  n2.test.com
    

    Server n2 becomes n2.test.com

    127.0.0.1    localhost
    127.0.1.1    n2.test.com
    127.0.0.1    n2.test.com
    192.168.56.101  n1.test.com
    

    Remarks:

    • You can use any domain name (other than test.com, which I dont own btw).
    • The IP addresses must fit your own Virtualbox setup.
  2. Update your host
    The host running Virtualbox. Change /etc/hosts

    192.168.56.101  n1.test.com
    192.168.56.102  n2.test.com
    
  3. Check multicast
    The communication between the nodes is using multicast for the session replication. The Glassfish team gives us a tool to verify if your servers can “see” each other.
    Go to the bin folder of the Glassfish installation and execute ./asadmin validate-multicast on both nodes
    You should get feedback like this Continue reading

Glassfish 3.1 – Clustering Tutorial

Glassfish Clustering, after being absent from version 3, made its re-debut after 2.1 in the current version 3.1
I was eager to get my hands on and tried to make sense of some information from various sources (see reference).

Clustering is quite a sophisticated subject, which you dont need to cover during development time, but at some stage (deployment to production) you better off knowing how it works and verify your application runs in the clustering environment.

I compiled the most essential steps in this instant-15min-tutorial creating the most simple cluster: 2 nodes with 1 instance each, 1 node also runs the DAS.

Glassfish Cluster

Continue reading

Installing pgAdminIII for PostgreSQL 9 on Ubuntu

pgAdmin is the best GUI you can use to administrate PostgreSQL, unffortunately the Ubuntu default packages still offer only PostgreSQL 8.4 and an older version of pgAdmin III that does not support PostgreSQL 9.0.x. Thanks to Martin Pitt who maintains the latest packages you can run and maintain the latest PostgreSQL versions.

If you run Maverick:

  • sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 8683D8A2
  • sudo apt-get update
  • sudo apt-get install pgadmin3

Check here for latest or other releases of Ubuntu.