Sunday, March 28, 2010

Transport Statistics Component for WSO2 ESB

Transport Statistics component shows statistics related to Transports and it will be available with the WSO2 Carbon Iridium (version 3.0.0) release. It displays the Transports which are implementing
the interface org.apache.axis2.transport.base.ManagementSupport. These transport statistics include bytes received, bytes sent, faults receiving, faults sending,last reset time, max size received, max size sent, messages received, messages sent, metrics window, min size received, min size sent, queue size, timeouts receiving, timeouts sending.

Viewing Transport Statistics
  • In the navigator, under Monitor, click Transport Statistics. The Transport Statistics page appears.
Figure 1: Transport Statistics
  • The entry page lists down all the exposed Tranports which have implemented the ManagementSupport interface (Figure 1). The graph gives an aggregated view of the bytes received/ bytes sent vs time for all transports.
  • Click on a link to view the relevant statistics which relates to a transport (Figure 2). The graph gives a drilled down view of the bytes received/ bytes sent vs time for a specific transport.
  • Each link will take you to a new page that displays the transport statistics exposed by JMX. These data are the data which is shown in the jconsole and we are giving an aggregated view of the transport stats.
Figure 2: Transport Statistics for HTTP transport
  • These transport statistics include bytes received, bytes sent, faults receiving, faults sending, last reset time, max size received, max size sent, messages received, messages sent, metrics window, min size received, min size sent, queue size, timeouts receiving, timeouts sending.
This is the first component that I developed for WSO2 ESB. During the development stages of this component I had the chance of learning Ajax and applying them to this component, which is showing a screenshot of the statistics at a given point of time.

https://svn.wso2.org/repos/wso2/branches/carbon/3.0.0/components/transport-statistics

Saturday, March 27, 2010

Restore a Registry Resource stored in a file to WSO2 Registry

Following code snippet shows, how to programmetically restore a Registry Resourece written in to a file, back to WSO2 Registry using RemoteRegistry. This is a follow-up to an earlier blogpost.

import org.wso2.carbon.registry.app.RemoteRegistry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;

import java.net.URL;
import java.net.MalformedURLException;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;

public class RemoteRegistrySampleTest {
public static void main(String[] args) {
System.setProperty("javax.net.ssl.trustStore", "CARBON_HOME/resources/security/client-truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");

RemoteRegistry esb2xRemoteRegistry = null;
try {
esb2xRemoteRegistry = new RemoteRegistry(new URL("https://localhost:9443/registry"),
"admin", "admin");
esb2xRemoteRegistry.restore("/esb-resources", new FileReader("/home/heshan/Dev/wso2_heshan/temp/registry.xml"));
} catch (RegistryException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
}

Backup WSO2 Registry Resource to a file

Following code snippet shows, how to programmetically backup WSO2 Registry Resource to a file using RemoteRegistry.

import org.wso2.carbon.registry.app.RemoteRegistry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;

import java.net.URL;
import java.net.MalformedURLException;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;

public class RemoteRegistrySampleTest {
public static void main(String[] args) {
System.setProperty("javax.net.ssl.trustStore", "CARBON_HOME/resources/security/client-truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");

RemoteRegistry esb2xRemoteRegistry = null;
try {
esb2xRemoteRegistry = new RemoteRegistry(new URL("https://localhost:9443/registry"),
"admin", "admin");
esb2xRemoteRegistry.dump("/esb-resources", new FileWriter("/home/heshan/Dev/wso2_heshan/temp/registry.xml"));
} catch (RegistryException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
}

Tuesday, March 2, 2010

Remove Line Breaks From a Java String

Following code snippet shows how to remove line termination characters from a String.


import java.util.regex.*;

public class ClassA {
public static void main(String args []) {
String inputText = "sdfsdfsf\nsdfsdfsd";
String inputText2 = "var trpListenerGr\naphDivId = #trpLi\nstenerGraph2\n";
RemoveLineTerminationCharacterss(inputText);
System.out.println("-------------------------------");
RemoveLineTerminationCharacterss(inputText2);

}

public static String RemoveLineTerminationCharacterss(String inputText){
Pattern p;
Matcher m;
System.out.println(" Input Text : " + inputText);
p = Pattern.compile("\n");
m = p.matcher(inputText);
String str = m.replaceAll("");
System.out.println(" OUtput Text: " + str);
return str;
}
}