Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.peierls.example.restlet.formpost;
- import org.restlet.*;
- import org.restlet.data.*;
- import org.restlet.resource.*;
- import org.restlet.routing.*;
- /**
- * Demonstrates automatic conversion of entity to Form.
- * Test with something like:
- * <pre>
- * curl -v --data param=value1 --data otherparam=value2 localhost:8182/myresource
- * </pre>
- */
- public class Main {
- public static void main(String... args) throws Exception {
- Component comp = new Component();
- App app = new App();
- comp.getServers().add(Protocol.HTTP, 8182);
- comp.getDefaultHost().attachDefault(app);
- comp.start();
- }
- public static class App extends Application {
- @Override public Restlet createInboundRoot() {
- Router router = new Router(getContext());
- router.attach("/myresource", MyResource.class);
- return router;
- }
- }
- public static class MyResource extends ServerResource {
- @Post public String doPost(Form form) {
- return String.format(
- "received POST with param=%s and otherparam=%s",
- form.getFirstValue("param", ""),
- form.getFirstValue("otherparam", "")
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement