use of com.manydesigns.portofino.dispatcher.resolvers.JavaResourceResolver in project Portofino by ManyDesigns.
the class TestJavaResourceResolver method simpleScenario.
@Test
public void simpleScenario() throws Exception {
FileObject root = getRoot();
ResourceResolver javaResourceResolver = getResourceResolver();
// A.java
Class<?> c = javaResourceResolver.resolve(root, Class.class);
assertEquals("A", c.getName());
Field string = c.getField("string");
Object a = c.newInstance();
assertEquals("class A", string.get(a));
// B.java
c = javaResourceResolver.resolve(root.resolveFile("b"), Class.class);
assertEquals("B", c.getName());
string = c.getField("string");
Object b = c.newInstance();
assertEquals("class B", string.get(b));
}
use of com.manydesigns.portofino.dispatcher.resolvers.JavaResourceResolver in project Portofino by ManyDesigns.
the class TestJavaResourceResolver method testSubResource.
@Test
public void testSubResource() throws Exception {
FileObject root = getRoot();
ResourceResolver javaResourceResolver = getResourceResolver();
FileObject p = root.resolveFile("p");
Class<?> c = javaResourceResolver.resolve(p, Class.class);
assertEquals("Params", c.getName());
c = javaResourceResolver.resolve(p.getChild("sub"), Class.class);
assertEquals("Sub", c.getName());
}
use of com.manydesigns.portofino.dispatcher.resolvers.JavaResourceResolver in project Portofino by ManyDesigns.
the class TestJavaResourceResolver method reload.
@Test
public void reload() throws Exception {
FileObject root = getRoot();
JavaResourceResolver javaResourceResolver = (JavaResourceResolver) getResourceResolver();
Class<?> c1 = javaResourceResolver.resolve(root, Class.class);
assertNotNull(c1);
Class<?> c2 = javaResourceResolver.resolve(root, Class.class);
assertEquals(c1, c2);
// TODO ideally we should update the file's last modified time but it's not possible since for this test it's a Classloader resource
javaResourceResolver.clearCache(0);
Class<?> c3 = javaResourceResolver.resolve(root, Class.class);
assertFalse(c1.equals(c3));
}
use of com.manydesigns.portofino.dispatcher.resolvers.JavaResourceResolver in project Portofino by ManyDesigns.
the class DispatcherInitializer method configureResourceResolvers.
protected void configureResourceResolvers(ResourceResolvers resourceResolver, CodeBase codeBase) {
resourceResolver.resourceResolvers.add(new JavaResourceResolver(codeBase));
addResourceResolver(resourceResolver, "com.manydesigns.portofino.dispatcher.resolvers.GroovyResourceResolver", codeBase, false);
addResourceResolver(resourceResolver, "com.manydesigns.portofino.dispatcher.resolvers.JacksonResourceResolver", codeBase, true);
}
use of com.manydesigns.portofino.dispatcher.resolvers.JavaResourceResolver in project Portofino by ManyDesigns.
the class GrizzlyMain method main.
public static void main(String[] args) throws Exception {
File currentDirectory = new File("");
FileSystemManager manager = VFS.getManager();
if (manager instanceof DefaultFileSystemManager) {
((DefaultFileSystemManager) manager).setBaseFile(currentDirectory);
}
String rootPath = currentDirectory.getAbsolutePath();
if (args.length > 0) {
rootPath = args[0];
}
FileObject codeBaseRoot;
try {
codeBaseRoot = VFS.getManager().resolveFile("res:");
} catch (Exception e) {
codeBaseRoot = VFS.getManager().resolveFile("res:com/manydesigns/portofino/dispatcher/main/GrizzlyMain.class").getParent().getParent().getParent().getParent().getParent().getParent();
}
CodeBase codeBase = new JavaCodeBase(codeBaseRoot);
codeBase = new GroovyCodeBase(codeBaseRoot, codeBase);
ResourceResolvers resourceResolver = new ResourceResolvers();
resourceResolver.resourceResolvers.add(new JavaResourceResolver(codeBase));
resourceResolver.resourceResolvers.add(new GroovyResourceResolver(codeBase));
FileObject root = manager.resolveFile(rootPath);
logger.info("Codebase rootFactory: " + codeBaseRoot.getURL());
logger.info("Root path: " + root.getURL());
DocumentedApiRoot.setRootFactory(() -> Root.get(root, resourceResolver));
String host = System.getProperty("portofino.web.host", "0.0.0.0");
String port = System.getProperty("portofino.web.port", "8090");
ResourceConfig config = new ResourceConfig(ApplicationRoot.class, OpenApiResource.class);
config.property(ServletProperties.FILTER_FORWARD_ON_404, true);
try {
config.register(Class.forName("org.glassfish.jersey.jackson.JacksonFeature"));
ResourceResolver jacksonRR = (ResourceResolver) Class.forName("com.manydesigns.portofino.dispatcher.resolvers.JacksonResourceResolver").newInstance();
resourceResolver.resourceResolvers.add(new CachingResourceResolver(jacksonRR));
} catch (ClassNotFoundException e) {
// Jackson not available
}
try {
config.register(Class.forName("com.manydesigns.portofino.dispatcher.security.ShiroResourceFilter"));
} catch (ClassNotFoundException e) {
// Shiro not available
}
/* TODO
BeanConfig beanConfig = new BeanConfig();
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost(host + ":" + port);
beanConfig.setBasePath("/");
beanConfig.setResourcePackage(ApplicationRoot.class.getPackage().getName());
beanConfig.setScan(true);*/
URI uri = URI.create("http://" + host + ":" + port + "/");
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(uri, config);
// https://scalajamsession.wordpress.com/2015/06/27/how-to-serve-static-files-with-jerseygrizzly-setup-and-control-access-to-static-content/
ClassLoader loader = GrizzlyMain.class.getClassLoader();
CLStaticHttpHandler webjarsHandler = new CLStaticHttpHandler(loader, "META-INF/resources/webjars/");
httpServer.getServerConfiguration().addHttpHandler(webjarsHandler, "/webjars/");
httpServer.start();
}
Aggregations