use of org.restlet.Restlet in project OpenAM by OpenRock.
the class ResourceSetRegistrationExceptionFilterTest method setup.
@BeforeMethod
public void setup() {
Restlet next = mock(Restlet.class);
JacksonRepresentationFactory jacksonRepresentationFactory = new JacksonRepresentationFactory(new ObjectMapper());
exceptionFilter = new ResourceSetRegistrationExceptionFilter(next, jacksonRepresentationFactory);
}
use of org.restlet.Restlet in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldHandleQueryParamRealmWithNoLeadingSlash.
@Test
public void shouldHandleQueryParamRealmWithNoLeadingSlash() throws IdRepoException, SSOException {
//Given
SSOToken adminToken = mock(SSOToken.class);
Restlet next = mock(Restlet.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
Request request = setUpRequest(httpRequest, adminToken);
Response response = mock(Response.class);
setUpServerName(request, adminToken, "/");
Reference reference = mock(Reference.class);
given(request.getResourceRef()).willReturn(reference);
Reference baseRef = mock(Reference.class);
given(reference.getBaseRef()).willReturn(baseRef);
given(baseRef.toString()).willReturn("The base url");
Form queryForm = mock(Form.class);
given(reference.getQueryAsForm()).willReturn(queryForm);
given(queryForm.getFirstValue("realm")).willReturn("REALM");
setUpRealmValidator("REALM", false, adminToken);
//When
router.doHandle(next, request, response);
//Then
assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
verify(httpRequest).setAttribute("realm", "/REALM");
}
use of org.restlet.Restlet in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldRouteToRealm.
@Test(dataProvider = "realmRoutingDataProvider")
public void shouldRouteToRealm(String realmLocation, boolean isRealmAlias) throws Exception {
//Given
SSOToken adminToken = mock(SSOToken.class);
Restlet next = mock(Restlet.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
Request request = setUpRequest(httpRequest, adminToken);
Response response = mock(Response.class);
String realm;
if (!isRealmAlias) {
realm = "REALM";
} else {
realm = "REALM_ALIAS";
}
if ("dns".equalsIgnoreCase(realmLocation)) {
//set up server name
setUpServerName(request, adminToken, realm);
}
if ("query".equalsIgnoreCase(realmLocation)) {
//set up query string
setUpServerName(request, adminToken, "/");
setUpQueryString(request, realm);
}
if ("uri".equalsIgnoreCase(realmLocation)) {
//set up uri
setUpServerName(request, adminToken, "/");
setUpUri(request, realm);
}
//set up validate realm
setUpRealmValidator(realm, isRealmAlias, adminToken);
//When
router.doHandle(next, request, response);
//Then
assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
verify(httpRequest).setAttribute("realm", "/REALM");
assertThat(request.getAttributes()).containsEntry("realmUrl", "The base url");
}
use of org.restlet.Restlet in project camel by apache.
the class RestletConsumer method createRestlet.
protected Restlet createRestlet() {
return new Restlet() {
@Override
public void handle(Request request, Response response) {
// must call super according to restlet documentation
super.handle(request, response);
LOG.debug("Consumer restlet handle request method: {}", request.getMethod());
Exchange exchange = null;
try {
// we want to handle the UoW
exchange = getEndpoint().createExchange();
createUoW(exchange);
RestletBinding binding = getEndpoint().getRestletBinding();
binding.populateExchangeFromRestletRequest(request, response, exchange);
try {
getProcessor().process(exchange);
} catch (Exception e) {
exchange.setException(e);
}
binding.populateRestletResponseFromExchange(exchange, response);
// resetlet will call the callback when its done sending where it would be safe
// to call doneUoW
Uniform callback = newResponseUniform(exchange);
response.setOnError(callback);
response.setOnSent(callback);
} catch (Throwable e) {
getExceptionHandler().handleException("Error processing request", exchange, e);
if (exchange != null) {
doneUoW(exchange);
}
}
}
};
}
use of org.restlet.Restlet in project camel by apache.
the class MethodBasedRouter method handle.
@Override
public void handle(Request request, Response response) {
Method method = request.getMethod();
LOG.debug("MethodRouter ({}) received request method: {}", uriPattern, method);
Restlet target = routes.get(method);
if (target != null) {
target.handle(request, response);
} else {
LOG.debug("MethodRouter ({}) method not allowed: {}", uriPattern, method);
response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
// must include list of allowed methods
response.setAllowedMethods(routes.keySet());
}
}
Aggregations