本文整理汇总了Java中org.restlet.routing.Filter类的典型用法代码示例。如果您正苦于以下问题:Java Filter类的具体用法?Java Filter怎么用?Java Filter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Filter类属于org.restlet.routing包,在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInboundRoot
import org.restlet.routing.Filter; //导入依赖的package包/类
@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;
}
示例2: createInboundRoot
import org.restlet.routing.Filter; //导入依赖的package包/类
@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;
}
示例3: createInterceptors
import org.restlet.routing.Filter; //导入依赖的package包/类
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;
}
示例4: createInboundRoot
import org.restlet.routing.Filter; //导入依赖的package包/类
/**
* (non-Javadoc)
*
* @see org.restlet.ext.jaxrs.JaxRsApplication#createInboundRoot()
*/
@Override
public Restlet createInboundRoot() {
Restlet root = super.createInboundRoot();
if (this.getFilters() != null) {
Restlet next = root;
for (int index = this.getFilters().size() - 1; index >= 0; index--) {
Filter filter = this.getFilters().get(index);
filter.setNext(next);
next = filter;
}
return next;
} else {
return root;
}
}
示例5: createInboundRoot
import org.restlet.routing.Filter; //导入依赖的package包/类
@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;
}
示例6: ReportRouter
import org.restlet.routing.Filter; //导入依赖的package包/类
public ReportRouter(Context context, Application application) throws ConfigurationException, ValidationException {
super(context);
String reportsLocation = Configuration.getInstance().getProperty("slipstream.reports.location");
Authorizer authorizer = new ReportsAuthorizer();
Authenticator authenticator = new CookieAuthenticator(getContext());
authenticator.setOptional(false);
authenticator.setEnroler(new SuperEnroler(application));
authenticator.setNext(authorizer);
ResultsDirectory directory = new ResultsDirectory(getContext(), "file://" + reportsLocation);
Filter decorator = new ReportDecorator();
decorator.setNext(directory);
authorizer.setNext(decorator);
attach("", authenticator);
}
示例7: beforeHandle
import org.restlet.routing.Filter; //导入依赖的package包/类
/**
* Skip the call to the server resource if the {@link #skippingResourceForCorsOptions} is true and if the current
* request use the OPTIONS method and is a CORS request.
*
* @param request
* The request to handle.
* @param response
* The response to update.
*/
@Override
protected int beforeHandle(Request request, Response response) {
if (skippingResourceForCorsOptions
&& Method.OPTIONS.equals(request.getMethod())
&& getCorsResponseHelper().isCorsRequest(request)) {
response.setAllowedMethods(getDefaultAllowedMethods());
return Filter.SKIP;
} else {
return Filter.CONTINUE;
}
}
示例8: addInboundFilter
import org.restlet.routing.Filter; //导入依赖的package包/类
/**
* Adds a new inbound filter to the chain.
*
* @param filter
* The inbound filter to add.
*/
protected synchronized void addInboundFilter(Filter filter) {
Restlet next = getInboundNext();
if (getFirstInboundFilter() == null) {
setFirstInboundFilter(filter);
} else if (getLastInboundFilter() != null) {
getLastInboundFilter().setNext(filter);
}
setLastInboundFilter(filter);
setInboundNext(next);
}
示例9: addOutboundFilter
import org.restlet.routing.Filter; //导入依赖的package包/类
/**
* Adds a new outbound filter to the chain.
*
* @param filter
* The outbound filter to add.
*/
protected synchronized void addOutboundFilter(Filter filter) {
Restlet next = getOutboundNext();
if (getFirstOutboundFilter() == null) {
setFirstOutboundFilter(filter);
} else if (getLastOutboundFilter() != null) {
getLastOutboundFilter().setNext(filter);
}
setLastOutboundFilter(filter);
setOutboundNext(next);
}
示例10: createInboundFilter
import org.restlet.routing.Filter; //导入依赖的package包/类
@Override
public Filter createInboundFilter(Context context) {
return new CorsFilter().setAllowedCredentials(allowedCredentials)
.setAllowedOrigins(allowedOrigins)
.setAllowingAllRequestedHeaders(allowingAllRequestedHeaders)
.setAllowedHeaders(allowedHeaders)
.setExposedHeaders(exposedHeaders)
.setSkippingResourceForCorsOptions(skippingResourceForCorsOptions)
.setDefaultAllowedMethods(getDefaultAllowedMethods())
.setMaxAge(maxAge);
}
示例11: createInboundRoot
import org.restlet.routing.Filter; //导入依赖的package包/类
@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;
}
示例12: beforeHandle
import org.restlet.routing.Filter; //导入依赖的package包/类
@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;
}
示例13: beforeHandle
import org.restlet.routing.Filter; //导入依赖的package包/类
@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;
}
示例14: createInboundRoot
import org.restlet.routing.Filter; //导入依赖的package包/类
@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 );
}
}
示例15: beforeHandle
import org.restlet.routing.Filter; //导入依赖的package包/类
@Override
protected int beforeHandle( Request request, Response response )
{
Reference reference = request.getResourceRef();
String name = reference.getLastSegment( true, false );
try
{
boolean validate = false;
boolean minify = false;
if( name.equals( unifiedFilename ) )
validate = true;
else if( name.equals( unifiedMinifiedFilename ) )
{
validate = true;
minify = true;
}
if( validate )
{
long now = System.currentTimeMillis();
long lastValidityCheck = this.lastValidityCheck.get();
if( lastValidityCheck == 0 || ( now - lastValidityCheck > minimumTimeBetweenValidityChecks ) )
{
if( this.lastValidityCheck.compareAndSet( lastValidityCheck, now ) )
unify( targetDirectory, minify );
}
}
}
catch( IOException x )
{
response.setStatus( Status.SERVER_ERROR_INTERNAL, x );
return Filter.STOP;
}
return Filter.CONTINUE;
}