package cj.proxy;


import org.restlet.ext.xml.DomRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;

/**
 * Resource which has only one representation.
 */
public class DefaultResource extends ServerResource {

    @Post("xml")
    public Representation acceptItem(Representation entity) {
		try {
			ProxyApplication proxyApplication = (ProxyApplication)getApplication();
			Util.printRepresentation("Request:", entity);

	        ClientResource itemsResource = new ClientResource(proxyApplication.getServerUri());
	        
		    Representation r = itemsResource.post(new DomRepresentation(entity));
		    if (itemsResource.getStatus().isSuccess()) {
	            //itemResource = new ClientResource(r.getLocationRef());
	        }
		   //Util.printRepresentation("Response:", r);

	    	return r;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
    }
}
