org.restlet.routing.Filter Java Examples
The following examples show how to use
org.restlet.routing.Filter.
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: RestApiServer.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public Restlet createInboundRoot() { Router baseRouter = new Router(context); baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH); for (RestletRoutable rr : restlets) { baseRouter.attach(rr.basePath(), rr.getRestlet(context)); } Filter slashFilter = new Filter() { @Override protected int beforeHandle(Request request, Response response) { Reference ref = request.getResourceRef(); String originalPath = ref.getPath(); if (originalPath.contains("//")) { String newPath = originalPath.replaceAll("/+", "/"); ref.setPath(newPath); } return Filter.CONTINUE; } }; slashFilter.setNext(baseRouter); return slashFilter; }
Example #2
Source File: PolygeneRestApplication.java From attic-polygene-java with Apache License 2.0 | 6 votes |
private Restlet createInterceptors( Filter guard ) { Filter inner = createInnerInterceptor(); if( inner != null ) { inner.setNext( router ); guard.setNext( inner ); // guard -> interceptor -> router } else { guard.setNext( router ); // guard -> router } inner = guard; // inner = guard Filter outer = createOuterInterceptor(); if( outer != null ) { outer.setNext( inner ); // outer -> inner return outer; } return inner; }
Example #3
Source File: ExtensionMediaTypeFilter.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override protected int beforeHandle( Request request, Response response ) { List<String> segments = request.getResourceRef().getSegments(); if( segments.get( segments.size() - 1 ).equals( "" ) ) { return Filter.CONTINUE; } String extensions = request.getResourceRef().getExtensions(); if( extensions != null ) { int idx = extensions.lastIndexOf( "." ); if( idx != -1 ) { extensions = extensions.substring( idx + 1 ); } MetadataService metadataService = getApplication().getMetadataService(); Metadata metadata = metadataService.getMetadata( extensions ); if( metadata != null && metadata instanceof MediaType ) { request.getClientInfo() .setAcceptedMediaTypes( Collections.singletonList( new Preference<MediaType>( (MediaType) metadata ) ) ); String path = request.getResourceRef().getPath(); path = path.substring( 0, path.length() - extensions.length() - 1 ); request.getResourceRef().setPath( path ); } } return Filter.CONTINUE; }
Example #4
Source File: ExtensionMediaTypeFilter.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override protected int beforeHandle( Request request, Response response ) { List<String> segments = request.getResourceRef().getSegments(); if (segments.get( segments.size()-1 ).equals("")) return Filter.CONTINUE; String extensions = request.getResourceRef().getExtensions(); if( extensions != null ) { int idx = extensions.lastIndexOf( "." ); if( idx != -1 ) { extensions = extensions.substring( idx + 1 ); } MetadataService metadataService = getApplication().getMetadataService(); Metadata metadata = metadataService.getMetadata( extensions ); if( metadata != null && metadata instanceof MediaType ) { request.getClientInfo() .setAcceptedMediaTypes( Collections.singletonList( new Preference<>( (MediaType) metadata ) ) ); String path = request.getResourceRef().getPath(); path = path.substring( 0, path.length() - extensions.length() - 1 ); request.getResourceRef().setPath( path ); } } return Filter.CONTINUE; }
Example #5
Source File: PolygeneRestApplication.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public Restlet createInboundRoot() { Context context = getContext(); Engine.getInstance().getRegisteredConverters().add( new PolygeneConverter( objectFactory ) ); if( polygeneApplication.mode() == Application.Mode.development ) { setDebugging( true ); } router = new Router( context ); addRoutes( router ); router.attach( basePath, newPolygeneRestlet( EntryPointResource.class, EntryPoint.class ) ); Verifier verifier = createVerifier(); Enroler enroler = createEnroler(); if( verifier == null && enroler == null ) { return createInterceptors(new Filter() { } ); } else { ChallengeAuthenticator guard = new ChallengeAuthenticator( context, ChallengeScheme.HTTP_BASIC, getName() + " Realm" ); if( verifier != null ) { guard.setVerifier( verifier ); } if( enroler != null ) { guard.setEnroler( enroler ); } return createInterceptors( guard ); } }
Example #6
Source File: APIInfoResource.java From ontopia with Apache License 2.0 | 5 votes |
private void describe(StringBuilder b, Restlet restlet, String path) { if (restlet instanceof Router) { describeRoutes(b, (Router) restlet, path); } else if (restlet instanceof Finder) { Finder f = (Finder) restlet; b.append(path).append(" = ").append(ClassUtils.collapsedName(f.getTargetClass())).append("\n"); } else if (restlet instanceof Filter) { describe(b, ((Filter)restlet).getNext(), path); } }
Example #7
Source File: APIInfoResource.java From ontopia with Apache License 2.0 | 5 votes |
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 #8
Source File: PolygeneRestApplication.java From attic-polygene-java with Apache License 2.0 | 4 votes |
protected Filter createOuterInterceptor() { return null; }
Example #9
Source File: PolygeneRestApplication.java From attic-polygene-java with Apache License 2.0 | 4 votes |
protected Filter createInnerInterceptor() { return null; }
Example #10
Source File: APIInfoResource.java From ontopia with Apache License 2.0 | 4 votes |
public boolean isFilter(Restlet restlet) { return restlet instanceof Filter; }