You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@abdera.apache.org by Chiradip Narayan Mandal <ch...@gmail.com> on 2008/02/20 18:01:39 UTC

Problem with PUT and DELETE

* Hello,

Can anybody please help me about the below code? It is mainly taken from the
example written by James. With the same condition POST is going perfectly
well. But I am not able to perform PUT and DELETE operations. I understand
the success status codes for PUT and DELETE are different from POST. I am
getting 400 as the status code and 'Bad request' as the satus code text. I
want to know how PUT and DELETE can be performed.

Chiradip

public* *static* *void* putToBlogger() *throws* Exception {

Abdera abdera = *new* Abdera();

URL url = *new* URL("http://atomsandbox.blogspot.com/feeds/posts/default" );

Parser parser = Abdera.*getNewParser*();

Document<Feed> doc = parser.parse( url.openStream() );

Feed feed = doc.getRoot();

Entry entry = feed.getEntry( "tag:blogger.com,1999:
blog-8038874006622135494.post-6147415018903117917" );

*out*.println( "entry.getTitle() : " + entry.getTitle() );

entry.setUpdated( *new* java.util.Date() );

AbderaClient client = *new* AbderaClient( abdera );

String auth = GoogleLogin.*getAuth*( client, "blogger",
"your_real_user_name", "your_password" );

RequestOptions options = client.getDefaultRequestOptions();

options.setAuthorization( "GoogleLogin " + auth );

BaseRequestEntity bre = *new* BaseRequestEntity( entry, *false* );

Response response = client.put( "
http://atomsandbox.blogspot.com/feeds/posts/default", bre, options );

*out*.println("response.getStatusText() : " + response.getStatus() + " " +
response.getStatusText() );

*if* ( response.getStatus() == 201 )

*out*.println( "Success!" );

*else
*

*out*.println( "Failed!" );

}

Re: Problem with PUT and DELETE

Posted by David Calavera <da...@gmail.com>.
Hi Chiradip, I think that currently Google atom services specification is
obsolete, they are working on update it to
rfc5023 and I suppose that can be a problem in order to test
your client application.

If you don't want to create your own atomPub server, wordpress
supports rfc5023 and you can use it instead of blogger.

Regards

On 2/20/08, Chiradip Narayan Mandal <ch...@gmail.com> wrote:
>
> * Hello,
>
> Can anybody please help me about the below code? It is mainly taken from
> the
> example written by James. With the same condition POST is going perfectly
> well. But I am not able to perform PUT and DELETE operations. I understand
> the success status codes for PUT and DELETE are different from POST. I am
> getting 400 as the status code and 'Bad request' as the satus code text. I
> want to know how PUT and DELETE can be performed.
>
> Chiradip
>
> public* *static* *void* putToBlogger() *throws* Exception {
>
> Abdera abdera = *new* Abdera();
>
> URL url = *new* URL("http://atomsandbox.blogspot.com/feeds/posts/default"
> );
>
> Parser parser = Abdera.*getNewParser*();
>
> Document<Feed> doc = parser.parse( url.openStream() );
>
> Feed feed = doc.getRoot();
>
> Entry entry = feed.getEntry( "tag:blogger.com,1999:
> blog-8038874006622135494.post-6147415018903117917" );
>
> *out*.println( "entry.getTitle() : " + entry.getTitle() );
>
> entry.setUpdated( *new* java.util.Date() );
>
> AbderaClient client = *new* AbderaClient( abdera );
>
> String auth = GoogleLogin.*getAuth*( client, "blogger",
> "your_real_user_name", "your_password" );
>
> RequestOptions options = client.getDefaultRequestOptions();
>
> options.setAuthorization( "GoogleLogin " + auth );
>
> BaseRequestEntity bre = *new* BaseRequestEntity( entry, *false* );
>
> Response response = client.put( "
> http://atomsandbox.blogspot.com/feeds/posts/default", bre, options );
>
> *out*.println("response.getStatusText() : " + response.getStatus() + " " +
> response.getStatusText() );
>
> *if* ( response.getStatus() == 201 )
>
> *out*.println( "Success!" );
>
> *else
> *
>
> *out*.println( "Failed!" );
>
> }
>



-- 
David Calavera
http://www.thinkincode.net

Re: Problem with PUT and DELETE

Posted by James M Snell <ja...@gmail.com>.

Chiradip Narayan Mandal wrote:
> Hello James and David,
> 
> Thanks for your replies. But James! I think PUT & DELETE is not going to
> work with blogger using Abdera, even after overriding.
> 

I've tested it before with the current version of blogger and it's worked.

> I have another problem - it is regarding POST with roller. I use the latest
> version of roller and the code snippet below. Problem is with the line
> containign 'Service service = service_doc.getRoot();'. I am getting a
> ClassCastException saying FOMFeed can not be casted to Service. Any help?
> 

You must be trying to GET the collection feed and not the service 
document or, roller is serving the feed incorrectly when a service 
document is requested.

- James

> Chiradip
> 
> Document<Service> service_doc = client.get(start).getDocument();
> 
> Service service = service_doc.getRoot();
> 
> Collection collection = service.getWorkspaces
> ().get(0).getCollections().get(0);
> 
> String uri = collection.getHref().toString();
> 
> 
> On Wed, Feb 20, 2008 at 11:17 PM, James M Snell <ja...@gmail.com> wrote:
> 
>> They may be blocking PUT and DELETE. Try using POST but add the
>> X-HTTP-Method-Override header to the request.
>>
>> e.g.
>>
>>   POST /foo HTTP/1.1
>>   X-HTTP-Method-Override: PUT
>>
>> More info:
>>   http://code.google.com/apis/gdata/basics.html#Updating-an-entry
>>
>> In the Abdera client, the post override can be set using the
>> RequestOptions
>>
>>   Abdera abdera = new Abdera();
>>   AbderaClient client = new AbderaClient(abdera);
>>   RequestOptions options = client.getDefaultRequestOptions();
>>   options.setUsePostOverride(true);
>>   ClientResponse resp = client.put("...", ..., options);
>>
>>
>> - James
>>
>> Chiradip Narayan Mandal wrote:
>>> * Hello,
>>  >
>>> Can anybody please help me about the below code? It is mainly taken from
>> the
>>> example written by James. With the same condition POST is going
>> perfectly
>>> well. But I am not able to perform PUT and DELETE operations. I
>> understand
>>> the success status codes for PUT and DELETE are different from POST. I
>> am
>>> getting 400 as the status code and 'Bad request' as the satus code text.
>> I
>>> want to know how PUT and DELETE can be performed.
>>>
>>> Chiradip
>>>
>>> public* *static* *void* putToBlogger() *throws* Exception {
>>>
>>> Abdera abdera = *new* Abdera();
>>>
>>> URL url = *new* URL("http://atomsandbox.blogspot.com/feeds/posts/default"
>> );
>>> Parser parser = Abdera.*getNewParser*();
>>>
>>> Document<Feed> doc = parser.parse( url.openStream() );
>>>
>>> Feed feed = doc.getRoot();
>>>
>>> Entry entry = feed.getEntry( "tag:blogger.com,1999:
>>> blog-8038874006622135494.post-6147415018903117917" );
>>>
>>> *out*.println( "entry.getTitle() : " + entry.getTitle() );
>>>
>>> entry.setUpdated( *new* java.util.Date() );
>>>
>>> AbderaClient client = *new* AbderaClient( abdera );
>>>
>>> String auth = GoogleLogin.*getAuth*( client, "blogger",
>>> "your_real_user_name", "your_password" );
>>>
>>> RequestOptions options = client.getDefaultRequestOptions();
>>>
>>> options.setAuthorization( "GoogleLogin " + auth );
>>>
>>> BaseRequestEntity bre = *new* BaseRequestEntity( entry, *false* );
>>>
>>> Response response = client.put( "
>>> http://atomsandbox.blogspot.com/feeds/posts/default", bre, options );
>>>
>>> *out*.println("response.getStatusText() : " + response.getStatus() + " "
>> +
>>> response.getStatusText() );
>>>
>>> *if* ( response.getStatus() == 201 )
>>>
>>> *out*.println( "Success!" );
>>>
>>> *else
>>> *
>>>
>>> *out*.println( "Failed!" );
>>>
>>> }
>>>
> 

Re: Problem with PUT and DELETE

Posted by Chiradip Narayan Mandal <ch...@gmail.com>.
Hello James and David,

Thanks for your replies. But James! I think PUT & DELETE is not going to
work with blogger using Abdera, even after overriding.

I have another problem - it is regarding POST with roller. I use the latest
version of roller and the code snippet below. Problem is with the line
containign 'Service service = service_doc.getRoot();'. I am getting a
ClassCastException saying FOMFeed can not be casted to Service. Any help?

Chiradip

Document<Service> service_doc = client.get(start).getDocument();

Service service = service_doc.getRoot();

Collection collection = service.getWorkspaces
().get(0).getCollections().get(0);

String uri = collection.getHref().toString();


On Wed, Feb 20, 2008 at 11:17 PM, James M Snell <ja...@gmail.com> wrote:

> They may be blocking PUT and DELETE. Try using POST but add the
> X-HTTP-Method-Override header to the request.
>
> e.g.
>
>   POST /foo HTTP/1.1
>   X-HTTP-Method-Override: PUT
>
> More info:
>   http://code.google.com/apis/gdata/basics.html#Updating-an-entry
>
> In the Abdera client, the post override can be set using the
> RequestOptions
>
>   Abdera abdera = new Abdera();
>   AbderaClient client = new AbderaClient(abdera);
>   RequestOptions options = client.getDefaultRequestOptions();
>   options.setUsePostOverride(true);
>   ClientResponse resp = client.put("...", ..., options);
>
>
> - James
>
> Chiradip Narayan Mandal wrote:
> > * Hello,
>  >
> > Can anybody please help me about the below code? It is mainly taken from
> the
> > example written by James. With the same condition POST is going
> perfectly
> > well. But I am not able to perform PUT and DELETE operations. I
> understand
> > the success status codes for PUT and DELETE are different from POST. I
> am
> > getting 400 as the status code and 'Bad request' as the satus code text.
> I
> > want to know how PUT and DELETE can be performed.
> >
> > Chiradip
> >
> > public* *static* *void* putToBlogger() *throws* Exception {
> >
> > Abdera abdera = *new* Abdera();
> >
> > URL url = *new* URL("http://atomsandbox.blogspot.com/feeds/posts/default"
> );
> >
> > Parser parser = Abdera.*getNewParser*();
> >
> > Document<Feed> doc = parser.parse( url.openStream() );
> >
> > Feed feed = doc.getRoot();
> >
> > Entry entry = feed.getEntry( "tag:blogger.com,1999:
> > blog-8038874006622135494.post-6147415018903117917" );
> >
> > *out*.println( "entry.getTitle() : " + entry.getTitle() );
> >
> > entry.setUpdated( *new* java.util.Date() );
> >
> > AbderaClient client = *new* AbderaClient( abdera );
> >
> > String auth = GoogleLogin.*getAuth*( client, "blogger",
> > "your_real_user_name", "your_password" );
> >
> > RequestOptions options = client.getDefaultRequestOptions();
> >
> > options.setAuthorization( "GoogleLogin " + auth );
> >
> > BaseRequestEntity bre = *new* BaseRequestEntity( entry, *false* );
> >
> > Response response = client.put( "
> > http://atomsandbox.blogspot.com/feeds/posts/default", bre, options );
> >
> > *out*.println("response.getStatusText() : " + response.getStatus() + " "
> +
> > response.getStatusText() );
> >
> > *if* ( response.getStatus() == 201 )
> >
> > *out*.println( "Success!" );
> >
> > *else
> > *
> >
> > *out*.println( "Failed!" );
> >
> > }
> >
>

Re: Problem with PUT and DELETE

Posted by James M Snell <ja...@gmail.com>.
They may be blocking PUT and DELETE. Try using POST but add the 
X-HTTP-Method-Override header to the request.

e.g.

   POST /foo HTTP/1.1
   X-HTTP-Method-Override: PUT

More info:
   http://code.google.com/apis/gdata/basics.html#Updating-an-entry

In the Abdera client, the post override can be set using the RequestOptions

   Abdera abdera = new Abdera();
   AbderaClient client = new AbderaClient(abdera);
   RequestOptions options = client.getDefaultRequestOptions();
   options.setUsePostOverride(true);
   ClientResponse resp = client.put("...", ..., options);


- James

Chiradip Narayan Mandal wrote:
> * Hello,
> 
> Can anybody please help me about the below code? It is mainly taken from the
> example written by James. With the same condition POST is going perfectly
> well. But I am not able to perform PUT and DELETE operations. I understand
> the success status codes for PUT and DELETE are different from POST. I am
> getting 400 as the status code and 'Bad request' as the satus code text. I
> want to know how PUT and DELETE can be performed.
> 
> Chiradip
> 
> public* *static* *void* putToBlogger() *throws* Exception {
> 
> Abdera abdera = *new* Abdera();
> 
> URL url = *new* URL("http://atomsandbox.blogspot.com/feeds/posts/default" );
> 
> Parser parser = Abdera.*getNewParser*();
> 
> Document<Feed> doc = parser.parse( url.openStream() );
> 
> Feed feed = doc.getRoot();
> 
> Entry entry = feed.getEntry( "tag:blogger.com,1999:
> blog-8038874006622135494.post-6147415018903117917" );
> 
> *out*.println( "entry.getTitle() : " + entry.getTitle() );
> 
> entry.setUpdated( *new* java.util.Date() );
> 
> AbderaClient client = *new* AbderaClient( abdera );
> 
> String auth = GoogleLogin.*getAuth*( client, "blogger",
> "your_real_user_name", "your_password" );
> 
> RequestOptions options = client.getDefaultRequestOptions();
> 
> options.setAuthorization( "GoogleLogin " + auth );
> 
> BaseRequestEntity bre = *new* BaseRequestEntity( entry, *false* );
> 
> Response response = client.put( "
> http://atomsandbox.blogspot.com/feeds/posts/default", bre, options );
> 
> *out*.println("response.getStatusText() : " + response.getStatus() + " " +
> response.getStatusText() );
> 
> *if* ( response.getStatus() == 201 )
> 
> *out*.println( "Success!" );
> 
> *else
> *
> 
> *out*.println( "Failed!" );
> 
> }
>