Spring 3.1 and Rest headaches

To get the rest interfaces I planned to work in my Spring application were a bit of a headache because I did not do many things correctly.

First thing I was not aware was the changes to the web.xml:

<filter>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <servlet-name>spring</servlet-name>
</filter-mapping>

These lines were added right after the DispatcherServlet. Without these lines I was getting errors on the DELETE method saying that the POST method was not implemented.

I also had a lot of trouble trying to generate a dynamic URL for the Rest calls. I could not get code similar to this to work:

<form:form action="<%= formUrl%>" method="delete">
	<input type="submit" value="Delete"/>
</form:form>

I tried the construct to generate the URL and it would not accept a string concatenated with a property from an object.

I add to declare a variable to do the concatenation:

String formUrl = "/admin/something/" + something.getId();

At least everything is working right now but that is a few hours lost to figuring out what works and why. Coding fun!

Advertisements

Published by

m5c

Java developper that loves photography and good coffee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s