最近工作需要restlet 这个框架,但是restlet文档奇少无比.碰到问题只要硬着头皮看restlet的原代码了
public class StaticResourceApplication extends Application {
/**
* Constructor.
*/
public StaticResourceApplication() {
// Sets the facultative name of the application.
setName("Static Resourc eApplication");
// the application requires the following client connector.
getConnectorService().getClientProtocols().add(Protocol.CLAP);
// getConnectorService().getServerProtocols().add(Protocol.CLAP);
}
@Override
public Restlet createRoot() {
// Instantiates the Directory with the path of the root directory
final Directory directory = new Directory(getContext(), LocalReference.createClapReference(LocalReference.CLAP_SYSTEM, "/"));
// Make sure the content negotiation is activated.
directory.setNegotiateContent(true);
return directory;
}
}
AutopubResource.setStorage(store);
System.out.println("Starting REST server on http://"
+ InetAddress.getLocalHost().getHostAddress() + ":" + PORT
+ "/");
component.getServers().add(Protocol.HTTP, PORT);
component.getDefaultHost().attach(new OpenAutopub());
component.getDefaultHost().attach("/resources",new StaticResourceApplication());
component.getClients().add(Protocol.CLAP);
component.start();