use of org.restlet.Response in project camel by apache.
the class RestletRouteBuilderTest method testNotFound.
@Test
public void testNotFound() throws IOException {
Client client = new Client(Protocol.HTTP);
Response response = client.handle(new Request(Method.POST, "http://localhost:" + portNum + "/unknown"));
// expect error status as no Restlet consumer to handle POST method
assertEquals(Status.CLIENT_ERROR_NOT_FOUND, response.getStatus());
assertNotNull(response.getEntity().getText());
}
use of org.restlet.Response in project camel by apache.
the class RestletRouteBuilderTest method testConsumer.
@Test
public void testConsumer() throws IOException {
Client client = new Client(Protocol.HTTP);
Response response = client.handle(new Request(Method.GET, "http://localhost:" + portNum + "/orders/99991/6"));
assertEquals("received GET request with id=99991 and x=6", response.getEntity().getText());
}
use of org.restlet.Response in project camel by apache.
the class RestletRouteBuilderTest method testConsumerWithSpaces.
@Test
public void testConsumerWithSpaces() throws IOException {
Client client = new Client(Protocol.HTTP);
Response response = client.handle(new Request(Method.GET, "http://localhost:" + portNum + "/orders with spaces in path/99991/6"));
assertEquals("received GET request with id=99991 and x=6", response.getEntity().getText());
}
use of org.restlet.Response in project qi4j-sdk by Qi4j.
the class ContextResource method handleCommand.
private void handleCommand(String segment) {
Request request = Request.getCurrent();
Response response = Response.getCurrent();
// Check if this is a request to show the form for this command
Method interactionMethod = resourceMethodCommands.get(segment);
if (shouldShowCommandForm(interactionMethod)) {
// Show form
// TODO This should check if method is idempotent
response.getAllowedMethods().add(org.restlet.data.Method.POST);
try {
// Check if there is a query with this name - if so invoke it
Method queryMethod = resourceMethodQueries.get(segment);
if (queryMethod != null) {
result(queryMethod.invoke(this));
} else {
request.setMethod(org.restlet.data.Method.POST);
response.setStatus(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY);
result(formForMethod(interactionMethod));
}
} catch (Exception e) {
handleException(response, e);
}
} else {
// Check timestamps
ResourceValidity validity = (ResourceValidity) request.getAttributes().get(RESOURCE_VALIDITY);
if (validity != null) {
validity.checkRequest();
}
// Check method constraints
if (!constraints.isValid(interactionMethod, current(), module)) {
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
}
// Create argument
Object[] arguments = requestReader.readRequest(Request.getCurrent(), interactionMethod);
Request.getCurrent().getAttributes().put(ARGUMENTS, arguments);
// Invoke method
try {
Object result = interactionMethod.invoke(this, arguments);
if (result != null) {
if (result instanceof Representation) {
response.setEntity((Representation) result);
} else {
result(convert(result));
}
}
} catch (Throwable e) {
handleException(response, e);
}
}
}
use of org.restlet.Response in project qi4j-sdk by Qi4j.
the class ContextResourceClientFactoryTest method testQueryListAndCommandProgressive.
@Test
public void testQueryListAndCommandProgressive() {
//START SNIPPET: query-list-and-command-progressive
crc.onResource(new ResultHandler<Resource>() {
@Override
public HandlerCommand handleResult(Resource result, ContextResourceClient client) {
return query("commandwithvalue").onSuccess(new ResultHandler<Links>() {
@Override
public HandlerCommand handleResult(Links result, ContextResourceClient client) {
Link link = LinksUtil.withId("right", result);
return command(link).onSuccess(new ResponseHandler() {
@Override
public HandlerCommand handleResponse(Response response, ContextResourceClient client) {
System.out.println("Done");
return null;
}
});
}
});
}
});
crc.start();
//END SNIPPET: query-list-and-command-progressive
}
Aggregations