本文整理汇总了Java中org.restlet.data.ClientInfo类的典型用法代码示例。如果您正苦于以下问题:Java ClientInfo类的具体用法?Java ClientInfo怎么用?Java ClientInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientInfo类属于org.restlet.data包,在下文中一共展示了ClientInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDefaultHttpHeader
import org.restlet.data.ClientInfo; //导入依赖的package包/类
/**
*
* 设置标准http header
* @param request {@code void}
* @since eSDK Cloud V100R003C50
*/
private void setDefaultHttpHeader(Request request)
{
ClientInfo clientInfo = new ClientInfo();
List<Preference<MediaType>> acceptedMediaTypes = new ArrayList<Preference<MediaType>>();
Preference<MediaType> preferenceMediaType = new Preference<MediaType>();
MediaType mediaType = MediaType.register("application/json;version=1.2;charset=UTF-8;", "");
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);
}
示例2: setRequestClientInfo
import org.restlet.data.ClientInfo; //导入依赖的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);
}
示例3: setDefaultHttpHeader
import org.restlet.data.ClientInfo; //导入依赖的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);
}
示例4: callAccessTokenServerResource
import org.restlet.data.ClientInfo; //导入依赖的package包/类
/**
* 認可コードを渡してアクセストークンを取得する.
*
* @param client クライアント
* @param authCode 認可コード(TokenManager.sessionsに存在するキー値を設定する)
* @param applicationName アプリケーション名
* @return not null: アクセストークン / null: アクセストークン取得失敗
*/
private static String callAccessTokenServerResource(final Client client, final String authCode,
final String applicationName) {
Request request = new Request();
ClientInfo clientInfo = new ClientInfo();
org.restlet.security.User user = new org.restlet.security.User(client.getClientId());
clientInfo.setUser(user);
request.setClientInfo(clientInfo);
Response response = new Response(request);
AccessTokenServerResource.init(request, response);
// 入力値(アプリケーション名はbase64エンコードする)
String base64ApplicationName = Base64.encodeToString(applicationName.getBytes(), Base64.URL_SAFE|Base64.NO_WRAP);
StringRepresentation input = new StringRepresentation("grant_type=authorization_code&code=" + authCode + "&"
+ AccessTokenServerResource.REDIR_URI + "=" + DUMMY_REDIRECT_URI + "&"
+ AccessTokenServerResource.APPLICATION_NAME + "=" + base64ApplicationName);
try {
ResultRepresentation resultRepresentation = (ResultRepresentation) AccessTokenServerResource
.requestToken(input);
if (resultRepresentation.getResult()) {
return resultRepresentation.getText();
}
} catch (JSONException | OAuthException e) {
e.printStackTrace();
}
return null;
}
示例5: getClientInfo
import org.restlet.data.ClientInfo; //导入依赖的package包/类
/**
* Returns the client-specific information. Creates a new instance if no one
* has been set.
*
* @return The client-specific information.
*/
public ClientInfo getClientInfo() {
// Lazy initialization with double-check.
ClientInfo c = this.clientInfo;
if (c == null) {
synchronized (this) {
c = this.clientInfo;
if (c == null) {
this.clientInfo = c = new ClientInfo();
}
}
}
return c;
}
示例6: setDefaultHttpHeader
import org.restlet.data.ClientInfo; //导入依赖的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);
}
示例7: setXForwardedForHeader
import org.restlet.data.ClientInfo; //导入依赖的package包/类
public static void setXForwardedForHeader(ContextResource contextResource, HttpRequest req) throws GadgetException {
ClientInfo clientInfo = contextResource.getClientInfo();
List<String> forwardedAddresses = clientInfo.getForwardedAddresses();
String origValue = null;
if (!forwardedAddresses.isEmpty()) {
origValue = StringUtils.join(clientInfo.getForwardedAddresses(), ", ");
}
String forwardedFor = getXForwardedForHeader(origValue, clientInfo.getAddress());
if (forwardedFor != null) {
req.setHeader("X-Forwarded-For", forwardedFor);
}
}
示例8: optionsRequestHandler
import org.restlet.data.ClientInfo; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Options
public void optionsRequestHandler(){
ClientInfo c = getRequest().getClientInfo();
String origin = c.getAddress();
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series<Header>(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add(new Header("Access-Control-Allow-Origin", origin));
responseHeaders.add(new Header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE"));
}
示例9: enrole
import org.restlet.data.ClientInfo; //导入依赖的package包/类
public void enrole(ClientInfo clientInfo) {
User user = null;
try {
user = User.loadByNameNoParams(clientInfo.getUser().getIdentifier());
} catch (ConfigurationException e) {
Util.throwConfigurationException(e);
}
if (user != null && user.isSuper()) {
clientInfo.getRoles().add(Super);
}
}
示例10: beforeHandle
import org.restlet.data.ClientInfo; //导入依赖的package包/类
@Override
protected int beforeHandle(Request request, Response response) {
ClientInfo clientInfo = request.getClientInfo();
String agent = clientInfo.getAgent();
for (String browserName : affectedBrowserNames) {
if (agent != null && agent.contains(browserName)) {
List<Preference<MediaType>> preferences;
preferences = clientInfo.getAcceptedMediaTypes();
LinkedList<Preference<MediaType>> trimmedPreferences;
trimmedPreferences = new LinkedList<Preference<MediaType>>();
for (Preference<MediaType> preference : preferences) {
MediaType mediaType = preference.getMetadata();
if (MediaType.TEXT_HTML.equals(mediaType)
|| MediaType.APPLICATION_XHTML.equals(mediaType)) {
trimmedPreferences.add(preference);
clientInfo.setAcceptedMediaTypes(trimmedPreferences);
}
}
}
}
return CONTINUE;
}
示例11: getInfo
import org.restlet.data.ClientInfo; //导入依赖的package包/类
public ClientInfo getInfo()
{
return info;
}
示例12: OntopiaTestResource
import org.restlet.data.ClientInfo; //导入依赖的package包/类
public OntopiaTestResource(Method method, String url, MediaType preferredMime) {
super(method, url);
setNext(client);
setClientInfo(new ClientInfo(preferredMime));
}
示例13: AbstractLocator
import org.restlet.data.ClientInfo; //导入依赖的package包/类
/**
* Abstractor locator matches a video path to a specific video instance
* based on client parameters like device, resolution, etc
* Further more conditional access is applied, a valid ticket need to be
* supplied in order to play out.
*
* @param abstractPath
* @param queryForm
* @param clientInfo
*/
public AbstractLocator(String abstractPath, Form queryForm, ClientInfo clientInfo) {
this.abstractPath = abstractPath.endsWith("/") ? abstractPath.substring(0, abstractPath.length()-1) : abstractPath;
this.queryString = URLDecoder.decode(queryForm.getQueryString());
this.queryForm = queryForm;
this.clientInfo = clientInfo;
GlobalConfiguration conf = GlobalConfiguration.getInstance();
this.abstractPath = conf.getProperty("server-basepath") + this.abstractPath;
String ticket = queryForm.getFirstValue("ticket", true);
LOG.debug("ticket = "+ticket);
LOG.debug("abstract path = "+abstractPath);
if (ticket == null) {
//TODO: check with smithers if ticket is required for this video
status = Status.CLIENT_ERROR_FORBIDDEN;
return;
} else {
if (ticket.indexOf("?") > -1) {
ticket = ticket.substring(0, ticket.indexOf("?"));
LOG.debug("new ticket = "+ticket);
}
String wowzaUri = conf.getProperty("wowza-server-uri");
Request request = new Request(Method.GET, wowzaUri+"/acl/ticket/"+ticket);
Client client = new Client(Protocol.HTTP);
Response response = client.handle(request);
//TODO: add support for ip whitelisting instead of ticketing
try {
Document fsxml = DocumentHelper.parseText(response.getEntityAsText());
String uri = fsxml.selectSingleNode("//properties/uri") == null ? null : fsxml.selectSingleNode("//properties/uri").getText();
//String fsxmlStatus = fsxml.selectSingleNode("//properties/status") == null ? null : fsxml.selectSingleNode("//properties/status").getText();
String domainPath = abstractPath.indexOf("/domain/") == -1 ? abstractPath : abstractPath.substring(abstractPath.indexOf("/domain/"));
if (uri != null && uri.startsWith(domainPath)) {
status = Status.REDIRECTION_SEE_OTHER;
return;
}
status = Status.CLIENT_ERROR_FORBIDDEN;
request.release();
response.release();
return;
} catch (DocumentException e) {
status = Status.SERVER_ERROR_INTERNAL;
request.release();
response.release();
return;
}
}
}
示例14: getClientInfo
import org.restlet.data.ClientInfo; //导入依赖的package包/类
public ClientInfo getClientInfo() {
return this.request.getClientInfo();
}
示例15: setClientInfo
import org.restlet.data.ClientInfo; //导入依赖的package包/类
/**
* Sets the client-specific information.
*
* @param clientInfo
* The client-specific information.
*/
public void setClientInfo(ClientInfo clientInfo) {
this.clientInfo = clientInfo;
}