, , . -, , .
" " , Restlet - , , , - . : " XYZ 10 ". - , , , Restlet, REST, ( ) , , , . .
barebones, , . 127.0.0.1:12345/sample/time .
import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;
public class ServerMain extends Application {
public static void main(String...args) throws Exception {
final Component component = new Component();
component.getServers().add(Protocol.HTTP, 12345);
ServerMain server = new ServerMain(component.getContext().createChildContext());
component.getDefaultHost().attach(server);
component.start();
}
public ServerMain(Context context) {
super(context);
}
public Restlet createRoot() {
Router router = new Router(getContext().createChildContext());
router.attach("/sample/time", CurrentTimeResource.class);
return router;
}
}
" ", :
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
public class CurrentTimeResource extends ServerResource {
@Get
public Representation getTime() {
long now = System.currentTimeMillis();
String nowstr = String.valueOf(now);
Representation result = new StringRepresentation(nowstr);
return result;
}
}