@Test(expected = RoutingException.class) public void testPut() throws RoutingException { Routes.load(ResourceUtil.getResourceAsFile("routes/via.xml")); System.out.println(Routes.getRouteSet().toString()); MockHttpServletRequest request = ((MockHttpServletRequest) RequestUtil.getRequest()); request.setMethod("PUT"); Routes.recognizePath("/methods/"); }
@Test public void testPost() { Routes.load(ResourceUtil.getResourceAsFile("routes/via.xml")); System.out.println(Routes.getRouteSet().toString()); MockHttpServletRequest request = ((MockHttpServletRequest) RequestUtil.getRequest()); request.setMethod("POST"); Options options = Routes.recognizePath("/methods/"); System.out.println(options); assertThat(options.getString("action"), is("getAndPost")); }
private void scanBindings() throws IOException { for (Map.Entry<Key<?>, Binding<?>> e : globalInjector.getAllBindings().entrySet()) { Key<?> bindingKey = e.getKey(); Binding<?> binding = e.getValue(); TypeLiteral boundTypeLiteral = bindingKey.getTypeLiteral(); Type boundType = boundTypeLiteral.getType(); if (boundType instanceof Class) { final Class boundClass = (Class) boundType; for (Method method : boundClass.getMethods()) { if ((method.getModifiers() & Modifier.STATIC) == 0) { for (Annotation annotation : method.getAnnotations()) { if (annotation instanceof Path) { Path pathSpec = (Path) annotation; RouteSpec routeIn = Routes.parse(pathSpec.value(), true); endPointMethods.add(new EndPointMethod(routeIn, bindingKey, boundClass, method)); } } } } if (MessageBodyReader.class.isAssignableFrom(boundClass)) { messageBodyReaders.add(0, (MessageBodyReader) globalInjector.getInstance(bindingKey)); } if (MessageBodyWriter.class.isAssignableFrom(boundClass)) { messageBodyWriters.add(0, (MessageBodyWriter) globalInjector.getInstance(bindingKey)); } } } }
/** * controller * * @param me */ @Override public void configRoute(Routes me) { // String path = this.getClass().getClassLoader().getResource("").getPath(); controlSscan(controlPackage); // 获取需要扫描的包 // 扫描器 Scan driven = new Scan(); for (String pake : controlPackage) { Set<Class<?>> clazzs = driven.getClasses(pake); /*System.out.println("pake: " + pake);*/ for (Class<?> clazz : clazzs) { // System.out.println(clazz.getSuperclass()); LOG.info(clazz.getName()); Class<?> superclass = clazz.getSuperclass(); Class<?> jfClz = com.jfinal.core.Controller.class; if (superclass == jfClz || superclass.getSuperclass() == jfClz) { C con = clazz.getAnnotation(C.class); if (null != con) { me.add(con.value(), (Class<? extends Controller>) clazz); } } } } }
@BeforeClass public static void setUpBeforeClass() throws Exception { routeDeclarations = new Routes(); ((Routes) routeDeclarations).defineRoutes(); routeMapping = routeDeclarations.createRouteMapping(new RouteDefaults()); resolver = new RouteResolver(routeMapping); }
private com.relteq.sirius.jaxb.Route restoreRoute(Routes db_route) throws TorqueException { com.relteq.sirius.jaxb.Route route = factory.createRoute(); route.setId(id2str(db_route.getId())); route.setName(db_route.getName()); com.relteq.sirius.jaxb.LinkReferences lrs = factory.createLinkReferences(); Criteria crit = new Criteria(); crit.addAscendingOrderByColumn(RouteLinksPeer.ORDINAL); @SuppressWarnings("unchecked") List<RouteLinks> db_rl_l = db_route.getRouteLinkss(crit); for (RouteLinks db_rl : db_rl_l) { com.relteq.sirius.jaxb.LinkReference lr = factory.createLinkReference(); lr.setId(id2str(db_rl.getLinkId())); lrs.getLinkReference().add(lr); } route.setLinkReferences(lrs); return route; }
public static Result javascriptRoutes() { response().setContentType("text/javascript"); return ok( Routes.javascriptRouter( "jsRoutes", // Routes for Projects controllers.routes.javascript.SoundProjects.add(), controllers.routes.javascript.SoundProjects.delete())); }
public static Result routeAndCall( Class<? extends Routes> router, FakeRequest fakeRequest, long timeout) { try { Routes routes = (Routes) router .getClassLoader() .loadClass(router.getName() + "$") .getDeclaredField("MODULE$") .get(null); if (routes.routes().isDefinedAt(fakeRequest.getWrappedRequest())) { return invokeHandler( routes.routes().apply(fakeRequest.getWrappedRequest()), fakeRequest, timeout); } else { return null; } } catch (RuntimeException e) { throw e; } catch (Throwable t) { throw new RuntimeException(t); } }
@Override public void configRoute(Routes me) { log.info("配置基本页面路由"); me.add("/", IndexController.class); me.add("/test", TestController.class); me.add("/user", UserController.class); me.add("/get", GetRecord.class); log.info("配置省级用户页面的路由"); me.add("/province/provincerecord", ProvinceRecordController.class); me.add("/province/sub", SubController.class); me.add("/province/pro", ProjectController.class); me.add("/province/tree", TreeController.class); me.add("/province/cityrecord", CityRecordController.class); me.add("/province/countyrecord", CountyRecordControll.class); me.add("/province/rfc", ProvinceRfcController.class); log.info("配置市级用户页面的路由"); me.add("/city/cityrecord", CityRecordControllerCity.class); me.add("/city/countyrecord", CountyControllerCity.class); log.info("配置县级用户页面的路由"); me.add("/county", CountyControllerCounty.class); }
public void get(String path, RouteHandler handler) { routes.add(GET, path, handler); }
public void process(HTTPMethod method, RouteRequest request, RouteResponse response) { Route route = routes.get(method, request.path); route.process(request, response); }
public void delete(String path, RouteHandler handler) { routes.add(DELETE, path, handler); }
public void put(String path, RouteHandler handler) { routes.add(PUT, path, handler); }
public void post(String path, RouteHandler handler) { routes.add(POST, path, handler); }
/** 配置路由 */ public void configRoute(Routes me) { me.add("/", IndexController.class).add("/topic", TopicController.class); me.add("/post", PostController.class).add("/reply", ReplyController.class); me.add("/admin/welcome", WelcomeController.class).add("/admin/module", ModuleController.class); }
/** * Set the specified route and headsign combination as a favorite, optionally for a specific * stop. Note that this will also handle the marking/unmarking of the designated route as the * favorite as well. The route is marked as not a favorite when no more routeId/headsign * combinations remain. If marking the route/headsign as favorite for all stops, then stopId * should be null. * * @param routeId routeId to be marked as favorite, in combination with headsign * @param headsign headsign to be marked as favorite, in combination with routeId * @param stopId stopId to be marked as a favorite, or null if all stopIds should be marked for * this routeId/headsign combo. * @param favorite true if this route and headsign combination should be marked as a favorite, * false if it should not */ public static void markAsFavorite( Context context, String routeId, String headsign, String stopId, boolean favorite) { if (context == null) { return; } ContentResolver cr = context.getContentResolver(); Uri routeUri = Uri.withAppendedPath(ObaContract.Routes.CONTENT_URI, routeId); String stopIdInternal; if (stopId != null) { stopIdInternal = stopId; } else { stopIdInternal = ALL_STOPS; } final String WHERE = ROUTE_ID + "=? AND " + HEADSIGN + "=? AND " + STOP_ID + "=?"; final String[] selectionArgs = {routeId, headsign, stopIdInternal}; if (favorite) { if (stopIdInternal != ALL_STOPS) { // First, delete any potential exclusion records for this stop by removing all records cr.delete(CONTENT_URI, WHERE, selectionArgs); } // Mark as favorite by inserting a record for this route/headsign combo ContentValues values = new ContentValues(); values.put(ROUTE_ID, routeId); values.put(HEADSIGN, headsign); values.put(STOP_ID, stopIdInternal); values.put(EXCLUDE, 0); cr.insert(CONTENT_URI, values); // Mark the route as a favorite also in the routes table Routes.markAsFavorite(context, routeUri, true); } else { // Deselect it as favorite by deleting all records for this route/headsign/stopId combo cr.delete(CONTENT_URI, WHERE, selectionArgs); if (stopIdInternal == ALL_STOPS) { // Also make sure we've deleted the single record for this specific stop, if it exists // We don't have the stopId here, so we can just delete all records for this // routeId/headsign final String[] selectionArgs2 = {routeId, headsign}; final String WHERE2 = ROUTE_ID + "=? AND " + HEADSIGN + "=?"; cr.delete(CONTENT_URI, WHERE2, selectionArgs2); } // If there are no more route/headsign combinations that are favorites for this route, // then mark the route as not a favorite if (!isFavorite(context, routeId)) { Routes.markAsFavorite(context, routeUri, false); } // If a single stop is unstarred, but isFavorite(...) == true due to starring all // stops, insert exclusion record if (stopIdInternal != ALL_STOPS && isFavorite(context, routeId, headsign, stopId)) { // Insert an exclusion record for this single stop, in case the user is unstarring it // after starring the entire route ContentValues values = new ContentValues(); values.put(ROUTE_ID, routeId); values.put(HEADSIGN, headsign); values.put(STOP_ID, stopIdInternal); values.put(EXCLUDE, 1); cr.insert(CONTENT_URI, values); } } StringBuilder analyicsLabel = new StringBuilder(); if (favorite) { analyicsLabel.append(context.getString(R.string.analytics_label_star_route)); } else { analyicsLabel.append(context.getString(R.string.analytics_label_unstar_route)); } analyicsLabel.append(" ").append(routeId).append("_").append(headsign).append(" for "); if (stopId != null) { analyicsLabel.append(stopId); } else { analyicsLabel.append("all stops"); } ObaAnalytics.reportEventWithCategory( ObaAnalytics.ObaEventCategory.UI_ACTION.toString(), context.getString(R.string.analytics_action_edit_field), analyicsLabel.toString()); }