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

The following are Jave code examples for showing how to use setRootRef() 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: search   File: TestRestManager.java   Source Code and License Vote up 5 votes
@Test
public void testResolveResourceId () throws Exception {
  Request testRequest = new Request();
  Reference rootRef = new Reference("http://solr.apache.org/");
  testRequest.setRootRef(rootRef);

  Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de");
  testRequest.setResourceRef(resourceRef);

  String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
  assertEquals(resourceId, "/schema/analysis/synonyms/de");
}
 
Example 2
Project: search   File: TestRestManager.java   Source Code and License Vote up 5 votes
@Test
public void testResolveResourceIdDecodeUrlEntities () throws Exception {
  Request testRequest = new Request();
  Reference rootRef = new Reference("http://solr.apache.org/");
  testRequest.setRootRef(rootRef);

  Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de/%C3%84ndern");
  testRequest.setResourceRef(resourceRef);

  String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
  assertEquals(resourceId, "/schema/analysis/synonyms/de/Ă„ndern");
}
 
Example 3
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;
}