package cj.proxy;

import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.ext.xml.DomRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class SimpleServerMain extends ServerResource {
	public static void main(String[] args) throws Exception {
		new Server(Protocol.HTTP, 8182, SimpleServerMain.class).start();
	}
	
	@Post
	public Representation doPost(Representation representation) {
		try {
			Util.printRepresentation("Request:", representation);
	    	DomRepresentation xmlRep = new DomRepresentation();
	    	Document doc = xmlRep.getDocument();
	    	Element elem = doc.createElement("hello");
	    	doc.appendChild(elem);
	    	elem.appendChild(doc.createTextNode("world"));
	    	doc.normalizeDocument();
	    	return xmlRep;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
}
