本文整理汇总了Java中org.restlet.resource.ServerResource类的典型用法代码示例。如果您正苦于以下问题:Java ServerResource类的具体用法?Java ServerResource怎么用?Java ServerResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerResource类属于org.restlet.resource包,在下文中一共展示了ServerResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTargetClass
import org.restlet.resource.ServerResource; //导入依赖的package包/类
public final Class<? extends ServerResource> getTargetClass() {
// If the key type is a subtype of ServerResource, return it.
Class<ServerResource> src = ServerResource.class;
if (src != null && targetClass != null
&& src.isAssignableFrom(targetClass)) {
@SuppressWarnings("unchecked")
Class<? extends ServerResource> result = (Class<? extends ServerResource>) targetClass;
return result;
}
// Otherwise, we can't in general determine the true target
// type, so we revert to the superclass implementation.
// Since we used the no-arg Finder constructor, it will return
// null unless someone has explicitly set a target class. This
// is only relevant to the use of the Router.detach(Class<?>
// targetClass) method; it implies that we cannot detach routes
// that target dependency-injected resources attached as
// non-ServerResource types without explicitly setting a target
// class type. This seems like a *very* minor restriction.
return super.getTargetClass();
}
示例2: wrapFinderWithMemberInjection
import org.restlet.resource.ServerResource; //导入依赖的package包/类
/**
* Wraps a {@link Finder} returned by {@link #createFinder(Class)} to do
* member injection using the passed in {@link MembersInjector}.
*
* @param finder
* The finder.
* @param membersInjector
* The instance of {@link MembersInjector}.
* @return A wrapped {@link Finder}.
*/
public static Finder wrapFinderWithMemberInjection(final Finder finder,
final SelfInjectingServerResource.MembersInjector membersInjector) {
return new Finder(finder.getContext(), finder.getTargetClass()) {
@Override
public ServerResource find(Request request, Response response) {
ServerResource res = finder.find(request, response);
if (res instanceof SelfInjectingServerResource) {
SelfInjectingServerResource tmp = (SelfInjectingServerResource) res;
tmp.ensureInjected(membersInjector);
} else {
membersInjector.injectMembers(res);
}
return res;
}
};
}
示例3: createInboundRoot
import org.restlet.resource.ServerResource; //导入依赖的package包/类
/**
* Binds all server resources to their corresponding URIs with the current
* application.
*/
@SuppressWarnings("unchecked")
@Override
public synchronized Restlet createInboundRoot() {
Context routerContext = getContext().createChildContext();
final Router appRouter = new Router(routerContext);
appRouter.attachDefault(BonjourService.class);
for (String resxURI : resx.keySet())
appRouter.attach(resxURI, (Class<ServerResource>) resx.get(resxURI));
// attachs bonjour service, which presents the API UI
appRouter.attach("", BonjourService.class);
appRouter.attach("/", BonjourService.class);
return appRouter;
}
示例4: attachRoutesForClass
import org.restlet.resource.ServerResource; //导入依赖的package包/类
private void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
TreeSet<String> pathsOrderedByLength = new TreeSet<String>(ComparatorUtils.chainedComparator(new Comparator<String>() {
private IntComparator _intComparator = IntComparators.NATURAL_COMPARATOR;
@Override
public int compare(String o1, String o2) {
return _intComparator.compare(o1.length(), o2.length());
}
}, ComparatorUtils.NATURAL_COMPARATOR));
for (Method method : clazz.getDeclaredMethods()) {
Annotation annotationInstance = method.getAnnotation(Paths.class);
if (annotationInstance != null) {
pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
}
}
for (String routePath : pathsOrderedByLength) {
LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
router.attach(routePath, new AddHeaderFilter(getContext(), createFinder(clazz)));
}
}
示例5: attachPath
import org.restlet.resource.ServerResource; //导入依赖的package包/类
private void attachPath(String path,
Class<? extends ServerResource> resourceClass, Role role) {
RoleAuthorizer ra = new RoleAuthorizer();
TemplateRoute route;
if (role != null) {
ra.getAuthorizedRoles().add(role);
ra.setNext(resourceClass);
route = attach(path, ra);
} else {
route = attach(path, resourceClass);
}
route.setMatchingMode(Template.MODE_STARTS_WITH);
// Allow the user variable to match any valid path characters.
// Needed because usernames from external sources may contain slashes.
Template template = route.getTemplate();
Map<String, Variable> variables = template.getVariables();
variables.put(UserResource.USERNAME_URI_ATTRIBUTE, new Variable(Variable.TYPE_URI_PATH));
template.setVariables(variables);
}
示例6: executeRequest
import org.restlet.resource.ServerResource; //导入依赖的package包/类
protected Response executeRequest(Request request, MediaType mediaType) {
List<Preference<MediaType>> accepts = request.getClientInfo().getAcceptedMediaTypes();
accepts.clear();
if (mediaType != null) {
accepts.add(new Preference<>(mediaType));
}
ServerResource resource = new ModuleResource();
Response response = new Response(request);
resource.init(null, request, response);
if (response.getStatus().isSuccess()) {
resource.handle();
}
return resource.getResponse();
}
示例7: setupApp
import org.restlet.resource.ServerResource; //导入依赖的package包/类
protected Application setupApp() throws Exception {
final MapTrackerMemory memory = new MapTrackerMemory();
memory.updateFile(new FileTrackingStatus(1L, 10L, "test1.txt",
FileTrackingStatus.STATUS.READY, 3, 4L, "testType1", new Date(), new Date()));
memory.updateFile(new FileTrackingStatus(1L, 10L, "test2.txt",
FileTrackingStatus.STATUS.READING, 3, 4L, "testType2", new Date(), new Date()));
memory.updateFile(new FileTrackingStatus(1L, 10L, "test3.txt",
FileTrackingStatus.STATUS.DONE, 3, 4L, "testType3", new Date(), new Date()));
this.memory = memory;
Finder finder = new Finder() {
@Override
public ServerResource find(Request request, Response response) {
return fileTrackingStatusResource(memory);
}
};
final Router router = new Router();
router.attach("/files/list", finder);
router.attach("/files/list/", finder);
router.attach("/files/list/{status}", finder);
return new Application() {
@Override
public Restlet createInboundRoot() {
return router;
}
};
}
示例8: setupApp
import org.restlet.resource.ServerResource; //导入依赖的package包/类
protected Application setupApp() throws Exception {
final MapTrackerMemory memory = new MapTrackerMemory();
memory.updateFile(new FileTrackingStatus(1L, 10L, new File("test1.txt")
.getAbsolutePath(), FileTrackingStatus.STATUS.READY, 3, 4L,
"testType1", new Date(), new Date()));
memory.updateFile(new FileTrackingStatus(1L, 10L, new File("test2.txt")
.getAbsolutePath(), FileTrackingStatus.STATUS.READING, 3, 4L,
"testType2", new Date(), new Date()));
memory.updateFile(new FileTrackingStatus(1L, 10L, new File("test3.txt")
.getAbsolutePath(), FileTrackingStatus.STATUS.DONE, 3, 4L,
"testType3", new Date(), new Date()));
this.memory = memory;
Finder finder = new Finder() {
@Override
public ServerResource find(Request request, Response response) {
return fileTrackingStatusPathResource(memory);
}
};
final Router router = new Router();
router.attach("/files/status", finder, Template.MODE_STARTS_WITH);
Application app = new Application() {
@Override
public Restlet createInboundRoot() {
return router;
}
};
return app;
}
示例9: attachFinder
import org.restlet.resource.ServerResource; //导入依赖的package包/类
/**
* Helper method to attch the server resource to the router.
*
* @param router
* @param pathTemplate
* @param resourceClass
* @param matchingMode
*/
private final void attachFinder(Router router, String pathTemplate,
final Class<? extends ServerResource> resourceClass,
int matchingMode) {
Finder finder = new Finder() {
@Override
public ServerResource find(Request request, Response response) {
return beanFactory.getBean(resourceClass);
}
};
router.attach(pathTemplate, finder, matchingMode);
}
示例10: createComponent
import org.restlet.resource.ServerResource; //导入依赖的package包/类
/**
* Creates a Component that will used this reasource to always return ok.
*
* @param port
* @return
*/
public static Component createComponent(int port) {
Finder finder = new Finder() {
@Override
public ServerResource find(Request request, Response response) {
return new AlwaysOKRestlet();
}
};
final Router router = new Router();
router.attach("/", finder, Template.MODE_STARTS_WITH);
Application app = new Application() {
@Override
public Restlet createInboundRoot() {
return router;
}
};
Component component = new Component();
component.getServers().add(org.restlet.data.Protocol.HTTP, port);
component.getDefaultHost().attach(app);
return component;
}
示例11: create
import org.restlet.resource.ServerResource; //导入依赖的package包/类
@Override
public ServerResource create(Request request, Response response) {
try {
return ServerResource.class.cast(getInjector().getInstance(
serverResourceKey));
} catch (ClassCastException ex) {
String msg = String.format(
"Must bind %s to ServerResource (or subclass)",
serverResourceKey);
throw new ProvisionException(msg, ex);
}
}
示例12: setUpAuth
import org.restlet.resource.ServerResource; //导入依赖的package包/类
private void setUpAuth(Router router,String path,String resourceKey,Class<? extends ServerResource> targetClass){
if(authpara == null ){
router.attach(path,targetClass);
return;
}
if((!authpara.isProtected(resourceKey))|| (!authpara.isEnabled())){
router.attach(path,targetClass);
return;
}
ChallengeAuthenticator auth = createAuthenticator();
auth.setNext(targetClass);
router.attach(path,auth);
logger.info("Resource "+router+" need to auth.");
}
示例13: find
import org.restlet.resource.ServerResource; //导入依赖的package包/类
public ServerResource find(Request request,Response response)
{
String path = packageName+request.getResourceRef().getRemainingPart();
if (path.endsWith("/")) {
path += indexName;
}
getLogger().info("resource: "+path);
ServerResource r = new ClassResource(classLoader,path);
r.setRequest(request);
r.setResponse(response);
return r;
}
示例14: find
import org.restlet.resource.ServerResource; //导入依赖的package包/类
public ServerResource find(Request request,Response response)
{
String path = packageName+request.getResourceRef().getRemainingPart();
ServerResource r = new ClassResource(baseClass,path);
r.setRequest(request);
r.setResponse(response);
return r;
}
示例15: create
import org.restlet.resource.ServerResource; //导入依赖的package包/类
/**
* Create an instance of the desired ServerResource, and inject dependencies.
*
* @param targetClass the desired class for the ServerResource
* @param request the current restlet request
* @param response the current restlet response
*/
@Override
public ServerResource create(Class<? extends ServerResource> targetClass,
Request request, Response response) {
ServerResource result = null;
if (targetClass != null) {
result = injector.getInstance(targetClass);
}
return result;
}