Re: jaxrs processing response

2012-02-23 Thread guillaume.m...@gmail.com
Each time I post a message, five minute after I find the solution:

just setRequestEntityBuffering to true.

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/jaxrs-processing-response-tp7084522p7313263.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2926005


Re: Restlet ClientResource Post Chunked Encoding - WCF Unsuported

2012-02-23 Thread guillaume.m...@gmail.com
Did you try setRequestEntityBuffering(true) like this:


ClientResource cr = new ClientResource("// uri //");
cr.setRequestEntityBuffering(true);


It work for me. 

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Restlet-ClientResource-Post-Chunked-Encoding-WCF-Unsuported-tp455p7313256.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2926003

Jetty + Webapp

2012-02-23 Thread Guilherme Gotardo
Hi all,

I have a .WAR file that contains a simple HelloWorld, and I want to add it into 
my server. I'm using the Jetty connector.

When I run my war directly with Jetty Server, works fine, but when I try to run 
using Restlet, the following error occurs:

Fev 23, 2012 2:40:47 PM org.restlet.engine.Engine createHelper
Warning: No available server connector supports the required protocols: 'WAR' . 
Please add the JAR of a matching connector to your classpath.
2012-02-23 14:40:47.274:INFO::jetty-7.1.6.v20100715
2012-02-23 14:40:47.367:INFO::Started SelectChannelConnector@0.0.0.0:8080


I've attached my code, please, what can I do to resolve that?
Thanks in advanced.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2925951

Main.java
Description: Binary data


MyResource.java
Description: Binary data


Re: jaxrs processing response

2012-02-23 Thread guillaume.m...@gmail.com
I try to do the same thing

Client side



ClientResource consumer = new ClientResource("// uri //");

Campus camp = new Campus("Montréal");
try {
consumer.post(camp, 
MediaType.APPLICATION_JSON).write(System.out);
// should echo
{key:""ahJzfm5vdGV0b25zdGExMzQ1MDhyDQsSBkNhbXB1cxjpBww,name:"Montréal"}
} catch (ResourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



Server side


@POST @Path("campus")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Campus create(Campus campus){
// but introspecting the campus object and get nothing
// store in database and retrieve the new created campus object
//
{key:""ahJzfm5vdGV0b25zdGExMzQ1MDhyDQsSBkNhbXB1cxjpBww,name:"Montréal"}
return campus;
}


My Campus Object 


@Entity
public class Campus implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger log =
Logger.getLogger(Campus.class.getSimpleName());

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private Key key;

@Basic
private String name;

@Basic
@JsonIgnore
private List interventionIds;

public Campus(){}

public Campus(Key key, String name) {
this.key = key;
this.name = name;
}

public Key getKey() {
return key;
}

public void setKey(Key key) {
this.key = key;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List getInterventionIds() {
return interventionIds;
}

public void setInterventionsKey(List interventionIds) {
this.interventionIds = interventionIds;
}

public void addInterventionId(Long id){
if(!this.interventionIds.contains(id)) {
this.interventionIds.add(id);
}
}

public void removeInterventionId(Long id) throws KeyNotFoundException {
if(!this.interventionIds.contains(id)){
throw new KeyNotFoundException();   
}

this.interventionIds.remove(id);
}

@JsonProperty
public String key(){
log.log(Level.INFO, "Key conversion (before)", this.key);
String convert_key = KeyFactory.keyToString(this.key);
log.log(Level.INFO, "Key conversion (after)", convert_key);

return convert_key;
}

@JsonProperty
public void key(String k){
this.setKey(KeyFactory.stringToKey(k));
}

@Override
public boolean equals(Object arg0) {
// TODO Auto-generated method stub
return EqualsBuilder.reflectionEquals(this, arg0);
}

@Override
public int hashCode() {
// TODO Auto-generated method stub
return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}


@Produces works fine and I get the good representation but @Consumes not
consumes the JSON to Java Object  

If someone can help us.

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/jaxrs-processing-response-tp7084522p7313223.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2926001

JaxbRepresentation + DecodeRepresentation problems

2012-02-23 Thread Felix Breske
Hi,
we have a client/server Application with restlet 1.1, 
Encode/DecodeRepresentation (for GZIP compression) and JaxbRepresention. 
Now ne need a new client and we tried restlet 2.0 on the client side.

With restlet 2.0 we run into some  trouble using JaxB and GZIP. After 
some debuging i found a problem. The DecodeRepresentation decodes only 
on getStream. The getText method uses getStream, so it works. The 
JaxbRepresentaion.getObject uses getReader instead of getStream (this 
changed since version 1.1.8 we use until now). getReader from the 
superclass WrappedRepresentation uses the getStream on the wrapped 
entity, so DecodeRepresentation.getStream is never called and Jaxb 
cannot read the GZIP Stream.

I've some test classes attached. At the ClientTest i override getReader 
with the code from StreamRepresentation.getReader to fix that problem.

So, is it a bug or just the wrong way to use jaxb and gzip? What ist the 
best practise for this usecase?

Thanks,
Felix

public class ClientTest {
 public static void main(final String[] args) throws 
ResourceException, IOException {
 ClientResource resource = new 
ClientResource("http://localhost:8182";);

 Representation r = new DecodeRepresentation(resource.get()) {
 @Override
 public Reader getReader() throws IOException {
 return BioUtils.getReader(getStream(), getCharacterSet());
 }
 };
 JaxbRepresentation jaxb = new 
JaxbRepresentation(r, TestDTO.class);
 TestDTO object = jaxb.getObject();
 System.out.println("Output : " + object.getString());
 }
}

public class ServerTest extends ServerResource {

 public static void main(final String[] args) throws Exception {
 new Server(Protocol.HTTP, 8182, ServerTest.class).start();
 }

 @Get("xml")
 public Representation getRepresentation() {
 TestDTO test = new TestDTO();
 test.setString("test");
 JaxbRepresentation rep = new 
JaxbRepresentation(test);
 return new EncodeRepresentation(Encoding.GZIP, rep);
 }
}

@XmlRootElement
public class TestDTO {
 private String string;

 public String getString() {
 return string;
 }

 public void setString(final String string) {
 this.string = string;
 }

}

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2925839


Re: Post problems when using Restlet Javascript Edition...

2012-02-23 Thread Thierry Templier
Hello Richard,

I answer in the message content.
> Thierry:
>
> Thanks so much for your help.  The short version is that the latest 
> Restlet JS code (plus one change in my code) fixes my problem with 
> post().  There is one "strangeness" that I will describe below, but it 
> isn't a big problem for me at this point, but I will describe it below 
> in case you think it matters.  Again, thank you!!  And, please let me 
> know if there is any testing that I can do for you.
You're welcome! Thanks very much for your proposal!
> Details...
> I installed the new scripts.  Only part that confused me was that I 
> initially took restlet-browser.js from:
> * modules\org.restlet.js\src\dist\restlet-browser.js
> But that was the wrong file, I had to use:
> * tests\org.restlet.js.tests\src\browser\static\restlet\restlet-browser.js
> if that is what was intended, all is fine.
The restlet-browser.js in the modules/org.restlet.js/src/dist folder is 
the assembly file that selects which files to include in the Restlet JS 
edition for browser. After having run Ant with build.browser task, the 
js file for the edition can be found in the 
modules/org.restlet.js/target/browser directory.
> Once I put in the right restlet-browser.js, I ran my test and got a 
> 415 error.  So I ran the test through tcpmon - and when going through 
> tcpmon - it worked!  But the mystery was that when going through 
> tcpmon, the server side method "acceptJava()" was being called, not 
> "acceptJson()".  I changed the ordering as per your email, but that 
> still didn't fix my problem (but I did discover that the re-ordering 
> is indeed necessary, but that is getting ahead of the story).
Do you know if tcpmon updates the request by adding or removing some 
HTTP headers?
>
> At this point I had:
> public interface CommitmentsResource {
>   @Post("json")
>   public String acceptJson(String value);  // For JSON
>   @Post("form")
>   public Representation accept(Form form);  // For HTML form
>   @Post()
>   public Representation acceptJava(Commitment commitment); // For Java 
> post
> }
>
> And...
> public class CommitmentsServerResource extends WadlServerResource 
> implements CommitmentsResource {
> @Post
> public Representation acceptJava(Commitment commitment) {
> }
> @Override
> public String acceptJson(String value) {
> }
> @Override
> // This is the code that actually handles posts that come from forms 
> and http posts
> public Representation accept(Form form) {
> }
> I had the thought that acceptJava was the one being called since it 
> was the only one with the @Post annotation.  I changed the @Override 
> annotations to @Post.  And then the Javascript post was handled by the 
> acceptJson method (which I then fleshed out and changed to return a 
> Represenation).
>
> Everything would be perfect at this point, except for the 
> "strangeness".  Now when I run the test through tcpmon, I get a 415 
> error there.  The call does make it to the server, since I get an 
> error in the console along the lines of:
> Feb 22, 2012 3:07:33 PM org.restlet.ext.jackson.JacksonRepresentation 
> getObject
> WARNING: Unable to parse the object with Jackson.
> org.codehaus.jackson.map.JsonMappingException: Can not deserialize 
> instance of org.restlet.data.Form out of START_OBJECT token
>  at [Source: org.restlet.engine.io.UnclosableInputStream@41c7d56b; 
> line: 1, column: 1]
>  at 
> org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
>   .
>
> And then to try and break my "non-tcpmon" client, I changed the 
> ordering of the @Post methods, and that did indeed break things as you 
> had predicted.
I discussed this issue with Restlet team and the problem comes from the 
Jackson extension. In fact, there is a problem when computing scores to 
route to the right method. They're working on this issue...
>
> Thanks again!!
> RB
Thierry

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2925813

Re: Post problems when using Restlet Javascript Edition...

2012-02-23 Thread Richard Berger
Thierry:

Thanks so much for your help.  The short version is that the latest Restlet
JS code (plus one change in my code) fixes my problem with post().  There
is one "strangeness" that I will describe below, but it isn't a big problem
for me at this point, but I will describe it below in case you think it
matters.  Again, thank you!!  And, please let me know if there is any
testing that I can do for you.

Details...
I installed the new scripts.  Only part that confused me was that I
initially took restlet-browser.js from:
* modules\org.restlet.js\src\dist\restlet-browser.js
But that was the wrong file, I had to use:
* tests\org.restlet.js.tests\src\browser\static\restlet\restlet-browser.js
if that is what was intended, all is fine.

Once I put in the right restlet-browser.js, I ran my test and got a 415
error.  So I ran the test through tcpmon - and when going through tcpmon -
it worked!  But the mystery was that when going through tcpmon, the server
side method "acceptJava()" was being called, not "acceptJson()".  I changed
the ordering as per your email, but that still didn't fix my problem (but I
did discover that the re-ordering is indeed necessary, but that is getting
ahead of the story).

At this point I had:
public interface CommitmentsResource {
  @Post("json")
  public String acceptJson(String value);  // For JSON
  @Post("form")
  public Representation accept(Form form);  // For HTML form
  @Post()
  public Representation acceptJava(Commitment commitment); // For Java post
}

And...
public class CommitmentsServerResource extends WadlServerResource
implements CommitmentsResource {
@Post
public Representation acceptJava(Commitment commitment) {
 }
@Override
public String acceptJson(String value) {
 }
@Override
// This is the code that actually handles posts that come from forms and
http posts
 public Representation accept(Form form) {
}
I had the thought that acceptJava was the one being called since it was the
only one with the @Post annotation.  I changed the @Override annotations to
@Post.  And then the Javascript post was handled by the acceptJson method
(which I then fleshed out and changed to return a Represenation).

Everything would be perfect at this point, except for the "strangeness".
 Now when I run the test through tcpmon, I get a 415 error there.  The call
does make it to the server, since I get an error in the console along the
lines of:
Feb 22, 2012 3:07:33 PM org.restlet.ext.jackson.JacksonRepresentation
getObject
WARNING: Unable to parse the object with Jackson.
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance
of org.restlet.data.Form out of START_OBJECT token
 at [Source: org.restlet.engine.io.UnclosableInputStream@41c7d56b; line: 1,
column: 1]
 at
org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
  .

And then to try and break my "non-tcpmon" client, I changed the ordering of
the @Post methods, and that did indeed break things as you had predicted.

Thanks again!!
RB

On Wed, Feb 22, 2012 at 1:07 AM, Thierry Templier [via Restlet Discuss] <
ml-node+s1400322n730770...@n2.nabble.com> wrote:

> Hello Richard,
>
> Regarding the post HTTP method and the annotated methods server
> resources, I updated the header management in the JavaScript edition.
> The routing to such methods is based on the Content-Type header. I
> committed all my updates in GitHub, so feel free to make some tests and
> give me a feedback.
>
> Be aware that there is a bug in Restlet 2.1 regarding the routing to the
> right methods. If a media isn't specified for the first method, this
> method will be used and it's not correct...
>
> @Put
> (...)
>
> @Put("json")
> (...)
>
> It works with the following:
>
> @Put("json")
> (...)
>
> @Put
> (...)
>
> This problem is about to be fixed in the Java version of Restlet.
>
> Thierry
>
> > Thanks again for your help.  I downloaded tcpmon and made the
> > suggested changes to my Java client.  I then did a post through Java
> > and below are the Request and the Response.
> >
> > Request
> > POST /commitments/ HTTP/1.1
> > Date: Wed, 15 Feb 2012 22:19:58 GMT
> > Content-Length: 109
> > Content-Type: application/json; charset=UTF-8
> > Accept: */*
> > Host: localhost:8880
> > User-Agent: Restlet-Framework/2.1rc2
> > Cache-Control: no-cache
> > Pragma: no-cache
> > Connection: keep-alive
> >
> > {"id":0,"title":"Added through post - Java client","description":"This
> > is a description of post Java client"}
> >
> > Response...
> > HTTP/1.1 200 OK
> > Content-Type: application/json; charset=UTF-8
> > Date: Wed, 15 Feb 2012 22:19:59 GMT
> > Accept-Ranges: bytes
> > Server: Restlet-Framework/2.1rc2
> > Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
> > Content-Length: 1
> >
> > 4
> >
> > Then I moved to the Javascript side.  I didn't install Firebug, but
> > instead I just changed the ClientResource creation from:
> >   var clientResource = new ClientResource("/commitments/");  /
> > To:
> >   var