While toying around with restlet I decided to test my restlets with curl.
It seems that if I send a 303 back to curl it correctly creates a new get request, restlet however seems to completely ignore it. unsure how to attach code, so will include here in case i fail to figure that out:
MyServer.java:
package com.obs.web;
import org.restlet.Component;
import org.restlet.data.Protocol;
public class MyServer {
public static void main(String[] args) throws Exception {
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getDefaultHost().attach("/products/{productId}", ProductResource.class);
component.getDefaultHost().attach("/products", ProductListResource.class);
component.start();
Thread.sleep(60000);
component.stop();
}
}
ProductResource.java:
package com.obs.web;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
public class ProductResource extends ServerResource {
@Get
public String doGet() {
return "productId:" + getRequestAttributes().get("productId");
}
}
ProductListResource.java:
package com.obs.web;
import org.restlet.representation.Representation;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
public class ProductListResource extends ServerResource {
@Post
public void doPost(Representation representation) {
redirectSeeOther("/products/98");
}
}
curl command line:
curl --trace-ascii trace.txt -L -X POST --data-urlencode a http://localhost:8182/products
contents of resulting trace.txt:
== Info: About to connect() to localhost port 8182 (#0)
== Info: Trying 127.0.0.1... == Info: connected
== Info: Connected to localhost (127.0.0.1) port 8182 (#0)
=> Send header, 244 bytes (0xf4)
0000: POST /products HTTP/1.1
0019: User-Agent: curl/7.21.6 (x86_64-pc-linux-gnu) libcurl/7.21.6 Ope
0059: nSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
008b: Host: localhost:8182
00a1: Accept: */*
00ae: Content-Length: 1
00c1: Content-Type: application/x-www-form-urlencoded
00f2:
=> Send data, 1 bytes (0x1)
0000: a
<= Recv header, 24 bytes (0x18)
0000: HTTP/1.1 303 See Other
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 26 Sep 2012 22:00:56 GMT
<= Recv header, 45 bytes (0x2d)
0000: Location: http://localhost:8182/products/98
<= Recv header, 33 bytes (0x21)
0000: Server: Restlet-Framework/2.1m3
<= Recv header, 19 bytes (0x13)
0000: Content-Length: 0
<= Recv header, 2 bytes (0x2)
0000:
== Info: Connection #0 to host localhost left intact
== Info: Issue another request to this URL: 'http://localhost:8182/products/98'
== Info: Disables POST, goes with GET
== Info: Re-using existing connection! (#0) with host localhost
== Info: Connected to localhost (127.0.0.1) port 8182 (#0)
=> Send header, 179 bytes (0xb3)
0000: POST /products/98 HTTP/1.1
001c: User-Agent: curl/7.21.6 (x86_64-pc-linux-gnu) libcurl/7.21.6 Ope
005c: nSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
008e: Host: localhost:8182
00a4: Accept: */*
00b1:
== Info: Connection died, retrying a fresh connect
== Info: Closing connection #0
== Info: Issue another request to this URL: 'http://localhost:8182/products/98'
== Info: About to connect() to localhost port 8182 (#0)
== Info: Trying 127.0.0.1... == Info: connected
== Info: Connected to localhost (127.0.0.1) port 8182 (#0)
=> Send header, 179 bytes (0xb3)
0000: POST /products/98 HTTP/1.1
001c: User-Agent: curl/7.21.6 (x86_64-pc-linux-gnu) libcurl/7.21.6 Ope
005c: nSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
008e: Host: localhost:8182
00a4: Accept: */*
00b1:
<= Recv header, 33 bytes (0x21)
0000: HTTP/1.1 405 Method Not Allowed
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 26 Sep 2012 22:01:26 GMT
<= Recv header, 12 bytes (0xc)
0000: Allow: GET
<= Recv header, 33 bytes (0x21)
0000: Server: Restlet-Framework/2.1m3
<= Recv header, 21 bytes (0x15)
0000: Content-Length: 487
<= Recv header, 40 bytes (0x28)
0000: Content-Type: text/html; charset=UTF-8
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 487 bytes (0x1e7)
0000: <html>.<head>. <title>Status page</title>.</head>.<body style=
0040: "font-family: sans-serif;">.<p style="font-size: 1.2em;font-weig
0080: ht: bold;margin: 1em 0px;">Method Not Allowed</p>.<p>The method
00c0: specified in the request is not allowed for the resource identif
0100: ied by the request URI</p>.<p>You can get technical details <a h
0140: ref="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec1
0180: 0.4.6">here</a>.<br>.Please continue your visit at our <a href="
01c0: /">home page</a>..</p>.</body>.</html>.
== Info: Connection #0 to host localhost left intact
== Info: Closing connection #0
While toying around with restlet I decided to test my restlets with curl. It seems that if I send a 303 back to curl it correctly creates a new get request, restlet however seems to completely ignore it. unsure how to attach code, so will include here in case i fail to figure that out:
MyServer.java:
ProductResource.java:
ProductListResource.java:
curl command line:
contents of resulting trace.txt: