Java Code Examples for org.restlet.Request.getResourceRef()

The following are Jave code examples for showing how to use getResourceRef() of the org.restlet.Request class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: fresco_floodlight   File: RestApiServer.java   Source Code and License Vote up 7 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
Project: QoS-floodlight   File: RestApiServer.java   Source Code and License Vote up 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 3
Project: floodlight1.2-delay   File: RestApiServer.java   Source Code and License Vote up 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 4
Project: ACAMPController   File: RestApiServer.java   Source Code and License Vote up 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 5
Project: fast-failover-demo   File: RestApiServer.java   Source Code and License Vote up 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 6
Project: prudence   File: ResolvingRedirector.java   Source Code and License Vote up 6 votes
@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 ) );
}
 
Example 7
Project: floodlightLB   File: RestApiServer.java   Source Code and License Vote up 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 8
Project: DSC   File: RestApiServer.java   Source Code and License Vote up 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 9
Project: Multipath-Hedera-system-in-Floodlight-controller   File: RestApiServer.java   Source Code and License Vote up 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 10
Project: floodlight_with_topoguard   File: RestApiServer.java   Source Code and License Vote up 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 11
Project: floodlight   File: RestApiServer.java   Source Code and License Vote up 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 12
Project: iTAP-controller   File: RestApiServer.java   Source Code and License Vote up 5 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 13
Project: SDN-Multicast   File: RestApiServer.java   Source Code and License Vote up 5 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 14
Project: bigstreams   File: CoordinationFileTrackingResource.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 15
Project: bigstreams   File: CoordinationFileTrackingHistoryResource.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 16
Project: floodlight-hardware   File: RestApiServer.java   Source Code and License Vote up 5 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 17
Project: prudence   File: ConversationService.java   Source Code and License Vote up 5 votes
/**
 * 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;
}
 
Example 18
Project: prudence   File: UnifyMinifyFilter.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 19
Project: arscheduler   File: RestApiServer.java   Source Code and License Vote up 4 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 20
Project: polygene-java   File: ValueCompositeRequestWriter.java   Source Code and License Vote up 4 votes
@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;
}
 
Example 21
Project: prudence   File: CachingUtil.java   Source Code and License Vote up 4 votes
/**
 * 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 );
	}
}
 
Example 22
Project: prudence   File: ZussFilter.java   Source Code and License Vote up 4 votes
@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;
}
 
Example 23
Project: prudence   File: ForwardedFilter.java   Source Code and License Vote up 4 votes
@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;
}
 
Example 24
Project: prudence   File: ResolvingRedirector.java   Source Code and License Vote up 4 votes
@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 );
			}
		}
	}
}
 
Example 25
Project: prudence   File: LessFilter.java   Source Code and License Vote up 4 votes
@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;
}
 
Example 26
Project: bigstreams   File: CoordinationFileTrackingCountResource.java   Source Code and License Vote up 3 votes
@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);

}