Making POST and DELETE calls to resource URL

As per portlet specification "For use cases that require state changes the serveResource call should be issued via an HTTP method POST or PUT or DELETE." I tried creating a ServeResourceHttpRequestPortlet to check if i can make HTTP PUT or HTTP DELETE call to portlet and i tried it on both WebSphere Portal and Apache Pluto and i got 405: HTTP method DELETE is not not supported by this URL error.

The ServeResourceHttpRequestPortlet is like this

public class ServeResourceHttpRequestPortlet extends GenericPortlet{
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering ServeResourceHttpRequestPortlet.doView()");
response.setContentType("text/html");
getPortletContext().getRequestDispatcher("/index.jsp").include(request, response);
System.out.println("Exiting ServeResourceHttpRequestPortlet.doView()");
}
public void serveResource(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
System.out.println("Entering ServeResourceHttpRequestPortlet.serveResource()");
response.setContentType("text/html");
System.out.println("Request method is " + request.getMethod());
response.getWriter().println("HTTP Method used is " + request.getMethod());
System.out.println("Exiting ServeResourceHttpRequestPortlet.serveResource()");
}
}


As you can see the serveResource() method simply returns name of the HTTP method used for making this request.

In the doView(), method i am passing control to index.jsp which is like this

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="false"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<style type="text/css">
@import src="http://o.aolcdn.com/dojo/1.3.2/dijit/themes/tundra/tundra.css";
@import src=""http://o.aolcdn.com/dojo/1.3.3/dojo/resources/dojo.css";
</style>
<script type="text/javascript" src="http://o.aolcdn.com/dojo/1.3.2/dojo/dojo.xd.js"
djConfig="parseOnLoad:true">
</script>
<portlet:defineObjects />
<script type="text/javascript">
dojo.require("dijit.form.Button");
dojo.require("dojo.parser");
</script>
<table>
<tr>
<td>
<button dojoType="dijit.form.Button" id="get">GET
<script type="dojo/method" event="onClick">
dojo.xhrGet({
url: "<portlet:resourceURL/>",
load: function(data, ioargs){
dojo.byId("resourceResponse").innerHTML = data;
},
error: function(error,ioargs){
alert(error);
}
});
</script>
</button>
</td>
<td>
<button dojoType="dijit.form.Button" id="post">POST
<script type="dojo/method" event="onClick">
dojo.xhrPost({
url: "<portlet:resourceURL/>",
load: function(data, ioargs){
dojo.byId("resourceResponse").innerHTML = data;
},
error: function(error,ioargs){
alert(error);
}
});
</script>
</button>
</td>
<td>
<button dojoType="dijit.form.Button" id="delete">DELETE
<script type="dojo/method" event="onClick">
dojo.xhrDelete({
url: "<portlet:resourceURL/>",
load: function(data, ioargs){
dojo.byId("resourceResponse").innerHTML = data;
},
error: function(error,ioargs){
alert(error);
}
});
</script>
</button>
</td>
<td>
<button dojoType="dijit.form.Button" id="put">PUT
<script type="dojo/method" event="onClick">
dojo.xhrPut({
url: "<portlet:resourceURL/>",
load: function(data, ioargs){
dojo.byId("resourceResponse").innerHTML = data;
},
error: function(error,ioargs){
alert(error);
}
});
</script>
</button>
</td>
</tr>
</table>
<div id="resourceResponse" />


As you can see the index.jsp has 4 buttons which try GET, POST, PUT and DELETE call to the resource URL. As you can see the GET and POST method worked but PUT and DELETE did not

3 comments:

srjwebsolutions said...


We are leading responsive website designing and development company in Noida.
We are offering mobile friendly responsive website designing, website development, e-commerce website, seo service and sem services in Noida.

Responsive Website Designing Company in Noida
Website Designing Company in Noida
SEO Services in Noida
SMO Services in Noida

Vikas Chaudhary said...

Battery Mantra is Authorized exide car battery dealer in Noida and Greater Noida. We are providing our service in Indirapuram, Delhi, Ashok Nagar.

Exide Battery Dealer in Noida
Battery Dealer in Noida
Authorized Battery Dealer in Noida
Car Battery Dealer in Noida
Car Battery Dealer
Exide Battery Dealer

EG MEDI said...

Egmedi.com is online medical store pharmacy in laxmi nagar Delhi. You can Order prescription/OTC medicines online.
Cash on Delivery available. Free Home Delivery


Online Pharmacy in Delhi
Buy Online medicine in Delhi
Online Pharmacy in laxmi nagar
Buy Online medicine in laxmi nagar
Onine Medical Store in Delhi
Online Medical store in laxmi nagar
Online medicine store in delhi
online medicine store in laxmi nagar
Purchase Medicine Online
Online Pharmacy India
Online Medical Store