设置内容/媒体类型 - Restlet

Chr*_*row 2 java content-type restlet

如何在Restlet(谷歌应用引擎版本2.0)中设置内容类型?在这种情况下,我想将内容类型设置为""text/xml".

我有:

public class SubResource  extends ServerResource {

 @Get
 public Representation get(Representation representation){

    setStatus(Status.SUCCESS_OK);
    StringRepresentation sr = new StringRepresentation(getSomeXml());

    return sr;
 }
}
Run Code Online (Sandbox Code Playgroud)

即使它是在Representation中设置的值,或者它是从ServerResource类设置的方式与返回代码相同,我也不确定.

回答:

    StringRepresentation sr = new StringRepresentation(getSomeXml());
    sr.setMediaType(MediaType.TEXT_XML);
Run Code Online (Sandbox Code Playgroud)

jav*_*y79 8

除非GAE风格中有一些我不知道的东西,否则我认为它不需要那么复杂.这对我有用:

 @Get( value = "xml" )
 public String myMethodNameHere(){
    return getSomeXml();
 }
Run Code Online (Sandbox Code Playgroud)


Eve*_*ews 5

如果您使用注释,则可以

@Get("txt")
public Representation get() {

    setStatus(Status.SUCCESS_OK);

    return new StringRepresentation("Hi");
 }
Run Code Online (Sandbox Code Playgroud)

请参阅GetMetadataService