Hi, On Oct 20, 2009, at 10:46 AM, webp...@tigris.org wrote:
> Hi, > is anyone there to help? > > Thanks! > >> Dear All, >> I am using the restlet-jee-2.0snapshot, >> jdk5.0 on Tomcat 5.5. >> >> I have an application.properties file: >> WEB-INF/classes/application.properties >> >> But I keep getting the following error: >> java.lang.IllegalArgumentException: Cannot access to the >> configuration file: "clap://system/WEB-INF/classes/ >> application.properties" I haven't used CLAP myself, but I have a guess: if you're running in Tomcat, the classpath will include WEB-INF/classes. That means that resources (in the java sense) that you want to load need to be expressed relative to that directory; i.e., clap://system/ application.properties. Rhett >> >> It seems that I am not working properly with >> the classloader, CLAP. >> >> I have tried most ways, clap://thread/.., >> clap://class...but no luck so far. >> >> Here below is the code: >> >> Thanks, >> Sinoea >> >> [code] >> public class DirectoryServletApplication extends Application { >> >> /** Freemarker configuration object. */ >> private Configuration fmc; >> >> public static void main(String[] args) throws Exception { >> // Create a component >> Component component = new Component(); >> component.getServers().add(Protocol.HTTP, 8182); >> component.getClients().add(Protocol.FILE); >> component.getClients().add(Protocol.CLAP); >> component.getClients().add(Protocol.HTTP); >> >> DirectoryServletApplication application = new >> DirectoryServletApplication(component.getContext()); >> >> // Attach the application to the component and start it >> component.getDefaultHost().attach("", application); >> component.start(); >> } >> >> public DirectoryServletApplication(Context context) throws >> IOException { >> super(context); >> getConnectorService().getClientProtocols().add(Protocol.FILE); >> getConnectorService().getClientProtocols().add(Protocol.CLAP); >> getConnectorService().getClientProtocols().add(Protocol.HTTP); >> >> // Look for the configuration file in the classpath (Here is >> the PROBLEM) >> Properties properties = getProperties("clap://system/WEB-INF/ >> classes/application.properties"); >> System.out.println(properties.get("web.root.path")); >> try { >> this.fmc = new Configuration(); >> final File templateDir = new File("C:\\Program Files\ >> \Apache Software Foundation\\Tomcat 5.5\\webapps\\directory\\ROOT\ >> \WEB-INF\\template"); >> this.fmc.setDirectoryForTemplateLoading(templateDir); >> } catch (Exception e) { >> getLogger().severe("Unable to configure FreeMarker."); >> e.printStackTrace(); >> } >> } >> >> @Override >> public synchronized Restlet createInboundRoot() { >> // Create a router Restlet that routes each call to a >> // new instance of HelloWorldResource. >> Router router = new Router(getContext()); >> >> // Defines only one route >> router.attachDefault(HomePage.class); >> >> router.attach("/contactus", ContactUs.class); >> >> return router; >> } >> >> /** >> * Returns the freemarker configuration object. >> * >> * @return the freemarker configuration object. >> */ >> public Configuration getFmc() { >> return this.fmc; >> } >> >> /** >> * Returns a Properties instance loaded from the given URI. >> * >> * @param propertiesUri >> * The URI of the properties file. >> * @return A Properties instance loaded from the given URI. >> * @throws IOException >> */ >> public static Properties getProperties(String propertiesUri) >> throws IOException { >> Reference reference = new Reference(propertiesUri); >> Response response = new >> Client(reference.getSchemeProtocol()).get(reference); >> if (!(response.getStatus().isSuccess() && >> response.isEntityAvailable())) { >> StringBuilder stringBuilder = new StringBuilder(); >> stringBuilder.append("Cannot access to the configuration >> file: \""); >> stringBuilder.append(propertiesUri); >> stringBuilder.append("\""); >> throw new >> IllegalArgumentException(stringBuilder.toString()); >> } >> >> Properties properties = new Properties(); >> properties.load(response.getEntity().getStream()); >> return properties; >> } >> } >> [/code] >> >> >> [code] >> >> <?xml version="1.0" encoding="UTF-8"?> >> <web-app id="directory" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee >> " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee >> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd >> "> >> <display-name>directory</display-name> >> <!-- Application class name --> >> <context-param> >> <param-name>org.restlet.application</param-name> >> <param-value>example.DirectoryServletApplication</param-value> >> </context-param> >> <context-param> >> <param-name>org.restlet.clients</param-name> >> <param-value>HTTP HTTPS CLAP FILE</param-value> >> </context-param> >> >> <!-- Restlet adapter --> >> <servlet> >> <servlet-name>RestletServlet</servlet-name> >> <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet- >> class> >> </servlet> >> >> <!-- Catch all requests --> >> <servlet-mapping> >> <servlet-name>RestletServlet</servlet-name> >> <url-pattern>/*</url-pattern> >> </servlet-mapping> >> </web-app> >> >> [/code] > > ------------------------------------------------------ > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2409438 ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2409857