我正在尝试提取网址查询参数但没有成功。
例如,AboutWebServices / merchantofferings?lat = 5?long = 7?cat = 9
使用Tomcat服务器,我尝试了Restlets的各种命令:
@Override
public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
Extractor extractor = new Extractor(getContext());
extractor.extractFromQuery("lat", "lat", true);
extractor.extractFromQuery("long", "long", false);
extractor.extractFromQuery("cat", "cat", false);
ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(),
ChallengeScheme.HTTP_BASIC,
"AnywhereAbout");
guard.setVerifier(new UserVerifer());
guard.setNext(extractor);
extractor.setNext(router);
// router.attach("/merchantofferings", extractor);
router.attach("/merchantofferings", MerchantOfferings.class);
router.attach("/merchantofferings/{id}", MerchantOfferings.class);
router.attach("/merchantprofile", MerchantProfile.class);
router.attach("/merchantprofile/{id}", MerchantProfile.class);
return guard;
}
路由适用于此方法但属性为null。
//@Get("json+?lat?long?cat")
@Get("json")
public String representGet() {
Context context = getContext();
String lat = (String) context.getAttributes().get("lat");
String lon = (String) context.getAttributes().get("long");
String cat = (String) context.getAttributes().get("cat");
return "hello, world: " + this.getRequest().toString();
}
此外,我一直在阅读新的Restlet in Action。很棒的书虽然它说你可以在注释中指定查询参数但它没有解释它们将如何使用,即没有例子。有人知道吗?在任何情况下,使用@Get(“json +?lat?long?cat”)的变体也不起作用。