当前位置: 首页>>代码示例>>Java>>正文


Java ServerResource类代码示例

本文整理汇总了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();
            }
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:23,代码来源:RestletGuice.java

示例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;
        }
    };
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:27,代码来源:ResourceInjectingApplication.java

示例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;
}
 
开发者ID:jpinho,项目名称:soaba,代码行数:21,代码来源:RestletServer.java

示例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)));
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:22,代码来源:ControllerRestApplication.java

示例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);
}
 
开发者ID:slipstream,项目名称:SlipStreamServer,代码行数:21,代码来源:UserRouter.java

示例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();
	}
 
开发者ID:slipstream,项目名称:SlipStreamServer,代码行数:19,代码来源:ModuleResourceTest.java

示例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;
			}

		};

	}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:38,代码来源:TestFileTrackerStatusResource.java

示例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;
	}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:39,代码来源:TestFileTrackerStatusPathResource.java

示例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);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:24,代码来源:CollectorDI.java

示例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;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:36,代码来源:AlwaysOKRestlet.java

示例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);
    }
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:13,代码来源:RestletGuice.java

示例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.");
}
 
开发者ID:eternnoir,项目名称:MCRest,代码行数:15,代码来源:RestApplication.java

示例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;
}
 
开发者ID:alexmilowski,项目名称:xproclet,代码行数:13,代码来源:ClassResourceFinder.java

示例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;
}
 
开发者ID:alexmilowski,项目名称:xproclet,代码行数:9,代码来源:LoginApplication.java

示例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;
}
 
开发者ID:lathil,项目名称:Ptoceti,代码行数:19,代码来源:GuiceFinder.java


注:本文中的org.restlet.resource.ServerResource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。