Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in DELETE operation in REST Webservice

 
Sharmistha Sarkar
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to extract HTML FORM values (age, name) in my rest service's java class.

First please look at my web.xml

WEB.XML


in web.xml I have added a filter "HiddenHttpMethodFilter" , It is because some where I saw there is no HTML FORM supports redirect Method as "DELETE" because there are only 2 methods available get and post. So I added this filter to support the Method="DELETE". But I am getting an exception below,



Now, If I don't add the filter I could write Method="GET" and get no exception like this. but I am again unable to extract HTML FORM Values(age , name)

INDEX.HTML


LoginService.java

@Path("/WebService")
public class LoginService {
@DELETE
@Path("/Delete/{age}/{name}")
@Produces("text/plain")

public static void getDelete(@PathParam("age") int age,@PathParam("name") String name) throws Exception {
System.out.println(age+name);

}
}

JARS in MY ECLIPSE BUILD PATH:
1. commons-logging-1.1.1
2. javax.servlet-api-3.0.1 [also I pasted inside <Tomcat>lib....as mentioned in some site]
3. urlrewritefilter-4.0.4
4. cors-filter-1.5.1 [also I pasted inside <Tomcat>lib]

JARS INSIDE WEBCONTENT->WEB-INF->LIB
1.asm-all-3.1.jar
2.asm-attrs-2.2.3.jar
3.asm-commons-4.0.jar
4.asm-util-4.1.jar
5.jersey-client-1.0.3.jar
6.jersey-core-1.0.3.jar
7.jersey-server-1.0.3.jar
8.jsr311-api-1.0.jar

However I just want my HTML Form Values to get into the LoginService.getDelete() and prints the value(age+name). Somewhere I read DELETE method in REST webservice cannot return any value so I gave void in getDelete(). I appreciate if anyone could help me out to resolve . I am stuck on this.
 
P Kn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i don't think HTML form i the best way to test your service. Check browser's address bar after submitting form. It shows something like:
../REST/WebService/Delete?age=30&name=Test
instead of:
../REST/WebService/Delete/30/Test
which LoginService is expecting. Moreover HTTP method of that request is... GET. Better try using a HTTP/REST client tool, like Simple Http Client (Chrome extension) and it should work.

 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML forms support GET and POST, but none of the other HTTP methods. You need to do a REST call through JavaScript or some other client app.

Also, are you certain that this error "java.lang.ClassNotFoundException: org.springframework.web.filter.HiddenHttpMethodFilter" has no bearing whatsoever on the working of your web app?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic