本文整理汇总了Java中org.restlet.data.ClientInfo.setAcceptedMediaTypes方法的典型用法代码示例。如果您正苦于以下问题:Java ClientInfo.setAcceptedMediaTypes方法的具体用法?Java ClientInfo.setAcceptedMediaTypes怎么用?Java ClientInfo.setAcceptedMediaTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.data.ClientInfo
的用法示例。
在下文中一共展示了ClientInfo.setAcceptedMediaTypes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例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: 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;
}