Creating links

16 views
Skip to first unread message

Fabiano Almeida

unread,
Jan 31, 2013, 3:18:12 PM1/31/13
to rest...@googlegroups.com
Hello everyone,

I have a server in Java and a client in Ruby. My Java application has this code:
@XStreamAlias("local")
public class Local implements HypermediaResource {
  // gets and sets

  public void configureRelations( RelationBuilder builder ) {
    builder.relation( "self" ).uses( LocalController.class ).get( id );
  }
}
When I get a register by id and try to access link "self", this doesn't exist. Here is my Ruby code:
resource.links.self
After this error, I tried to access the URL on my browser and I can't see the "atom" attribute on the XML generated.

What's wrong with my code?

Thanks in advance!

--
Fabiano Almeida

Fabiano Almeida

unread,
Feb 1, 2013, 1:04:55 PM2/1/13
to rest...@googlegroups.com
Hi guys,

I solved it. I didn't see the web.xml configuration on Java application.

However, I figured out other problem. I can't access directly the resource on Ruby application (my client). I need make something like that:
current = Restfulie.at('http://localhost:8080/context/locals/1').accepts("application/xml").get
# ...

current.resource
# => { "local" =>
#      { "id" =>"1", 
#        "description"=>"Testing", 
#        "status"=>"A", 
#        "user"=>"1228", 
#        "created"=>"2013-01-31 15:37:18.0", 
#        "updated"=>"2013-01-31 15:37:18.0", 
#        "link"=>[
#                     { "rel"=>"self", 
#                       "href"=>"http://localhost:8080/context/locals/1",
#                       "xmlns:atom"=>"http://www.w3.org/2005/Atom"}
#                   ]
#      }}

# response.resource doesn't returning local object
local = response.resource['local']

local.links
# => nil

local.link('self')
# => [{"rel"=>"self", "href"=>"http://localhost:8080/context/locals/1", "xmlns:atom"=>"http://www.w3.org/2005/Atom"}]
I can't understood this behavior. I need to have in my Ruby client an ActiveRecord called Local? Is it necessary?

Thanks in advance!

--
Fabiano Almeida

Guilherme Silveira

unread,
Feb 1, 2013, 1:26:39 PM2/1/13
to restfulie
Hi Fabiano,

Great!

It doesn't feel right, although if it is being returned like that it is... what is the rails version?

regards

Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/


--
 
---
You received this message because you are subscribed to the Google Groups "restfulie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to restfulie+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Fabiano Almeida

unread,
Feb 1, 2013, 1:37:57 PM2/1/13
to rest...@googlegroups.com
Oh great Guilherme!

Thanks, btw! I'm on 3.2.11 version of Rails.

What's information that you need?
--
Fabiano Almeida

Guilherme Silveira

unread,
Feb 1, 2013, 2:55:54 PM2/1/13
to restfulie

Hi fabiano.

Where is the responses variante coming from in your Last example?

Regards

Fabiano Almeida

unread,
Feb 4, 2013, 7:19:01 AM2/4/13
to rest...@googlegroups.com
Hello Guilherme,

I'm sorry by delay. Ok, below I show my response log after call my register via get
1.9.3p194 :001 > current = Restfulie.at('http://localhost:8080/contest/locals/1').accepts("application/xml").get
#=> ready to execute request using stack [{:type=>Restfulie::Client::Feature::BaseRequest, :args=>[]}, {:type=>Restfulie::Client::Feature::RescueException, :args=>[]}, {:type=>Restfulie::Client::Feature::SetupHeader, :args=>[]}, {:type=>Restfulie::Client::Feature::SerializeBody, :args=>[]}, {:type=>Restfulie::Client::Feature::EnhanceResponse, :args=>[]}, {:type=>Restfulie::Client::Feature::FollowRequest, :args=>[]}]
#=> invoking filter Restfulie::Client::Feature::FollowRequest with #<Restfulie::Client::Dsl:0x007fa8d3aed7c8> at {}
#=> invoking filter Restfulie::Client::Feature::EnhanceResponse with #<Restfulie::Client::Dsl:0x007fa8d3aed7c8> at {}
#=> invoking filter Restfulie::Client::Feature::SerializeBody with #<Restfulie::Client::Dsl:0x007fa8d3aed7c8> at {}
#=> invoking filter Restfulie::Client::Feature::SetupHeader with #<Restfulie::Client::Dsl:0x007fa8d3aed7c8> at {}
#=> invoking filter Restfulie::Client::Feature::RescueException with #<Restfulie::Client::Dsl:0x007fa8d3aed7c8> at {}
#=> invoking filter Restfulie::Client::Feature::BaseRequest with #<Restfulie::Client::Dsl:0x007fa8d3aed7c8> at {}
#=> GET /context/locals/1

#=> #<Net::HTTPOK 200 OK readbody=true>
By the way, I have a silly doubt... I need to have an ActiveRecord model (called Local) on my client? I guess the answer is no, but I was with this in mind.

Thanks, again, in advance!

Fabiano Almeida

unread,
Feb 13, 2013, 12:44:30 PM2/13/13
to rest...@googlegroups.com
Hello Guilherme,

Any update on this? Is it incompatible with the rails last version?

Thanks in advance!
--
Fabiano Almeida

Fabiano Almeida

unread,
Feb 18, 2013, 8:37:44 AM2/18/13
to rest...@googlegroups.com
Hi Guilherme,

Please, help me. Do you have any smoke signal? ;-)

I'm so sorry for many messages, but I need to solve this problem and I don't know what's happening.

Thanks in advance!
--
Fabiano Almeida

Guilherme Silveira

unread,
Feb 18, 2013, 6:51:28 PM2/18/13
to restfulie
Hi Fabiano,

Sorry Im on vacation. The resource and code methods are returning correctly? 200 and what?
Try outputting the resource content and checking if the hash contains the link variable

Regards


Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/


Fabiano Almeida

unread,
Feb 19, 2013, 1:15:44 PM2/19/13
to rest...@googlegroups.com
Hi Guilherme,

I'm so sorry. I didn't know that you're on vacation. Sorry!

Answering your first question... Yes!
=> #<Net::HTTPOK 200 OK readbody=true>
Above I showing all the output. Beginning the first URL call (get method) and finishing with showing resource content:

1.9.3-p194 :007 > current = Restfulie.at('http://localhost:8080/context/locals/1').accepts("application/xml").get

#=> ready to execute request using stack [{:type=>Restfulie::Client::Feature::BaseRequest, :args=>[]}, {:type=>Restfulie::Client::Feature::RescueException, :args=>[]}, {:type=>Restfulie::Client::Feature::SetupHeader, :args=>[]}, {:type=>Restfulie::Client::Feature::SerializeBody, :args=>[]}, {:type=>Restfulie::Client::Feature::EnhanceResponse, :args=>[]}, {:type=>Restfulie::Client::Feature::FollowRequest, :args=>[]}]
#=> invoking filter Restfulie::Client::Feature::FollowRequest with #<Restfulie::Client::Dsl:0x007fe03f40a098> at {}
#=> invoking filter Restfulie::Client::Feature::EnhanceResponse with #<Restfulie::Client::Dsl:0x007fe03f40a098> at {}
#=> invoking filter Restfulie::Client::Feature::SerializeBody with #<Restfulie::Client::Dsl:0x007fe03f40a098> at {}
#=> invoking filter Restfulie::Client::Feature::SetupHeader with #<Restfulie::Client::Dsl:0x007fe03f40a098> at {}
#=> invoking filter Restfulie::Client::Feature::RescueException with #<Restfulie::Client::Dsl:0x007fe03f40a098> at {}
#=> invoking filter Restfulie::Client::Feature::BaseRequest with #<Restfulie::Client::Dsl:0x007fe03f40a098> at {}
#=> GET /genhio/localidades/1


 => #<Net::HTTPOK 200 OK readbody=true> 
1.9.3-p194 :008 > current.resource
 => {"local"=>{"id"=>"1", "description"=>"Test", "status"=>"A", "userCreated"=>"594", "createdAt"=>"2013-02-19 15:00:56.0", "userUpdated"=>"594", "updatedAt"=>"2013-02-19 15:00:56.0", "link"=>[{"rel"=>"self", "href"=>"http://localhost:8080/context/locals/1", "xmlns:atom"=>"http://www.w3.org/2005/Atom"}, {"rel"=>"locais", "href"=>"http://localhost:8080/context/locals/1/all", "xmlns:atom"=>"http://www.w3.org/2005/Atom"}]}}
So, in the resource I can see an attribute called link (an array), containing all available links.

Guilherme Silveira

unread,
Mar 6, 2013, 6:30:46 AM3/6/13
to restfulie
Hi Fabiano,

I am back. It looks like it is the way it should. Because there is a root element called local, you should first do .local before reaching for the link, like the code in your second email. 

Regards

Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/


Reply all
Reply to author
Forward
0 new messages