當前位置: 首頁>>代碼示例>>Java>>正文


Java Request類代碼示例

本文整理匯總了Java中org.restlet.Request的典型用法代碼示例。如果您正苦於以下問題:Java Request類的具體用法?Java Request怎麽用?Java Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Request類屬於org.restlet包,在下文中一共展示了Request類的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;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:27,代碼來源:RestApiServer.java

示例2: authorize

import org.restlet.Request; //導入依賴的package包/類
@Override
protected boolean authorize(Request request, Response response) {
	if (request.getMethod() == Method.OPTIONS) return true;

	if (request.getAttributes().get("account") != null) return true;
	
	String accessToken = request.getHeaders().getFirstValue(HttpHeaders.AUTHORIZATION);
	if (accessToken == null) return true;
	
	try {
		accessToken.replace("OAuth ", "");
		AccountBean acc = mAccounts.getAccountFromToken(accessToken);
	    if (acc != null) {
	    	request.getAttributes().put("account", acc);
	    	return true;
	    }
	} catch (Exception e) {
		Main.LOGGER.log(Level.WARNING, "Error while handling OAuth authentification", e);
		return false;
	}
    
	return false;
}
 
開發者ID:FightForSub,項目名稱:FFS-Api,代碼行數:24,代碼來源:AuthAggregator.java

示例3: verify

import org.restlet.Request; //導入依賴的package包/類
@Override
public int verify(Request request, Response response) {
	if (request.getMethod() == Method.OPTIONS) return RESULT_VALID;

	if (request.getAttributes().get("account") != null) return RESULT_VALID;
	
	String accessToken = request.getHeaders().getFirstValue(HttpHeaders.AUTHORIZATION);
	if (accessToken == null) return RESULT_MISSING;
	
	try {
		accessToken.replace("OAuth ", "");
		AccountBean acc = mAccounts.getAccountFromToken(accessToken);
	    if (acc != null) {
	    	request.getAttributes().put("account", acc);
	    	return RESULT_VALID;
	    }
	} catch (Exception e) {
		Main.LOGGER.log(Level.WARNING, "Error while handling OAuth authentification", e);
		return RESULT_INVALID;
	}
    
	return RESULT_INVALID;
}
 
開發者ID:FightForSub,項目名稱:FFS-Api,代碼行數:24,代碼來源:OAuthVerifier.java

示例4: 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;
}
 
開發者ID:JianqingJiang,項目名稱:QoS-floodlight,代碼行數:27,代碼來源:RestApiServer.java

示例5: 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 ) );
}
 
開發者ID:tliron,項目名稱:prudence,代碼行數:18,代碼來源:ResolvingRedirector.java

示例6: getVariant

import org.restlet.Request; //導入依賴的package包/類
protected Variant getVariant( Request request,
                              List<Language> possibleLanguages,
                              List<MediaType> possibleMediaTypes
)
{
    Language language = request.getClientInfo().getPreferredLanguage( possibleLanguages );

    if( language == null )
    {
        language = possibleLanguages.get( 0 );
    }

    MediaType responseType = request.getClientInfo().getPreferredMediaType( possibleMediaTypes );

    if( responseType == null && request.getClientInfo()
                                    .getPreferredMediaType( Collections.singletonList( MediaType.ALL ) ) == MediaType.ALL )
    {
        responseType = possibleMediaTypes.get( 0 );
    }

    Variant variant = new Variant( responseType, language );
    variant.setCharacterSet( CharacterSet.UTF_8 );

    return variant;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:26,代碼來源:AbstractResponseWriter.java

示例7: list

import org.restlet.Request; //導入依賴的package包/類
@Override
public List<Car> list() {
    Client client = new Client(new Context(), Protocol.HTTPS);
    Series<Parameter> parameters = client.getContext().getParameters();
    parameters.add("truststorePath", System.getProperty("javax.net.ssl.trustStore"));

    ClientResource clientResource = new ClientResource("https://localhost:8043/api/cars/cars");
    clientResource.setNext(client);
    ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER);
    challenge.setRawValue(Request.getCurrent().getAttributes().getOrDefault("token", "").toString());
    clientResource.setChallengeResponse(challenge);
    CarServiceInterface carServiceInterface = clientResource.wrap(CarServiceInterface.class);
    Car[] allCars = carServiceInterface.getAllCars();
    try {
        client.stop();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return asList(allCars);
}
 
開發者ID:cdelmas,項目名稱:microservices-comparison,代碼行數:21,代碼來源:RemoteCarService.java

示例8: pullData

import org.restlet.Request; //導入依賴的package包/類
/**
 * Pull data from provided URL
 * @param url
 * @return output string or empty string
 */
private String pullData(String url) throws IOException {
    Client client = new Client(Protocol.HTTP);
    ClientResource cr = new ClientResource(url);
    Request req = cr.getRequest();

    // now header
    Series<Header> headerValue = new Series<Header>(Header.class);
    req.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, headerValue);
    headerValue.add("Accept", "application/json");
    headerValue.add("Content-Type", "application/json");

    // fire it up
    cr.get(MediaType.APPLICATION_JSON);
    Representation output = cr.getResponseEntity();

    // return null or received text
    return (output == null) ? "" : output.getText();
}
 
開發者ID:icclab,項目名稱:cyclops-rc,代碼行數:24,代碼來源:McnPuller.java

示例9: doInit

import org.restlet.Request; //導入依賴的package包/類
/**
 * Initializes the resource, and delegates to the <code>handleInit()</code>
 * entry point in the executable.
 */
@Override
protected void doInit() throws ResourceException
{
	super.doInit();
	setAnnotated( false );

	if( attributes.isSourceViewable() )
	{
		Request request = getRequest();
		Form query = request.getResourceRef().getQueryAsForm();
		if( TRUE.equals( query.getFirstValue( SOURCE ) ) )
			// Bypass doInit delegation
			return;
	}

	DelegatedResourceConversationService conversationService = new DelegatedResourceConversationService( this, null, null, attributes.getDefaultCharacterSet() );
	enter( attributes.getEntryPointNameForInit(), true, conversationService );
}
 
開發者ID:tliron,項目名稱:prudence,代碼行數:23,代碼來源:DelegatedResource.java

示例10: initialize

import org.restlet.Request; //導入依賴的package包/類
public void initialize( ExecutionContext executionContext ) throws ExecutionException
{
	Request request = Request.getCurrent();

	LazyInitializationGet exposedGet = new LazyInitializationGet( request );
	LazyInitializationFile exposedFile = new LazyInitializationFile( request, fileItemFactory );
	LazyInitializationPost exposedPost = new LazyInitializationPost( request, exposedFile );
	LazyInitializationCookie exposedCookie = new LazyInitializationCookie( request );
	LazyInitializationRequest exposedRequest = new LazyInitializationRequest( exposedGet, exposedPost, exposedCookie );

	// Note that our maps will only contain the last parameter in case of
	// duplicates. This is PHP's defined behavior.

	executionContext.getServices().put( "_GET", Collections.unmodifiableMap( exposedGet ) );
	executionContext.getServices().put( "_FILE", Collections.unmodifiableMap( exposedFile ) );
	executionContext.getServices().put( "_POST", Collections.unmodifiableMap( exposedPost ) );
	executionContext.getServices().put( "_COOKIE", Collections.unmodifiableMap( exposedCookie ) );
	executionContext.getServices().put( "_REQUEST", Collections.unmodifiableMap( exposedRequest ) );
}
 
開發者ID:tliron,項目名稱:prudence,代碼行數:20,代碼來源:PhpExecutionController.java

示例11: init

import org.restlet.Request; //導入依賴的package包/類
@Override
public void init(final Context context, final Request request, final Response response) {
    super.init(context, request, response);
    this.ticketGrantingTicketId = (String) request.getAttributes().get("ticketGrantingTicketId");
    this.setNegotiated(false);
    this.getVariants().add(new Variant(MediaType.APPLICATION_WWW_FORM));
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:8,代碼來源:TicketGrantingTicketResource.java

示例12: handle

import org.restlet.Request; //導入依賴的package包/類
@Override
public void handle(final Request req, final Response res)
{
    final String zoomStr = (String) req.getAttributes().get("zoom");
    final String xStr = (String) req.getAttributes().get("x");
    final String yStr = (String) req.getAttributes().get("y");
    
    final Path path = new Path(zoomStr, xStr, yStr, req.getResourceRef().getQueryAsForm().getFirstValue("path", true));
    final Params p = getTileParameters(path, req.getResourceRef().getQueryAsForm());
    res.setEntity(new PngOutputRepresentation(getTile(p)));
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:12,代碼來源:TileRestlet.java

示例13: requestRequiresAuthentication

import org.restlet.Request; //導入依賴的package包/類
@Override
public boolean requestRequiresAuthentication(Request request) {
    
    // Get relevant information from the request
    String userId = getUserId(request);
    String userId2 = getUserIdFromHeader(request);
    String password = getPassword(request);
    String apiCalled = getApiCalled(request);
    
    // Check if the user is authorized to perform the operation
    ensureUserIsAuthorized(apiCalled, userId);

    // If the BASIC authentication header is present and the user is the session user,
    // persist the user in the Activiti database
    if (userId2 != null && password != null && userId2.equals(userId)) {
        persistUser(userId, password);
    }
    
    // Set authenticated user id for this Activiti thread
    Authentication.setAuthenticatedUserId(userId);
    
    // Update request client info
    setRequestClientInfo(request, userId);
    
    // Return false to skip any Activiti-specific authentication
    return false;
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:28,代碼來源:CustomActivitiRestAuthenticator.java

示例14: setRequestClientInfo

import org.restlet.Request; //導入依賴的package包/類
private void setRequestClientInfo(Request request, String userId) {
    ClientInfo ci = request.getClientInfo();
    User user = new User();
    user.setIdentifier(userId);
    ci.setUser(user);
    request.setClientInfo(ci);
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:8,代碼來源:CustomActivitiRestAuthenticator.java

示例15: setDefaultHttpHeader

import org.restlet.Request; //導入依賴的package包/類
/**
 * 設置標準http header
 * 
 * @param request {@code void}
 * @since eSDK Cloud V100R003C50
 */
private void setDefaultHttpHeader(Request request, String version)
{
	ClientInfo clientInfo = new ClientInfo();

	List<Preference<MediaType>> acceptedMediaTypes = new ArrayList<Preference<MediaType>>();
	Preference<MediaType> preferenceMediaType = new Preference<MediaType>();

	String acceptStr = "application/json;";
	if (null == version)
	{
		acceptStr += "charset=UTF-8;";
	}
	else
	{
		acceptStr += version + "charset=UTF-8;";
	}
	MediaType mediaType = MediaType.register(acceptStr, "");
	preferenceMediaType.setMetadata(mediaType);
	acceptedMediaTypes.add(preferenceMediaType);
	clientInfo.setAcceptedMediaTypes(acceptedMediaTypes);

	List<Preference<Language>> acceptedLanguages = new ArrayList<Preference<Language>>();

	Preference<Language> preferenceLanguage = new Preference<Language>();
	Language language = new Language("zh_CN", "");
	preferenceLanguage.setMetadata(language);
	acceptedLanguages.add(preferenceLanguage);

	clientInfo.setAcceptedLanguages(acceptedLanguages);
	request.setClientInfo(clientInfo);
}
 
開發者ID:Huawei,項目名稱:eSDK_FC_SDK_Java,代碼行數:38,代碼來源:RestletClient.java


注:本文中的org.restlet.Request類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。