Tuesday, December 27, 2011

Setup JMX connection

JMX connection is used for invocation of JMX operations on the remote host or local Java Virtual machine. How we can establish this?

Friday, December 23, 2011

What is KeepAlive and how we can use it?

Imagine that we have two applications that interact via network protocol. One of the applications should know the online offline status of other app. We may use some kind of PING mechanism and this ping may be implemented between java applications usin Apache MINA features. I'd like to show a sample of usage KeepAlive messaging feature that included into MINA.

How to validate XML using .xsd file

This construction was used in one unit-test. I had to check whether the XML string returned by tested function is in accordance with xsd scheme defined, the routine below:

try
      {
         String actualResult = testedFunction();
         InputStream inputStream = new ByteArrayInputStream(actualResult.getBytes());
         StreamSource ss = new StreamSource(inputStream);
         // get validation driver:
         SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
         // create schema by reading it from an XSD file:
         Schema schema = factory.newSchema(new StreamSource("xsd_file_path"));
         Validator validator = schema.newValidator();
         // at last perform validation:
         validator.validate(ss);
      }
      catch(SAXException ex) {
         // we are here if the document is not valid:
         // ... process validation error...
         fail("Output result is not valid");
         ex.printStackTrace();
      }
      catch(Exception e) {
         // Mustn't reach this code
         fail();
      }