Thursday, March 25, 2010

JDK hidden treasures

Couple of tools we occasionally use but knowing them is useful esp. when we want to peek into JVM.

jps  -List the java process running.
eg: jps -m -l

jvisualvm - Visualize all the VMS running. Seems to be a better option than jconsole. Comes with jdk1.6+ i think
http://java.sun.com/javase/6/docs/technotes/guides/visualvm/intro.html

jconsole -
eg: TODO: remotely manage Mbeans??

jar
eg: jar xvf --to extract, jar cvf -- to create ?

jarsigner  --useful for signing applets.
jstack --??

java  - The jvm ...
javac  - The compiler

javaw  - As far as I know useful to run a process without sticking it to the console which is opening it. eg: javaw eclipse




Friday, March 19, 2010

Good tools for web developers

Must have tools for web developers Xrefresh which works with firebug. Basically you install 2 things , a firefox addon and a system specific xreferesh server. the addon behaves like a client and refreshes the page when you save a html/css/js in your editor Fireshot An excellent plugin to take screenshots and edit them all easily in the plugin.

Thursday, March 18, 2010

Fun with XML on Oracle - XMLTypes

To register a schema in oracle do below:
1. drop directory XMLDIR;
2. create directory XMLDIR as 'C:\';
3. select * from ALL_DIRECTORIES
4.
DBMS_XMLSCHEMA.registerSchema(
SCHEMAURL => 'C:\oracle9i\admin\TEST\utl_file\test.xsd',
SCHEMADOC => bfilename('XMLDIR','test.xsd'),
CSID => nls_charset_id('AL32UTF8'));
5. desc DBMS_XMLSCHEMA confirms that registerSchema exists

Gotchas:
error: ORA-01031: insufficient privileges


Wednesday, March 17, 2010

Clip chain - copy mulitple words at one go!

Clip Chain:
The separator can be changed as often as you'd like while building the text chain—Caps Lock+Esc resets the separator to the default (nothing).

Use the Caps Lock+C shortcut to copy the currently selected text and Caps Lock+V to paste Once the chain has been pasted using Caps Lock+V, the chain is moved to the clipboard and reset.

To paste the chain again, use the standard Ctrl+V shortcut. The chain can also be reset at any time by pressing Caps Lock+Backspace.

More : http://lifehacker.com/5337238/clipchain-copies-multiple-text-strings-for-easy-pasting


Tuesday, March 2, 2010

Playing with load - Jmeter

Scenario:
I want to test http web service using distinct samples as it violates primary key constraints on my database.

The solution:
Java Custom Sampler can be easily configured in jmeter by:
1. Implementing JavaSamplerClient interface.
2. Copy this custom jar into [JMETRE_HOME]/lib/ext . Also any related jars if required!
3. Fire up jmeter client. > Thread Group >Add > Sampler > Java Request ..You should see your custom sampler..

The code is below:
public class CustomServiceSampler implements JavaSamplerClient {
public Arguments getDefaultParameters() {
		Arguments params = new Arguments();
		params.addArgument("SERVICE_URI", DEFAULT_SERVICE_URI);
        params.addArgument("XML_TEMPLATE_PATH", DEFAULT_BRANCH_TEMPLATE_PATH);
        params.addArgument("DATA_ENCODING", DEFAULT_DATA_ENCODING);
		return params;
	}

	@Override
	public SampleResult runTest(JavaSamplerContext context) {
		SampleResult result = new SampleResult();
		
		HttpClient client = new HttpClient();
		String url = context.getParameter("SERVICE_URI", DEFAULT_SERVICE_URI);
		String templatePath= context.getParameter("XML_TEMPLATE_PATH", DEFAULT_BRANCH_TEMPLATE_PATH);
		String contentType= context.getParameter("DATA_ENCODING", DEFAULT_DATA_ENCODING);
		
		PostMethod method = new PostMethod(url);
		method.setRequestHeader("Content-Type", contentType);
		try {
			String template = FileUtils.readFileToString(new File(templatePath));
			String id= (System.currentTimeMillis() + "").substring(0, 10);
			result.setSampleLabel("Post xml- " + id);
			logger.info("Sending POST request to "+url +" with id:"+id);
			String xml = template.replaceAll("\\{ID\\}", branchId);
			xml = xml .replaceAll("\\{DATE\\}", new Date() + "");

			RequestEntity requestEntity = new StringRequestEntity(xml );
			method.setRequestEntity(requestEntity);

			result.setRequestHeaders(ToStringBuilder.reflectionToString(method.getRequestHeaders()));
			result.setSamplerData(xml );
			
			result.sampleStart();
			client.executeMethod(method);
			result.sampleEnd();
			
			String response = new String(method.getResponseBody());
			int code = method.getStatusCode();
			logger.info("Recived response .. status code "+code +" response xml :"+response);
			boolean success= code ==201 ? true:false;
			result.setSuccessful(success);
			result.setResponseData(response);
			result.setResponseCode(code+"");
			result.setResponseMessage(response);
			
			
		} catch (Exception e) {
			logger.error(e,e);
			result.sampleEnd();
			result.setResponseMessage(e.getMessage());
			result.setSuccessful(false);
		}
		return result;
	}
}

References:
http://www.scribd.com/doc/23029283/Using-JMeter-to-Performance-Test-Web-Services