Java Code Examples for org.restlet.Response.getEntityAsText()

The following are Jave code examples for showing how to use getEntityAsText() of the org.restlet.Response class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: polygene-java   File: JSONResponseReader.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 2
Project: MCRest   File: ServerStatusTest.java   Source Code and License Vote up 5 votes
@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"));
}
 
Example 3
Project: MCRest   File: AuthResourceTest.java   Source Code and License Vote up 5 votes
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;
}
 
Example 4
Project: bigstreams   File: AgentStatusResource.java   Source Code and License Vote up 3 votes
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());
	}
	
}
 
Example 5
Project: bigstreams   File: TestCollectorResource.java   Source Code and License Vote up 2 votes
@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();
	}

}