本文整理汇总了Java中org.restlet.representation.StringRepresentation.setMediaType方法的典型用法代码示例。如果您正苦于以下问题:Java StringRepresentation.setMediaType方法的具体用法?Java StringRepresentation.setMediaType怎么用?Java StringRepresentation.setMediaType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.representation.StringRepresentation
的用法示例。
在下文中一共展示了StringRepresentation.setMediaType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: responseErrorRepresentation
import org.restlet.representation.StringRepresentation; //导入方法依赖的package包/类
/**
* Returns the representation of the given error. The format of the JSON
* document is according to 5.2. Error Response.
*
* @param ex
* Any OAuthException with error
* @return The representation of the given error.
*/
public static Representation responseErrorRepresentation(OAuthException ex) {
try {
return new JsonRepresentation(ex.createErrorDocument());
} catch (JSONException e) {
StringRepresentation r = new StringRepresentation(
"{\"error\":\"server_error\",\"error_description:\":\""
+ e.getLocalizedMessage() + "\"}");
r.setMediaType(MediaType.APPLICATION_JSON);
return r;
}
}
示例2: getRepresentation
import org.restlet.representation.StringRepresentation; //导入方法依赖的package包/类
@Override
public Representation getRepresentation(Status status, Request request, Response response) {
if (status.isError()) {
StringRepresentation ret = new StringRepresentation(status.getDescription());
ret.setMediaType(MediaType.TEXT_PLAIN);
return ret;
}
return super.toRepresentation(status, request, response);
}
示例3: toTxt
import org.restlet.representation.StringRepresentation; //导入方法依赖的package包/类
@Get("csv")
public Representation toTxt() {
String result = "firstname, lastname, email, organisation, activesince, lastonine, lastexecute\n";
for (UserView u : User.viewList()) {
result += String.format("%s, %s, %s, %s, %s, %s, %s\n", u.firstName, u.lastName, u.email, u.organization,
u.activeSince, u.lastOnline, u.lastExecute);
}
StringRepresentation response = new StringRepresentation(result);
response.setMediaType(MediaType.TEXT_CSV);
return response;
}