Monday, July 18, 2011

Resize EBS Volumes , Here is A Link

If you need to increase the size of an EBS volume, here is good article to accomplish this: article

Sunday, June 19, 2011

Developing and Testing in Android Against Local Web Services

Found a great post on Developing and Testing in Android Against Local Web Services, so I thought I would share it.
http://denimgroup.posterous.com/android-dns-setup-for-developing-and-testing

Thursday, November 18, 2010

Recommend using Fluent Nhibernate

I have been using Fluent Nhibernate instead of Nhibernate with xml config files.
It is definitely helpful in preventing configuration typos.
There other contrib projects for Nhibernate that I have found extremely useful
including Nhibernate Validator and NHibernate Spatial.
Nhibernate is independent from Hibernate and it doesn't benefit from a large corporate backer. Due to this Nhibernate and contrib projects are spread across multiple websites.
Main Site:
Fluent Nhibernate:

Friday, January 22, 2010

Unit Testing Restful Web Services using Restlet and Jaxb

One way to post data to a Restful web services is to Serialize your object using Jaxb (Java Architecture for XML Binding) when you are using Java.  Since you are dealing with Web Services you client code could also be in .Net, javascript, PHP, Rails, etc.  But, in this post we are assuming your client is Java based.  If you Object class is in a separate project from your Test project, one thing that will cause you to pull your hair out is you will get : JAXBException stating errors creating marshaller or unmarshaller, unless you place a jaxb.index file with your Object class in the same package. For example, if the Object that you are Serializing is Sample.java with the package com.acme.businessobjects, then you have to place a jaxb.index file with the package com.acme.businessobjects. Within the jaxb.index file just place one line with just the class name: Sample, and that's it.
Here is link to javadoc that discuss this: http://java.sun.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html
The best way to understand Jaxb is to create a sample object called Sample, and create a test case
To demonstrate this issue create 2 projects , one that contains the Sample.java class, and one the contains you Test case. Note: Initially do not place a jaxb.index file with your Sample.java, this way you will see the JaxbException. After you see that you get the JaxbException, then place an jaxb.index file with your Sample.java, and rebuild your project. The second time around, once you have an jaxb.index file, your JAXBException will eliminated.
The test case uses a schema file named: sample.xsd, this is created using Sun's schemagen tool that comes with Java. From the command line: schemagen path/Sample.java. This creates a file named schema1.xsd, rename this file and copy to your test project folder. For detailed info see: Sun JAXB Tutorial
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Sample {
@XmlElement(name = "value")
private String val;

public Sample() {
}

public Sample(String val) {
this.val = val;
}

public String getVal() {
return val;
}

public void setVal(String val) {
this.val = val;
}

@Override
public String toString() {
return "Sample [val=" + val + "]";
}
}
This test case below tests both Marshalling and Unmarshalling using Jaxb.
public void testGenerateMarshallerToFile() throws JAXBException, FileNotFoundException, SAXException
{
JAXBContext context1 = JAXBContext.newInstance(Sample.class);

JAXBContext context2 = JAXBContext.newInstance("com.acme.businessobjects");

Marshaller m = context1.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
Sample sample = new Sample();
sample.setVal("Hello");
final File f = new File("src/test/java/com/endurotracker/gwt/test/rest/api/sample.xml");
m.marshal(sample, new FileOutputStream(f));

Unmarshaller um = context2.createUnmarshaller();

um.setSchema(getSchema("Sample.xsd"));

Object bce = um.unmarshal(f);

m.marshal(bce, System.out);



}
To test your Restlet web services with Jaxb, you will need to create a SampleResource class. Luckily, for you there is such a test in the org.restlet.test package, so you will only need to download the latest restlet source code. restlet.org The name of the test class you are interested in is: JaxbIntegrationConverterTestCase

Friday, January 1, 2010

Restful Web Services using Asp.net MVC

Microsoft's new Asp.net MVC framework can also easily support Restful Web Services.
Controller actions can be called from Ajax based based websites using Javascript.
For example if you create a controller named APIController with a method:GetUsers,
then a Restful url would be /API/GetUsers. To implement your Restful Web Services using Asp.net MVC, take a look at these excellent write ups,
create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml, and
Creating-a-RESTful-Web-Service-Using-ASPNet-MVC-Part-1-Introduction

Thursday, December 31, 2009

Restful Web Services using Restlet Framework

Restlet framework is a Restful Web Service framework written Java.

restful.org

However, Microsoft has worked with the team behind Restlet and has enabled interoperability between Azure ADO.net and Restlet.

microsoft-selects-restlet-to-show-rest-interoperability

Other big companies like Google also use the Restlet framework for writing Web Services in a Restful way. I always lean towards projects that are well documented and the Restlet framework has some good documentation including examples, tutorials, and api documents. In addition, if you want to integrate a Spring Web project with Restlet, here is a good write up,

restlet-with-spring

If your website leverages ajax via javascript, one of the nice things with Restlets is that you can easily call your Restful Web Services using javascript.

Restlets has implemented lots of extensions, for example if you want to write a smartphone app in android to call Restful Web Services, Restlets has an extension for this.

Restlet is extremely flexible and can be called from either a Web client or Web server code.

Thursday, December 17, 2009

Spring MVC with SiteMesh Decoration Framework and Velocity Templates

Most developers hate to repeat themselves, so they like to reuse as much code as possible. The folks at OpenSymphony.org who also brought you Quartz developed Sitemesh to utilize the Gang of Four pattern composition.
In short, SiteMesh is a web-page layout and decoration framework. It allows you to
reuse your layouts (header and footer for example) throughout your site, so that
you site has a consistent look and feel.

The general documentation at the SiteMesh Site site is quite good but I needed to utilize Sitemesh in the following specific scenario, I am using Spring MVC and Velocity Templates.

Since the general install documentation, installation instructions is very good, I will not repeat it here. Once you have downloaded and setup your web project, you will have 3 xml config that you will be dealing with, web.xml, sitemesh.xml, and decorators.xml. In my case I am using Spring MVC and Velocity, so I need to customize my web.xml configuration to handle this setup. Here is how my web.xml is configured:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>EnduroTracker</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<!--SiteMesh-->
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>*.html</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

<!--Used to Enable Spring MVC -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<!--Sitemesh-->
<servlet>
<servlet-name>sitemesh-velocity</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.velocity.VelocityDecoratorServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>sitemesh-velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>


<welcome-file-list>
<welcome-file>homeIndex.html</welcome-file>
</welcome-file-list>

<error-page>
<error-code>500</error-code>
<location>/error.html</location>
</error-page>

</web-app>


If you followed the SiteMesh Install steps at their site and then customized your
web.xml for your Spring MVC web project, you should now have SiteMesh configured correctly to use with Spring MVC and Velocity.
Important to note in your decorators.xml since you are using Velocity,
you will be using *.vm decorator files, here is an example decorators.xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/decorators">
<!-- Any urls that are excluded will never be decorated by Sitemesh -->
<!--<excludes>
<pattern>/exclude.vm</pattern>
<pattern>/exclude/*</pattern>
</excludes>-->

<decorator name="default" page="default.vm">
<pattern>/*</pattern>
</decorator>

</decorators>