本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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 ) );
}
示例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;
}
示例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);
}
示例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();
}
示例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 );
}
示例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 ) );
}
示例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));
}
示例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)));
}
示例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;
}
示例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);
}
示例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);
}