Search in sources :

Example 1 with Restlet

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);
}
Also used : Restlet(org.restlet.Restlet) JacksonRepresentationFactory(org.forgerock.openam.rest.representations.JacksonRepresentationFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with Restlet

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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(org.restlet.Response) SSOToken(com.iplanet.sso.SSOToken) Restlet(org.restlet.Restlet) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) HttpRequest(org.restlet.engine.adapter.HttpRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Test(org.testng.annotations.Test)

Example 3 with Restlet

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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(org.restlet.Response) SSOToken(com.iplanet.sso.SSOToken) Restlet(org.restlet.Restlet) HttpRequest(org.restlet.engine.adapter.HttpRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Test(org.testng.annotations.Test)

Example 4 with Restlet

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);
                }
            }
        }
    };
}
Also used : Response(org.restlet.Response) Exchange(org.apache.camel.Exchange) Restlet(org.restlet.Restlet) Request(org.restlet.Request) Uniform(org.restlet.Uniform)

Example 5 with Restlet

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());
    }
}
Also used : Restlet(org.restlet.Restlet) Method(org.restlet.data.Method)

Aggregations

Restlet (org.restlet.Restlet)13 Request (org.restlet.Request)5 Response (org.restlet.Response)5 Router (org.restlet.routing.Router)5 StringRepresentation (org.restlet.representation.StringRepresentation)3 SSOToken (com.iplanet.sso.SSOToken)2 File (java.io.File)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpRequest (org.restlet.engine.adapter.HttpRequest)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Test (org.testng.annotations.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FileSystemResourceFactory (io.milton.http.fs.FileSystemResourceFactory)1 FsMemoryLockManager (io.milton.http.fs.FsMemoryLockManager)1 NullSecurityManager (io.milton.http.fs.NullSecurityManager)1 SimpleFileContentService (io.milton.http.fs.SimpleFileContentService)1 WebDavRestlet (io.milton.restlet.WebDavRestlet)1 Exchange (org.apache.camel.Exchange)1 ZkChildResource (org.apache.helix.webapp.resources.ZkChildResource)1 ZkPathResource (org.apache.helix.webapp.resources.ZkPathResource)1