Search in sources :

Example 1 with Resource

use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilder method addResourceRequestHandlers.

protected void addResourceRequestHandlers(EzyBeanContext beanContext) {
    ResourceResolver resourceResolver = getResourceResolver(beanContext);
    if (resourceResolver == null) {
        return;
    }
    ResourceDownloadManager downloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
    Map<String, Resource> resources = resourceResolver.getResources();
    for (String resourceURI : resources.keySet()) {
        Resource resource = resources.get(resourceURI);
        RequestURI requestURI = new RequestURI(HttpMethod.GET, resourceURI, false, true, true, resource.getFullPath());
        RequestHandler requestHandler = new ResourceRequestHandler(resource.getPath(), resource.getUri(), resource.getExtension(), downloadManager);
        requestHandlerManager.addHandler(requestURI, requestHandler);
    }
}
Also used : ResourceDownloadManager(com.tvd12.ezyhttp.core.resources.ResourceDownloadManager) ResourceRequestHandler(com.tvd12.ezyhttp.server.core.handler.ResourceRequestHandler) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) ResourceRequestHandler(com.tvd12.ezyhttp.server.core.handler.ResourceRequestHandler) ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) Resource(com.tvd12.ezyhttp.server.core.resources.Resource) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI)

Example 2 with Resource

use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.

the class ResourceLoaderTest method urlPathEmpty.

@Test
public void urlPathEmpty() {
    // given
    ResourceLoader sut = new ResourceLoader() {

        @Override
        protected Set<URL> getResourceURLs(String resource) {
            try {
                return Sets.newHashSet(new URL("http://locahost"));
            } catch (MalformedURLException e) {
                e.printStackTrace();
                throw new IllegalArgumentException(e);
            }
        }
    };
    // when
    List<String> listResources = sut.listResources("application.yaml");
    // then
    Asserts.assertTrue(listResources.isEmpty());
}
Also used : ResourceLoader(com.tvd12.ezyhttp.server.core.resources.ResourceLoader) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 3 with Resource

use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.

the class RequestHandlerManagerTest method test.

@Test
public void test() {
    // given
    RequestHandlerManager sut = new RequestHandlerManager();
    RequestHandler requestHandler = mock(RequestHandler.class);
    RequestURI requestURI = new RequestURI(HttpMethod.GET, "/get", RequestURIMeta.builder().api(true).authenticated(true).management(true).resource(true).payment(true).feature("hello.world").resourceFullPath("/").build());
    sut.addHandler(requestURI, requestHandler);
    // when
    FeatureURIManager featureURIManager = sut.getFeatureURIManager();
    // then
    Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get"), "hello.world");
    Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get/"), "hello.world");
}
Also used : RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) FeatureURIManager(com.tvd12.ezyhttp.server.core.manager.FeatureURIManager) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) Test(org.testng.annotations.Test)

Example 4 with Resource

use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.

the class ResourceResolverTest method test.

@Test
public void test() {
    // given
    ResourceResolver sut = new ResourceResolver();
    sut.register("static/css");
    sut.register(new String[] { "templates/js" });
    // when
    Map<String, Resource> resources = sut.getResources();
    // then
    Asserts.assertEquals(3, resources.size());
}
Also used : ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) Resource(com.tvd12.ezyhttp.server.core.resources.Resource) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)3 RequestHandler (com.tvd12.ezyhttp.server.core.handler.RequestHandler)2 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)2 Resource (com.tvd12.ezyhttp.server.core.resources.Resource)2 ResourceResolver (com.tvd12.ezyhttp.server.core.resources.ResourceResolver)2 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)1 ResourceRequestHandler (com.tvd12.ezyhttp.server.core.handler.ResourceRequestHandler)1 FeatureURIManager (com.tvd12.ezyhttp.server.core.manager.FeatureURIManager)1 RequestHandlerManager (com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager)1 ResourceLoader (com.tvd12.ezyhttp.server.core.resources.ResourceLoader)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1