users@jersey.java.net

Re: [Jersey] HTTP Status Error 405 when using POST

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 07 Apr 2009 20:03:05 +0200

On Apr 7, 2009, at 7:52 PM, Naresh wrote:

> Hi Tim,
>
> I think the response hints that you are not sending a POST request,
> but a GET.
> Are you sending the request as a form submission, if so may be you
> should specify the form submission method as POST?
>

Or try using curl e.g.:

curl -v -X POST http://mymachine:8080/myapp/applicationperms/updateacessleve?user=johndoe&appname=TEST&level=0


> One more suggestion - in general a PUT request should be used for
> performing any updates and POST should be for creations.
>

In addition: PUT can also be used for updates too. It depends on who
has control of the URI space, the client or the server. Also POST is
not exclusively used for creation it can be used for actions on
resources. Sometimes it is also used for updates because of
limitations with browsers supporting PUT.

Paul.

> Thanks,
> Naresh
>
> timothy-a.mcknight_at_ubs.com wrote:
>>
>> Hi,
>>
>> I am trying to use @POST to perform an update. My method is the
>> following:
>>
>> @POST
>> @Path("updateacesslevel")
>> public void updateUserAccessLevel(@QueryParam("appname")
>> String anApplication, @QueryParam("user") String aUser,
>> @QueryParam("level") int appLevel) {
>>
>> /***if (anApplication == null) {
>> //do something
>> }
>> if (aUser == null) {
>> //do something
>> }*/
>> if (aUser != null && anApplication != null){
>> int returnValue;
>> try {
>> returnValue =
>> AppPerms.updateAppAccessLevel(anApplication, aUser, appLevel);
>> } catch (Exception e) {
>> log.error("Error updating access,",
>> e);
>> }
>> }
>> }
>>
>> When I hit my url:
>> _http://mymachine:8080/myapp/applicationperms/updateacesslevel?user=johndoe&appname=TEST&level=0_
>> <http://mymachine:8080/myapp/applicationperms/updateacesslevel?user=johndoe&appname=TEST&level=0
>> >
>>
>>
>> I get an HTTP Status 405 -_ The specified HTTP method is not allowed
>> for the requested resource ()._
>>
>> I am using tomcat 6 and my web.xml file is as follows:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns="http://java.sun.com/xml/ns/javaee"
>> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>> _http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd_" id="WebApp_ID"
>> version="2.5">
>>
>> <display-name>ORION</display-name>
>>
>> <servlet>
>> <servlet-name>My app</servlet-name>
>> <servlet-class>
>>
>> com.sun.jersey.spi.container.servlet.ServletContainer
>> </servlet-class>
>> <load-on-startup>1</load-on-startup>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>My app</servlet-name>
>> <url-pattern>/*</url-pattern>
>> </servlet-mapping>
>> <security-constraint>
>> <web-resource-collection>
>> <web-resource-name>Permitted Actions</web-resource-
>> name>
>> <url-pattern>/*</url-pattern>
>> <http-method>GET</http-method>
>> <http-method>POST</http-method>
>> <http-method>PUT</http-method>
>> <http-method>DELETE</http-method>
>> </web-resource-collection>
>> </security-constraint>
>> </web-app
>>
>> Does anyone have an idea on what I may be doing wrong?
>>
>> Thanks,
>> Tim
>>
>> ------------------------------------------------------------------------
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>