当前位置: 首页>>代码示例>>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;未经允许,请勿转载。