本文整理汇总了Java中org.restlet.Response.getEntityAsText方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getEntityAsText方法的具体用法?Java Response.getEntityAsText怎么用?Java Response.getEntityAsText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.Response
的用法示例。
在下文中一共展示了Response.getEntityAsText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readResponse
import org.restlet.Response; //导入方法依赖的package包/类
@Override
public Object readResponse( Response response, Class<?> resultType )
{
if( response.getEntity().getMediaType().equals( MediaType.APPLICATION_JSON ) )
{
if( ValueComposite.class.isAssignableFrom( resultType ) )
{
String jsonValue = response.getEntityAsText();
ValueCompositeType valueType = module.valueDescriptor( resultType.getName() ).valueType();
return jsonDeserializer.deserialize( module, valueType, jsonValue );
}
else if( resultType.equals( Form.class ) )
{
try( JsonReader reader = jsonFactories.readerFactory()
.createReader( response.getEntity().getReader() ) )
{
JsonObject jsonObject = reader.readObject();
Form form = new Form();
jsonObject.forEach(
( key, value ) ->
{
String valueString = value.getValueType() == JsonValue.ValueType.STRING
? ( (JsonString) value ).getString()
: value.toString();
form.set( key, valueString );
} );
return form;
}
catch( IOException | JsonException e )
{
throw new ResourceException( e );
}
}
}
return null;
}
示例2: TestGetServerStatus
import org.restlet.Response; //导入方法依赖的package包/类
@Test
public void TestGetServerStatus(){
Request request = new Request(Method.GET, serverUrl+"/");
Response response = client.handle(request);
String responseString = response.getEntityAsText();
Assert.assertTrue(responseString.contains("MCStub"));
}
示例3: getRequestResult
import org.restlet.Response; //导入方法依赖的package包/类
private Response getRequestResult(String path) {
Client client = new Client(Protocol.HTTP);
Request request = new Request(Method.GET, serverUrl+path);
Response response = client.handle(request);
String s = response.getEntityAsText();
return response;
}
示例4: getFiles
import org.restlet.Response; //导入方法依赖的package包/类
private String getFiles(String url) {
Response resp = client.get(url);
if(resp.getStatus().isSuccess()){
return resp.getEntityAsText();
}else{
throw new RuntimeException("Error: " + resp.getStatus().getDescription());
}
}
示例5: testCollectorStatus
import org.restlet.Response; //导入方法依赖的package包/类
@Test
public void testCollectorStatus() throws Exception {
Configuration conf = bootstrap.getBean(Configuration.class);
int port = conf.getInt(CollectorProperties.WRITER.COLLECTOR_MON_PORT
.toString(),
(Integer) CollectorProperties.WRITER.COLLECTOR_MON_PORT
.getDefaultValue());
Component pingComp = (Component) bootstrap.getBean("restletComponent");
pingComp.start();
try {
Client client = bootstrap.getBean(Client.class);
Response resp = client.get("http://localhost:" + port
+ "/collector/status");
assertNotNull(resp);
assertTrue(resp.getStatus().isSuccess());
String entity = resp.getEntityAsText();
assertNotNull(entity);
ObjectMapper objMapper = new ObjectMapper();
System.out.println("Status: " + entity);
CollectorStatus status = objMapper.readValue(entity,
CollectorStatusImpl.class);
assertNotNull(status);
} finally {
pingComp.stop();
}
}