當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。