Esquire Theme by Matthew Buchanan
Social icons by Tim van Damme

22

May

Spring Social Eventbrite plugin

I started on a Spring Social Plugin for Eventbrite. Right now it only supports search (event_search) but in the coming days I will be adding more support.

Its on github.

27

Mar

A better Mustache Spring View

I forked a github repository that has a Mustache View Resolver. It had no support for partials.

I fixed that: https://github.com/agentgt/mustache-spring-view

I need this for some Spring MVC Single Page Application work I’m doing. I plan on making another github project to show how it works.

06

Mar

JATL 0.2.1 released

JATL 0.2.1 has been released.

A rather strange issue with how XML treats white space was fixed: http://code.google.com/p/jatl/issues/detail?id=10

It turns out that XML normalizes white spaces in attribute values

That is:

  • CR #xD
  • Newline #xA
  • Tab #x9

Will be replaced with Space #x20 when parsed by a compliant XML parser. The only way to avoid this is to explicitly escape these characters. JATL now handles this correctly such that if you put a newline, tab, or carriage return character in your attribute its escaped properly. I feel slightly stupid about missing this as I even remember learning about this a long time ago.

The future release of JATL (0.3.0) will make it possible plugin your own custom escape strategy for both attributes and elements. 

The important thing to take from this is that there are different forms of XML escaping:

  • Element escaping (this is what most people know about)
  • Attribute escaping (this is what I missed)

Attribute escaping is rather tricky as you have to know when to escape the single (') or double quote ("). That is if you use the double quote to surround your attribute you will have to escape it. Vice versa for the other issue. I added a Util class to handle this and will make it more usable in the future.

Thank you David Portabella for finding this issue.

16

Feb

Fixing Spring’s Default View Resolver

Most Spring MVC applications use org.springframework.web.servlet.view.UrlBasedViewResolver

This view resolver allows you to redirect with the prefix “redirect:” thus you can do something like:

	@RequestMapping(value={"/doc/api", "/doc/api/"})
	public String apiDoc(ModelMap model) {
		//some logic
		m.put("hiddenStuff", "blah blah");
		if (success) { return "myview"; }
                else { return "redirect:/doc/api/index.html"; }
	}

This will redirect to http://host/doc/api/index.html?hiddenStuff=blah%20blah . This is probably not what you expected and also seems rather dangerous that its attaching model attributes as parameters.

Below is a fix and some enhancements for this annoying problem:

This view resolver allows you to redirect with out attaching the model attributes with redirect-no-model:. I have also added a way to do a permanent redirect (301) with redirect-permanently: instead of 307. You would use this if you refactored a public URL for SEO purposes.

03

Jan

HttpServletRequest getRequestURL() is dumb

Every time I have to wrap a Servlet Request for a filter I’m always reminded of the strangeness of getRequestURL() and its brother getRequestURI().

For the most part getRequestURI() makes sense if you know what it does. I say “know” because its javadoc is rather questionable.  It returns only the path and not the query parameters, host, port, and scheme. Ideally it should be called getRequestPath() but I can see why that name might be confused with the context path which is a completely different thing.

Now we get to getRequestURL() which returns a StringBuffer? According to the Javadoc I can edit this StringBuffer and add query parameters. However this is extremely misleading as this will do absolutely nothing to the request. In fact getRequestURL() returns a new StringBuffer everytime. Why the hell not just return a String? Some say its for performance (which its not but I’ll leave that as an exercise for later) and some say for convenience but I say its annoying. 

Also one would think getRequestURL() would return the query parameters but it does not which also bothers me slightly.

getPathInfo() is even more confusing. I try to avoid using it and instead use getContextPath() and getRequestURI().

The reason these things are annoying is that every time I go write a servlet filter I forget what does what and end up writing some log statements to see the output of each (since I don’t trust the javadoc). 

10

Dec

Added Twilio to my Maven respository

Added some Maven support to twilio: https://github.com/twilio/twilio-java However its still not in the central repository so I have added it my repositry.

Hopefully they’ll take my changes and create an Nexus account: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide

23

Nov

Is there a Coffeescript for Java?

Is there a Coffeescript for Java? In other words X gets compiled to readable Java.

If only I had more copious free time I might consider doing this as a side project. Maybe someone as already done this?

30

Oct

A Java Client for Amazon Commerce API

I had some old Amazon Product Advertising API Client (now known as its Commerce API) code lying around that I have been meaning to Github. This client uses JAXB and REST (Commons HTTP Client) instead of JAXWS.

https://github.com/agentgt/JavaAmazonProductAdvertisingClient

A relevant stackoverflow post: http://stackoverflow.com/questions/2963168/amazon-products-api-library-for-java

22

Oct

Added Spring Social LinkedIn into my Maven Repo

Spring Social has a SNAPSHOT version of spring-social-linkedin but has not released it as 1.0.0.RELEASE and unfortunately the milestone release is too far behind.

If you are using the maven release plugin it will not let you release with SNAPSHOT dependencies. I tried using the Maven Version plugin to get around this but I could not figure it out so I used my good ole custom maven repository:

18

Oct

JATL 0.2.0 Released

New Features:

  • whitespace/indenting support
  • OSGI bundle

I made indenting/whitespace/pretty-print support rather powerful at the cost of some complexity. I don’t know of any other library that allows you to apply different indenting based on the tag.

For example you can now make it so that <span> tags are always inlined (no newline or indenting).

Attribute white spacing is not yet available but it will come at some point.