本文整理汇总了Java中org.restlet.Request.setResourceRef方法的典型用法代码示例。如果您正苦于以下问题:Java Request.setResourceRef方法的具体用法?Java Request.setResourceRef怎么用?Java Request.setResourceRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.Request
的用法示例。
在下文中一共展示了Request.setResourceRef方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testResolveResourceId
import org.restlet.Request; //导入方法依赖的package包/类
@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");
}
示例2: testResolveResourceIdDecodeUrlEntities
import org.restlet.Request; //导入方法依赖的package包/类
@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");
}
示例3: callAuthorizationServerResource
import org.restlet.Request; //导入方法依赖的package包/类
/**
* AuthorizationServerResourceを実行.
*
* @param client クライアント情報
* @param initialize 初期化フラグ(trueにするとContextを初期化する)
* @param sessionId セッションID(引き継ぐセッションIDが存在すれば指定する、無ければnullを設定する)
* @return not null: RedirectRepresentation型の戻り値を返す / null: エラー
* @throws AuthorizationException Authorization例外.
*/
private static RedirectRepresentation callAuthorizationServerResource(final Client client,
final boolean initialize, final String sessionId) throws AuthorizationException {
// AuthorizationServerResourceを初期化する
if (initialize) {
Context context = new Context(sLogger);
AuthorizationServerResource.init(context);
}
// request, responseを初期化 *
Request request = new Request();
request.setOriginalRef(new Reference(DUMMY_ORIGINAL_REF));
Response response = new Response(request);
request.setResourceRef(new Reference(DUMMY_REFERENCE));
// セッションIDが指定されていたらRequestに設定する
if (sessionId != null) {
Series<Cookie> cookies = new Series<>(Cookie.class);
cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId);
request.setCookies(cookies);
}
AuthorizationServerResource.init(request, response, sClientManager, sTokenManager);
// Formに設定する
Form paramsA = new Form();
paramsA.add(AuthorizationServerResource.CLIENT_ID, client.getClientId());
paramsA.add(AuthorizationServerResource.REDIR_URI, DUMMY_REDIRECT_URI);
paramsA.add(AuthorizationServerResource.RESPONSE_TYPE, "code");
paramsA.add(AuthorizationServerResource.SCOPE, DUMMY_SCOPE1);
/// requestAuthorizationを実行する
Representation representationA;
try {
representationA = AuthorizationServerResource.requestAuthorization(paramsA);
} catch (OAuthException e) {
throw new AuthorizationException(e);
}
// 正常終了(ログイン画面リダイレクト)
if (representationA instanceof RedirectRepresentation) {
return (RedirectRepresentation) representationA;
}
return null;
}
示例4: callLoginPageServerResource
import org.restlet.Request; //导入方法依赖的package包/类
/**
* LoginPageServerResourceを実行する.
*
* @param userId ユーザーID
* @param password パスワード
* @return 戻り値(ResultRepresentation)
*/
private static ResultRepresentation callLoginPageServerResource(final String userId, final String password) {
// 前の処理からセッションIDを引き継ぐ
String sessionId = AuthorizationServerResource.getSessionId();
Series<Cookie> cookies = new Series<>(Cookie.class);
cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId);
// (B)の処理
LoginPageServerResource.initResult();
Request request = new Request();
Reference requestReference = new Reference(DUMMY_ORIGINAL_REF);
requestReference.addQueryParameter(LoginPageServerResource.USER_ID, userId);
requestReference.addQueryParameter(LoginPageServerResource.PASSWORD, password);
requestReference.addQueryParameter(LoginPageServerResource.CONTINUE,
RedirectRepresentation.RedirectProc.requestAuthorization.toString());
// QueryParameterとは別の変数に値を入れているので、直接値を設定する
ArrayList<String> userIds = new ArrayList<>();
userIds.add(userId);
ArrayList<String> passwords = new ArrayList<>();
passwords.add(password);
ArrayList<String> continues = new ArrayList<>();
continues.add(RedirectRepresentation.RedirectProc.requestAuthorization.toString());
LoginPageServerResource.getQuery().put(LoginPageServerResource.USER_ID, userIds);
LoginPageServerResource.getQuery().put(LoginPageServerResource.PASSWORD, passwords);
LoginPageServerResource.getQuery().put(LoginPageServerResource.CONTINUE, continues);
request.setCookies(cookies);
request.setOriginalRef(requestReference);
request.setResourceRef(requestReference);
Response response = new Response(request);
LoginPageServerResource.init(request, response);
ResultRepresentation resultRepresentation;
try {
resultRepresentation = (ResultRepresentation) LoginPageServerResource.getPage();
} catch (OAuthException e) {
resultRepresentation = new ResultRepresentation();
resultRepresentation.setResult(false);
resultRepresentation.setError(e.getMessage(), e.getErrorDescription());
}
return resultRepresentation;
}
示例5: 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 );
}
}
示例6: 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;
}
示例7: 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 );
}
}
}
}