Monday, December 24, 2012

Jersey Server Binary File

To serve a binary file such as a ZIP file with a REST service in Jersey, use the following:


@GET
@Produces("application/zip")
@Path("{itemId}")
public Response downloadItem(@PathParam("itemId") int itemId){
   String fileName = "item" + itemId + ".zip";
   StreamingOutput streamingOutput = new StreamingOutput(){
       public void write(OutputStream output) throws IOException, WebApplicationException {
           // write data to output stream here
       }        
   };
   
   return Response.ok(streamingOutput, "application/zip").header("content-disposition","attachment; filename = "+fileName).build();
}

Sunday, December 23, 2012

Uploading Files to S3 With Ant

This is becoming more and more relevant as S3 is increasingly being used for deployment of software in the cloud.

This is the one I'm currently using.
https://github.com/corley/aws-ant-task
Apparently it's still being actively maintained.

Question on StackOverflow about this: http://stackoverflow.com/questions/3782157/ant-tasks-for-amazon-ec2-s3

Wednesday, December 12, 2012

Using Hibernate Query Cache in Spring

The steps for configuring the EHCache query cache is the same as when not using Spring. The main difference is how queries is being indicated as cacheable. In Spring, queries are made via the a subclass DAO of the HibernateDaoSupport class, which provides a method to indicate whether all queries in the DAO should use the query cache.

This should be called in the initDao method.

   @Override
   protected void initDao() throws Exception {
       super.initDao();

       // this enables the usage of query cache for all queries in this DAO
       this.getHibernateTemplate().setCacheQueries(true);

       // the cache region name that should be used for this entity
       this.getHibernateTemplate().setQueryCacheRegion(“XXXXXXX”);

       // optional, for enabling statistics collection for profiling
       this.getHibernateTemplate().getSessionFactory().getStatistics().setStatisticsEnabled(true);
   }


Note that this is for the query cache, not the second-level cache, the latter which is used for "get" operations.

Tuesday, December 4, 2012

Cocos2D: Z Order

The higher the number, the closer the object is to the viewer.

The lower the number, the further the object is to the viewer.

Jackson Pretty Print

Some of the solutions posted online is deprecated.

Here's the way to do it with a recent version of Jackson.


ObjectWriter jsonWriter = (new ObjectMapper()).writerWithDefaultPrettyPrinter();
String result = jsonWriter.writeValueAsString(obj);

Processing JSON Response in JMeter

This is a simple and somewhat limited way to do this. You will be able to extract individual values pretty easily but if you want a comprehensive data model of the JSON data structure, this isn't the way to go. If the same property name is used in multiple objects within a JSON data structure, this won't work as well.

Basically this method uses Regular Expressions (using JMeter's Regular Express Extractor) to extract individual values that you're looking for specifically.

Link: http://alexandru-ersenie.com/2009/09/14/json-and-jmeter-extract-json-response/

For more complex requirements, someone has posted about using the BSF PostProcessor and Javascript.

Link: http://www.havecomputerwillcode.com/blog/?p=500