本文整理汇总了Java中org.restlet.Request.getResourceRef方法的典型用法代码示例。如果您正苦于以下问题:Java Request.getResourceRef方法的具体用法?Java Request.getResourceRef怎么用?Java Request.getResourceRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.Request
的用法示例。
在下文中一共展示了Request.getResourceRef方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInboundRoot
import org.restlet.Request; //导入方法依赖的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.Request; //导入方法依赖的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: getTargetRef
import org.restlet.Request; //导入方法依赖的package包/类
@Override
protected Reference getTargetRef( Request request, Response response )
{
// This is essentially the original Restlet code modified to use
// ResolvingTemplate.
// Create the template
Template rt = new ResolvingTemplate( this.targetTemplate );
rt.setLogger( getLogger() );
// Return the formatted target URI
if( new Reference( this.targetTemplate ).isRelative() )
// Be sure to keep the resource's base reference.
return new Reference( request.getResourceRef(), rt.format( request, response ) );
return new Reference( rt.format( request, response ) );
}
示例4: getFileTrackingStatusList
import org.restlet.Request; //导入方法依赖的package包/类
@Get("json")
public Collection<FileTrackingStatus> getFileTrackingStatusList() {
List<Range> ranges = getRanges();
Request request = super.getRequest();
Reference resource = request.getResourceRef();
String query = resource.getQueryAsForm().getFirstValue("query");
int from = 0, max = 1000;
if (ranges != null && ranges.size() > 0) {
Range range = ranges.get(0);
from = (int) range.getIndex();
max = (int) range.getSize();
}
Collection<FileTrackingStatus> coll = (query == null) ? fileTrackerMemory
.getFiles(from, max) : fileTrackerMemory.getFilesByQuery(query,
from, max);
//sort by file date
List<FileTrackingStatus> list = null;
if(coll instanceof List){
list = (List<FileTrackingStatus>)coll;
}else{
list = new ArrayList<FileTrackingStatus>(coll);
}
Collections.sort(list, FileDateComparator.INSTANCE);
return coll;
}
示例5: getAgentHistory
import org.restlet.Request; //导入方法依赖的package包/类
@Get("json")
public Collection<FileTrackerHistoryItem> getAgentHistory() {
List<Range> ranges = getRanges();
Request request = super.getRequest();
Reference resource = request.getResourceRef();
Form form = resource.getQueryAsForm();
String agentName = form.getFirstValue("agent");
if (agentName == null) {
agentName = (String) getRequestAttributes().get("agent");
}
Collection<FileTrackerHistoryItem> coll = null;
if (agentName != null) {
int from = 0, max = 1000;
if (ranges != null && ranges.size() > 0) {
Range range = ranges.get(0);
from = (int) range.getIndex();
max = (int) range.getSize();
}
coll = fileTrackerMemory.getAgentHistory(agentName, from, max);
}
if (coll == null) {
coll = new ArrayList<FileTrackerHistoryItem>();
}
return coll;
}
示例6: createInboundRoot
import org.restlet.Request; //导入方法依赖的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;
}
示例7: getReference
import org.restlet.Request; //导入方法依赖的package包/类
/**
* The resource reference.
*
* @return The reference
*/
public Reference getReference()
{
if( reference == null )
{
Request request = getRequest();
reference = CapturingRedirector.getCapturedReference( request );
if( reference == null )
reference = request.getResourceRef();
}
return reference;
}
示例8: beforeHandle
import org.restlet.Request; //导入方法依赖的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;
}
示例9: writeRequest
import org.restlet.Request; //导入方法依赖的package包/类
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
if (requestObject instanceof ValueComposite)
{
// Value as parameter
final ValueComposite valueObject = (ValueComposite) requestObject;
if (request.getMethod().equals(Method.GET))
{
StateHolder holder = spi.stateOf( valueObject );
final ValueDescriptor descriptor = spi.valueDescriptorFor( valueObject );
final Reference ref = request.getResourceRef();
ref.setQuery( null );
descriptor.state().properties().forEach( propertyDescriptor -> {
try
{
Object value = holder.propertyFor( propertyDescriptor.accessor() ).get();
String param;
if( value == null )
{
param = null;
}
else
{
param = serializer.serialize( value );
}
ref.addQueryParameter( propertyDescriptor.qualifiedName().name(), param );
}
catch( SerializationException e )
{
throw new ResourceException( e );
}
} );
}
else
{
request.setEntity(new WriterRepresentation( MediaType.APPLICATION_JSON )
{
@Override
public void write( Writer writer )
throws IOException
{
setCharacterSet( CharacterSet.UTF_8 );
serializer.serialize( writer, valueObject );
}
});
}
return true;
}
return false;
}
示例10: castKey
import org.restlet.Request; //导入方法依赖的package包/类
/**
* Casts the cache key template for an executable.
*
* @param documentDescriptor
* The document descriptor
* @param suffix
* The optional attribute suffix
* @param parserName
* The parser to use, or null for the default parser
* @param conversationService
* The conversation service
* @param encoding
* The encoding
* @return The cache key or null
*/
public String castKey( DocumentDescriptor<Executable> documentDescriptor, String suffix, String parserName, ResourceConversationServiceBase<R> conversationService, Encoding encoding )
{
Executable executable = documentDescriptor.getDocument();
String cacheKeyTemplate = getKeyTemplate( executable, suffix );
if( cacheKeyTemplate == null )
return null;
Request request = resource.getRequest();
Response response = resource.getResponse();
if( !ProgramParser.NAME.equals( parserName ) )
{
// Set initial media type according to the document's tag (might
// be used by resolver)
if( conversationService.getMediaType() == null )
conversationService.setMediaTypeExtension( documentDescriptor.getTag() );
}
// Template and its resolver
Template template = new Template( cacheKeyTemplate );
CachingKeyTemplateResolver<R> resolver = new CachingKeyTemplateResolver<R>( documentDescriptor, resource, conversationService, encoding, request, response );
// Cache key template plugins
callKeyTemplatePlugins( template, executable, suffix );
Reference captiveReference = CapturingRedirector.getCapturedReference( request );
Reference resourceReference = request.getResourceRef();
try
{
// Temporarily use captive reference as the resource reference
if( captiveReference != null )
request.setResourceRef( captiveReference );
// Cast it
return template.format( resolver );
}
finally
{
// Return to original reference
if( captiveReference != null )
request.setResourceRef( resourceReference );
}
}
示例11: beforeHandle
import org.restlet.Request; //导入方法依赖的package包/类
@Override
protected int beforeHandle( Request request, Response response )
{
Reference reference = request.getResourceRef();
String path = reference.getRemainingPart( true, false );
try
{
// String name = reference.getLastSegment( true, false );
String zussPath = null;
boolean minify = false;
if( path.endsWith( CSS_MIN_EXTENSION ) )
{
zussPath = path.substring( 0, path.length() - CSS_MIN_EXTENSION_LENGTH ) + ZUSS_EXTENSION;
minify = true;
}
else if( path.endsWith( CSS_EXTENSION ) )
zussPath = path.substring( 0, path.length() - CSS_EXTENSION_LENGTH ) + ZUSS_EXTENSION;
if( zussPath != null )
{
long now = System.currentTimeMillis();
AtomicLong lastValidityCheckAtomic = getLastValidityCheck( path );
long lastValidityCheck = lastValidityCheckAtomic.get();
if( lastValidityCheck == 0 || ( now - lastValidityCheck > minimumTimeBetweenValidityChecks ) )
{
if( lastValidityCheckAtomic.compareAndSet( lastValidityCheck, now ) )
{
for( File sourceDirectory : sourceDirectories )
{
File zussFile = new File( sourceDirectory, zussPath );
if( zussFile.exists() )
{
File cssFile = new File( targetDirectory, path );
translate( zussFile, cssFile, minify );
break;
}
}
// ZUSS file was not found, so don't keep the entry for
// it
this.lastValidityChecks.remove( path );
}
}
}
}
catch( IOException x )
{
response.setStatus( Status.SERVER_ERROR_INTERNAL, x );
return Filter.STOP;
}
return Filter.CONTINUE;
}
示例12: beforeHandle
import org.restlet.Request; //导入方法依赖的package包/类
@Override
protected int beforeHandle( Request request, Response response )
{
if( !isApplying() )
return CONTINUE;
String forwardedScheme = request.getHeaders().getFirstValue( X_FORWARDED_PROTO_HEADER );
String forwardedDomain = request.getHeaders().getFirstValue( X_FORWARDED_HOST_HEADER );
String forwardedPortString = request.getHeaders().getFirstValue( X_FORWARDED_PORT_HEADER );
if( ( forwardedScheme != null ) || ( forwardedDomain != null ) || ( forwardedPortString != null ) )
{
int forwardedPort = -1;
if( forwardedDomain != null )
{
int colon = forwardedDomain.indexOf( ':' );
if( colon != -1 )
{
// Parse host:port
try
{
forwardedPort = Integer.parseInt( forwardedDomain.substring( 0, colon ) );
}
catch( NumberFormatException x )
{
// Invalid
}
forwardedDomain = forwardedDomain.substring( 0, colon );
}
}
if( forwardedPortString != null )
// Note: will override port in X-Forwarded-Host
forwardedPort = Integer.parseInt( forwardedPortString );
Reference reference;
reference = request.getResourceRef();
if( reference != null )
{
apply( reference, forwardedScheme, forwardedDomain, forwardedPort );
request.setResourceRef( reference );
}
reference = request.getRootRef();
if( reference != null )
{
apply( reference, forwardedScheme, forwardedDomain, forwardedPort );
request.setRootRef( reference );
}
reference = request.getOriginalRef();
if( reference != null )
{
apply( reference, forwardedScheme, forwardedDomain, forwardedPort );
request.setOriginalRef( reference );
}
}
return CONTINUE;
}
示例13: serverRedirect
import org.restlet.Request; //导入方法依赖的package包/类
@Override
protected void serverRedirect( Restlet next, Reference targetRef, Request request, Response response )
{
validateNotRecursiveServerRedirect( targetRef, request, response );
// This is essentially the original Restlet code modified to use
// ResolvingTemplate.
if( next == null )
getLogger().warning( "No next Restlet provided for server redirection to " + targetRef );
else
{
// Save the base URI if it exists as we might need it for
// redirections
Reference resourceRef = request.getResourceRef();
Reference baseRef = resourceRef.getBaseRef();
// Reset the protocol and let the dispatcher handle the protocol
request.setProtocol( null );
// Update the request to cleanly go to the target URI
request.setResourceRef( targetRef );
rewrite( request );
next.handle( request, response );
// Allow for response rewriting and clean the headers
response.setEntity( rewrite( response.getEntity() ) );
rewrite( response );
request.setResourceRef( resourceRef );
// In case of redirection, we may have to rewrite the redirect URI
if( response.getLocationRef() != null )
{
Template rt = new ResolvingTemplate( this.targetTemplate );
rt.setLogger( getLogger() );
int matched = rt.parse( response.getLocationRef().toString(), request );
if( matched > 0 )
{
String remainingPart = (String) request.getAttributes().get( "rr" );
if( remainingPart != null )
response.setLocationRef( baseRef.toString() + remainingPart );
}
}
}
}
示例14: beforeHandle
import org.restlet.Request; //导入方法依赖的package包/类
@Override
protected int beforeHandle( Request request, Response response )
{
Reference reference = request.getResourceRef();
String path = reference.getRemainingPart( true, false );
try
{
// String name = reference.getLastSegment( true, false );
String lessPath = null;
boolean minify = false;
if( path.endsWith( CSS_MIN_EXTENSION ) )
{
lessPath = path.substring( 0, path.length() - CSS_MIN_EXTENSION_LENGTH ) + LESS_EXTENSION;
minify = true;
}
else if( path.endsWith( CSS_EXTENSION ) )
lessPath = path.substring( 0, path.length() - CSS_EXTENSION_LENGTH ) + LESS_EXTENSION;
if( lessPath != null )
{
long now = System.currentTimeMillis();
AtomicLong lastValidityCheckAtomic = getLastValidityCheck( path );
long lastValidityCheck = lastValidityCheckAtomic.get();
if( lastValidityCheck == 0 || ( now - lastValidityCheck > minimumTimeBetweenValidityChecks ) )
{
if( lastValidityCheckAtomic.compareAndSet( lastValidityCheck, now ) )
{
for( File sourceDirectory : sourceDirectories )
{
File lessFile = new File( sourceDirectory, lessPath );
if( lessFile.exists() )
{
File cssFile = new File( targetDirectory, path );
translate( lessFile, cssFile, minify );
break;
}
}
// LESS file was not found, so don't keep the entry for
// it
this.lastValidityChecks.remove( path );
}
}
}
}
catch( IOException x )
{
response.setStatus( Status.SERVER_ERROR_INTERNAL, x );
return Filter.STOP;
}
return Filter.CONTINUE;
}
示例15: getFileTrackingStatusCount
import org.restlet.Request; //导入方法依赖的package包/类
@Get("json")
public long getFileTrackingStatusCount() {
Request request = super.getRequest();
Reference resource = request.getResourceRef();
String query = resource.getQueryAsForm().getFirstValue("query");
return (query == null) ? fileTrackerMemory.getFileCount()
: fileTrackerMemory.getFileCountByQuery(query);
}