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


Java Response.getEntityAsText方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:37,代码来源:JSONResponseReader.java

示例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"));
}
 
开发者ID:eternnoir,项目名称:MCRest,代码行数:8,代码来源:ServerStatusTest.java

示例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;
}
 
开发者ID:eternnoir,项目名称:MCRest,代码行数:8,代码来源:AuthResourceTest.java

示例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());
	}
	
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:13,代码来源:AgentStatusResource.java

示例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();
	}

}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:42,代码来源:TestCollectorResource.java


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