org.restlet.routing.TemplateRoute Java Examples

The following examples show how to use org.restlet.routing.TemplateRoute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PolygeneRestApplication.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
protected void addResourcePath( String name,
                                Class<? extends HasIdentity> type,
                                String basePath,
                                boolean createLink,
                                boolean rootRoute
                              )
{
    if( createLink )
    {
        router.attach( basePath + name + "/create", newPolygeneRestlet( CreationResource.class, type ) );
    }
    TemplateRoute route = router.attach( basePath + name + "/", newPolygeneRestlet( EntityListResource.class, type ) );
    if( rootRoute )
    {
        route.setName( name );
    }
    router.attach( basePath + name + "/{id}/", newPolygeneRestlet( EntityResource.class, type ) );
    router.attach( basePath + name + "/{id}/{invoke}", newPolygeneRestlet( EntityResource.class, type ) );
}
 
Example #2
Source File: WorkspaceApplicationTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_attach_inbound_route_to_application() throws Exception {
    final Router inboundRoot = (Router) workspaceApplication.createInboundRoot();

    assertThat(inboundRoot).isNotNull();
    assertThat(inboundRoot.getRoutes()).hasSize(3);
    final TemplateRoute route1 = (TemplateRoute) inboundRoot.getRoutes().get(0);
    assertThat(route1.getTemplate().getPattern()).isEqualTo("/workspace/{filePath}/{action}");
    assertThat(((Finder) route1.getNext()).getTargetClass()).isEqualTo(WorkspaceServerResource.class);
    final TemplateRoute route2 = (TemplateRoute) inboundRoot.getRoutes().get(1);
    assertThat(route2.getTemplate().getPattern()).isEqualTo("/workspace/{action}");
    assertThat(((Finder) route2.getNext()).getTargetClass()).isEqualTo(WorkspaceServerResource.class);
    final TemplateRoute route3 = (TemplateRoute) inboundRoot.getRoutes().get(2);
    assertThat(route3.getTemplate().getPattern()).isEqualTo("/workspace/status/");
    assertThat(((Finder) route3.getNext()).getTargetClass()).isEqualTo(APIStatus.class);
}
 
Example #3
Source File: EntryPointResource.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private EntryPoint createEntryPoint()
        {
            Map<String, RestLink> entryPoints = new HashMap<>();
            for( Route r : parameters.router().get().getRoutes() )
            {
                if( r instanceof TemplateRoute)
                {
                    TemplateRoute route = (TemplateRoute) r;
                    Template template = route.getTemplate();
                    // Only include patterns that doesn't have variables, and has a proper name.
                    if( template.getVariableNames().isEmpty() && route.getName().indexOf( '>' ) == -1 )
                    {
                        Reference hostRef = parameters.request().get().getOriginalRef();
//                        Reference reference = new Reference( hostRef, template.getPattern() );
                        RestLink link;
                        if( route.getDescription() == null )
                        {
                            link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET );
                        }
                        else
                        {
                            link = resourceBuilder.createRestLink( template.getPattern(), hostRef, Method.GET, route.getDescription() );
                        }
                        entryPoints.put( route.getName(), link );
                    }
                }
            }
            ValueBuilder<EntryPoint> builder = vbf.newValueBuilder( EntryPoint.class );
            builder.prototype().identity().set( StringIdentity.identityOf( "/" ) );
            builder.prototype().api().set( entryPoints );
            return builder.newInstance();
        }
 
Example #4
Source File: APIInfoResource.java    From ontopia with Apache License 2.0 5 votes vote down vote up
private void list(Map<Restlet, String> all, Restlet restlet, String path) {
	all.put(restlet, path);
	if (restlet instanceof Router) {
		for (Route r : ((Router)restlet).getRoutes()) {
			list(all, r, path + ((TemplateRoute)r).getTemplate().getPattern());
		}
	} else if (restlet instanceof Filter) {
		list(all, ((Filter) restlet).getNext(), path);
	}
}
 
Example #5
Source File: WorkspaceResourceServerManagerTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_start_a_restlet_component_with_attached_application() throws Exception {
    final RouteList routes = defaultHost.getRoutes();
    assertThat(routes).hasSize(1);
    final TemplateRoute route = (TemplateRoute) routes.get(0);
    assertThat(route.getTemplate().getPattern()).isEqualTo("/api");
    assertThat(route.getNext()).isInstanceOf(WorkspaceApplication.class);
}
 
Example #6
Source File: APIInfoResource.java    From ontopia with Apache License 2.0 3 votes vote down vote up
private void describeRoutes(StringBuilder b, Router router, String path) {
	RouteList routes = router.getRoutes();
	
	b.append("[").append(path).append("] = Router: ").append(router.getName()).append(": ").append(router.getDescription()).append("\n");
	
	for (Route r : routes) {
		if (r instanceof TemplateRoute) {
			describe(b, r.getNext(), path + ((TemplateRoute)r).getTemplate().getPattern());
		}
		
	}
	
}