DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

EasyMX - An alternative to JMX

Erdinç Kocaman user avatar by
Erdinç Kocaman
·
Dec. 10, 11 · Interview
Like (0)
Save
Tweet
Share
7.90K Views

Join the DZone community and get the full member experience.

Join For Free

Monitoring and getting information about the internals of application is always crucial. For this reason Java platform has introduced JMX infrastructure long time ago.
It allows you to access detailed information about the application in a standard way. Here, I'll show you another way of getting and displaying the details about the application. I prefer this way as it seems to be easier to use than JMX. I have opened a project called "EasyMX" in SourceForge, you can access codes at
http://easymx.sourceforge.net.

EasyMX uses Rest and Eclipse plugins. The management services are developed using Rest and accessed by the Eclipse plugin. I will explain it step by step below. First you have to write a service to get information about the application, say it is a time service displaying current server time. You have to configure Rest first.

in web.xml, add a servlet to configure Rest;

	<servlet>
		<servlet-name>Jersey REST Service</servlet-name>
		<servlet-class>
  			com.sun.jersey.spi.container.servlet.ServletContainer
		</servlet-class>

		<init-param>
    		<param-name>com.sun.jersey.config.property.packages</param-name>
    		<param-value>net.sourceforge.easymx.web.rest</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>	
	</servlet>
	<servlet-mapping>
		<servlet-name>Jersey REST Service</servlet-name>
		<url-pattern>/rest/*</url-pattern>
	</servlet-mapping> 

 

It accepts all Rest implementations under the package "net.sourceforge.easymx.web.rest"

Second add an class, e.g SysInfo, under this package and write a service to get current time of the server;

@Path("/sysInfo")
public class SysInfo {
	
	@GET
	@Path("getTime")
	public String getTime() {
		return new Date().toString();
	}
}

 

Make sure that you can see time information by browsing to http://localhost:8080/easymx/rest/sysInfo/getTime. You should see something like this : Fri Nov 25 17:13:47 EET 2011
Now, the time service completed and you can see it using the Eclipse plugin also.

EasyMx has an Eclipse plugin which you can install just like other plugins by copying it to plugins folder of Eclipse install path. After copying and restarting the
Eclipse, choose EasyMX/Servers List from "Show View" menu item. You should see similar screen as below;

 

First thing you have to do is to add an server. To do that, right click on "EasyMX Servers" node and click "Add server". You should enter server name and uri of
rest services. In this example you should enter;
Server name : Test Server
Address        : http://localhost:8080/easymx/rest

Click "Ok" and server definition is added. 

Now, you should define services in the plugin to access the service you developed on the server. To add the service, right-click on server "Test Server" and click on "Add service". You should see similiar screen as below;

 

Service name      : sysInfo
Context URI         : /sysInfo/getTime
Result type          : text

You enter a name for service and uri you can access. Uri must starts with "/" and points to your Rest time service. Since your server address is http://localhost:8080/easymx/rest" and the service uri is "/sysInfo/getTime", complete address of your service is concatenation of these two addresses, "http://localhost:8080/easymx/rest/sysInfo/getTime". You set "text" as result type as you just return a simple string from time service. It can be "tabular" also, I will show the usage of that result type later.


To invoke the service, double click on the service name and a dialog screen is displayed. First part of the dialog allows entering parameters of the service. For this service, there is no need to enter any parameter so this part is empty. Second part is includes  button to invoke the service and an area to show the status of service invocation. Just click on "Invoke service" button, you should see server time;


 

Second service lists the properties of a Java application. The service implementation;

	@GET
	@Produces(MediaType.TEXT_XML)
	@Path("getSysProps")
	public String getSysProps() {
		Properties props = System.getProperties();
		
		List<Map<String,String>> propsNormalized = new ArrayList<Map<String,String>>();
		
		
		for(Map.Entry<Object, Object> entry:props.entrySet()) {
			Map<String, String> val  = new HashMap<String, String>();
			
			String name = "";
			if( entry.getKey() != null ) {
				name = entry.getKey().toString();
			}
			
			String value = "";
			
			if ( entry.getValue() != null) {
				value = entry.getValue().toString();
			}
			
			val.put("name", name);
			val.put("value", value);
			propsNormalized.add(val);
			
		}
		
		Collections.sort(propsNormalized, new Comparator<Map<String, String>>() {
			
			public int compare(Map<String, String> o1, Map<String, String> o2) {
				return o1.get("name").compareTo(o2.get("name"));
			}
		});
		
		return new EasyMxUtil().generateXml(propsNormalized, "name", "value");
	}

 This service lists the properties and its values in a tabular format. Data is received in xml format conforming the standard below;

<result>
	<row> <propertyName value="propertyValue"/>  </row>
</result

EasyMxUtil class is used to generate the xml format. You don't need to use that class, generating xml data in proper format is enough.
Now it comes to defining this new service in the plugin. Right-click on the server and click on "Add service". Add the values below;

Service name : sysInfo-getSysProps
Context URI    : /sysInfo/getSysProps
Result type     : tabular

Since the data is in xml format you should set the result type as "tabular". When you click on "Invoke service" the similar screen like below displayed;

You can see the properties and values of you service result as listed tabularly. You can also view the raw xml formatted data returned. If you click any
cell of the table you see it is copied to area below.

Another feature of the plugin is passing parameters to the service. To give an example for this, a service to search a property by name is developed.

Service implementation;

	@GET
	@Produces(MediaType.TEXT_PLAIN)
	@Path("getSysPropByName")
	public String getSysPropByName(@QueryParam("name") String name) {
		if ( name == null ) {
			return "";
		}
		
		Properties props = System.getProperties();
		
		return props.getProperty(name);
	}

Service definition in plugin;

Service name : sysInfo-getSysProps
Context URI    : /sysInfo/getSysPropByName
Result type     : text

 

You can add parameters by right-clicking on parameters(name-value pairs) area and selecting "Insert New Property". Enter "name" as name field, and "user.home" as value.

You should see similar screen;

 

All information related to the servers and services is stored in file ".easymx-servers.xml" under user home folder.

 Another screenshot listing the services;

 

There are some drawbacks of using this approach. First it has no notification mechanism as in JMX and no security issues considered. But it may be a different way of accessing detailed information about your application. You can download files from https://sourceforge.net/projects/easymx/files/1.0.0/

 

 

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Was the Question Again, ChatGPT?
  • ChatGPT: The Unexpected API Test Automation Help
  • Load Balancing Pattern
  • Top 5 Java REST API Frameworks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: