Restlet学习:Restlet framework中API层与实现层的分层处理方式

Restlet框架由API层和实现层组成。API层提供REST概念的支持并简化客户端和服务端应用调用处理。实现层如Noelios Restlet Engine(NRE),与API层分离,允许多种实现。使用时需将实现层jar包加入classpath。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Restlet framework is composed of two main parts. First, there is the "Restlet API", a neutral API supporting the concepts of REST and facilitating the handling of calls for both client-side and server-side applications. This API must be supported by a Restlet implementation before it can effectively be used. Multiple implementations could be provided (open source projects or commercial products).
Restlet framework分为两个部分,API层和实现层。API层相当于规范,实现层可以有多种实现。要使用Restlet framework,必须在classpath中包含实现的jar包。Restlet framework提供了默认的实现。

层次结构图:
[img]http://www.restlet.org/documentation/1.1/images/tutorial01[/img]

This separation between the API and the implementation is similar to the one between the Servlet API and Web containers like Jetty or Tomcat, or between the JDBC API and concrete JDBC drivers. Currently, the "Noelios Restlet Engine" (NRE) is available and acts as the reference implementation. When you download the Restlet distribution, the API and the NRE come bundled together, ready to be used. If you need to use a different implementation just add the implementation JAR file to the classpath and remove the NRE JAR file named com.noelios.restlet.jar.
API层和实现层的关系如Servlet API和Web Container,JDBC API和JDBC drivers。如果要使用自己的实现层,可以在classpath中去掉NRE的jar包com.noelios.restlet.jar。

The registration is done automatically. See the JAR specification for details. When an implementation is loaded, it automatically calls back the org.restlet.util.Engine.setInstance() method.
实现层是自动注册的,只需要把jar放到classpath即可。部分源代码如下:

//实现层jar的META-INF
com.noelios.restlet.jar\META-INF\services\org.restlet.util.Engine:
com.noelios.restlet.Engine # The Noelios Restlet Engine

//实现层的Engine类,继承自API层的Engine类
public class Engine extends org.restlet.util.Engine {...}

//API层的Engine类
public abstract class Engine {
...

private static final String providerResource = "META-INF/services/org.restlet.util.Engine";

public static ClassLoader getClassLoader() {
ClassLoader result = getUserClassLoader();

if (result == null) {
result = Thread.currentThread().getContextClassLoader();
}

if (result == null) {
result = Class.class.getClassLoader();
}

if (result == null) {
result = ClassLoader.getSystemClassLoader();
}

return result;
}

//从classpath中读取实现层的Engine类实例
public static Engine getInstance() {
...

// Try the default classloader
ClassLoader cl = getClassLoader();
URL configURL = cl.getResource(providerResource);

if (configURL == null) {
// Try the current thread's classloader
cl = Thread.currentThread().getContextClassLoader();
configURL = cl.getResource(providerResource);
}

if (configURL == null) {
// Try the system classloader
cl = ClassLoader.getSystemClassLoader();
configURL = cl.getResource(providerResource);
}

...
engineClassName = providerName.substring(0,
providerName.indexOf('#')).trim();
instance = (Engine) Engine.loadClass(engineClassName)
.newInstance();
...
}

参考:
http://www.restlet.org/documentation/1.1/tutorial
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值