当前位置: 首页>>代码示例>>Java>>正文


Java ClientInfo.setAcceptedMediaTypes方法代码示例

本文整理汇总了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);
}
 
开发者ID:eSDK,项目名称:esdk_cloud_fc_cli,代码行数:29,代码来源:RestletClient.java

示例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);
}
 
开发者ID:Huawei,项目名称:eSDK_FC_SDK_Java,代码行数:38,代码来源:RestletClient.java

示例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);
}
 
开发者ID:eSDK,项目名称:esdk_cloud_fc_cli,代码行数:38,代码来源:RestletClient.java

示例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;
}
 
开发者ID:slipstream,项目名称:SlipStreamServer,代码行数:29,代码来源:TrimmedMediaTypesFilter.java


注:本文中的org.restlet.data.ClientInfo.setAcceptedMediaTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。