commit 3646830693ecf3652ff9954002a685430634ad59 from: leo date: Thu Jan 29 13:22:18 2009 UTC moved main application into another sub project fixed some tests commit - 63823a9f1ddefd9361bcf5223c7b9e71fee7bf40 commit + 3646830693ecf3652ff9954002a685430634ad59 blob - /dev/null blob + 4ffa13f363bb7e2a984cd5dbd5049b70d07bfd07 (mode 644) --- /dev/null +++ modules/server/moxo-server.iml @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + blob - /dev/null blob + 476dfe8db6dc10c84d565ecc644ec9683126cfdd (mode 644) --- /dev/null +++ modules/server/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + com.thinkberg + moxo-server + Moxo Server + 1.0 + + + org.mortbay.jetty + jetty + 6.1.1 + + + com.thinkberg + webdav + 1.0-SNAPSHOT + + + com.thinkberg + vfs.s3 + 1.0-SNAPSHOT + + + + + + maven-compiler-plugin + + true + true + 1.5 + 1.5 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/MoxoTest.java + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + package + + jar + + + + + com.thinkberg.moxo.Main + true + + + + **/moxo/* + + + + + + + + + \ No newline at end of file blob - /dev/null blob + 834ca79e40db93587eb89c07798c51befb4cdbe8 (mode 644) --- /dev/null +++ modules/server/src/main/java/com/thinkberg/moxo/Main.java @@ -0,0 +1,164 @@ +/* + * Copyright 2007 Matthias L. Jugel. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.thinkberg.moxo; + +import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.Policy; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; + +/** + * The launcher is responsible for extracting referenced libraries from the jar and + * setting up the classpath. + * + * @author Matthias L. Jugel + */ +public class Main { + private final static URL location = Main.class.getProtectionDomain().getCodeSource().getLocation(); + + public static void main(String args[]) + throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader(); + if (null == parentClassLoader) { + parentClassLoader = Main.class.getClassLoader(); + } + if (null == parentClassLoader) { + parentClassLoader = ClassLoader.getSystemClassLoader(); + } + URLClassLoader classLoader = new URLClassLoader(initClassPath(), parentClassLoader); + Thread.currentThread().setContextClassLoader(classLoader); + + System.setSecurityManager(null); + + try { + Policy.getPolicy().refresh(); + } catch (Exception e) { + e.printStackTrace(); + } + + Class mainClass = classLoader.loadClass("com.thinkberg.moxo.MoxoJettyRunner"); + @SuppressWarnings({"RedundantArrayCreation"}) + final Method main = mainClass.getDeclaredMethod("main", new Class[]{String[].class}); + main.invoke(null, new Object[]{args}); + } + + /** + * Read the jar manifest and add class-path entries to the classpath. + * + * @return the classpath + */ + @SuppressWarnings({"ConstantConditions"}) + private static URL[] initClassPath() { + List urlArray = new ArrayList(); + InputStream manifestIn = null; + InputStream jarIn = null; + try { + manifestIn = location.openStream(); + JarInputStream launcherJarIs = new JarInputStream(manifestIn); + StringBuffer classPath = new StringBuffer(location.getFile()); + List classpathList = new ArrayList(urlArray); + JarEntry jarEntry; + while (null != (jarEntry = launcherJarIs.getNextJarEntry())) { + if (!jarEntry.isDirectory() && jarEntry.getName().endsWith(".jar")) { + try { + URL classPathEntry = getResourceUrl(jarEntry.getName()); + if (!classpathList.contains(classPathEntry)) { + urlArray.add(classPathEntry); + classPath.append(File.pathSeparatorChar); + classPath.append(classPathEntry.getFile()); + } + } catch (IOException e) { + System.err.println("ignored '" + jarEntry.getName() + "'"); + } + } + } + + System.setProperty("java.class.path", classPath.toString()); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + manifestIn.close(); + } catch (Throwable ignore) { + // ignore errors + } + try { + jarIn.close(); + } catch (Throwable ignore) { + // ignore errors + } + } + return urlArray.toArray(new URL[urlArray.size()]); + } + + /** + * Get URL. + * + * @param resource resource name/path + * @return the url pointing to the resource + * @throws IOException if the resource cannot be accessed + */ + private static URL getResourceUrl(String resource) throws IOException { + File directoryBase = new File(location.getFile()).getParentFile(); + File file = new File(resource); + if (file.isAbsolute() && file.exists()) { + return file.toURL(); + } + file = new File(directoryBase, resource); + if (file.exists()) { + return file.toURL(); + } + + URL resourceURL = Main.class.getResource("/" + resource); + if (null != resourceURL) { + return extract(resourceURL); + } + + throw new MalformedURLException(resource); + } + + /** + * Extract file from launcher jar to be able to access is via classpath. + * + * @param resource the jar resource to be extracted + * @return a url pointing to the new file + * @throws IOException if the extraction was not possible + */ + private static URL extract(URL resource) throws IOException { + File f = File.createTempFile("launcher_", ".jar"); + f.deleteOnExit(); + if (f.getParentFile() != null) { + f.getParentFile().mkdirs(); + } + InputStream is = new BufferedInputStream(resource.openStream()); + FileOutputStream os = new FileOutputStream(f); + byte[] arr = new byte[8192]; + for (int i = 0; i >= 0; i = is.read(arr)) { + os.write(arr, 0, i); + } + is.close(); + os.close(); + return f.toURL(); + } +} \ No newline at end of file blob - /dev/null blob + 81fa814c760d3f3302548ef451f1fcad06157e6d (mode 644) --- /dev/null +++ modules/server/src/main/java/com/thinkberg/moxo/MoxoJettyRunner.java @@ -0,0 +1,66 @@ +/* + * Copyright 2007 Matthias L. Jugel. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.thinkberg.moxo; + +import org.mortbay.jetty.Server; +import org.mortbay.xml.XmlConfiguration; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +/** + * The Java Webserver starter uses jetty. + * + * @author Matthias L. Jugel + */ +public class MoxoJettyRunner { + private static final String CONF_JETTY_XML = "/jetty.xml"; + + public static void main(String[] args) { + System.out.println("Moxo S3 DAV Proxy (c) 2007 Matthias L. Jugel"); + + // set encoding of the JVM and make sure Jetty decodes URIs correctly + System.setProperty("file.encoding", "UTF-8"); + System.setProperty("org.mortbay.util.URI.charset", "UTF-8"); + + try { + Server server = new Server(); + XmlConfiguration xmlConfiguration = new XmlConfiguration(getXmlConfigurationUrl()); + xmlConfiguration.configure(server); + server.start(); + server.join(); + } catch (Exception e) { + System.err.println("Can't start server: " + e.getMessage()); + System.exit(1); + } + } + + private static URL getXmlConfigurationUrl() { + String configFile = System.getProperty("jetty.xml", CONF_JETTY_XML); + URL url = MoxoJettyRunner.class.getResource(configFile); + if (null == url) { + try { + url = new File(configFile).toURL(); + System.err.println("Loading configuration from file: " + url.toExternalForm()); + } catch (MalformedURLException e) { + // ignore ... + } + } + return url; + } +} blob - /dev/null blob + ee8611fc7310c54462bf8672a9ff9845cbab912a (mode 644) --- /dev/null +++ modules/server/src/main/resources/commons-logging.properties @@ -0,0 +1,17 @@ +# +# Copyright 2007 Matthias L. Jugel. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger +org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \ No newline at end of file blob - /dev/null blob + 71c406fc4d38c233930be39548d9d3767b2a5d3b (mode 644) --- /dev/null +++ modules/server/src/main/resources/jetty.xml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + 10 + 50 + 250 + + + + + + + + + + + + + + + + + + + + 30000 + 2 + 8443 + + + + + + + + 8443 + 30000 + /.keystore + + OBF:1fvu20731x191vul1vup1x1d20731ftg + OBF:1fvu20731x191vul1vup1x1d20731ftg + /.keystore + + OBF:1fvu20731x191vul1vup1x1d20731ftg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + + + + com.thinkberg.webdav.servlet.MoxoWebDAVServlet + /* + + vfs.uri + ram:/ + + + vfs.auth.domain + + + + vfs.auth.user + theuser + + + vfs.auth.password + thepassword + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /yyyy_mm_dd.request.log + + 90 + true + false + GMT + + + + + + + + true + + true + + blob - /dev/null blob + 06d0ba45d0947de8c84d470d4bc1a1fd74c4346a (mode 644) --- /dev/null +++ modules/server/src/main/resources/simplelog.properties @@ -0,0 +1,19 @@ +# +# Copyright 2007 Matthias L. Jugel. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +org.apache.commons.logging.simplelog.defaultlog=error +org.apache.commons.logging.simplelog.log.com.thinkberg.vfs.s3=info +org.apache.commons.logging.simplelog.log.com.thinkberg.webdav=info \ No newline at end of file blob - 834ca79e40db93587eb89c07798c51befb4cdbe8 (mode 644) blob + /dev/null --- src/main/java/com/thinkberg/moxo/Main.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2007 Matthias L. Jugel. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.thinkberg.moxo; - -import java.io.*; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.security.Policy; -import java.util.ArrayList; -import java.util.List; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; - -/** - * The launcher is responsible for extracting referenced libraries from the jar and - * setting up the classpath. - * - * @author Matthias L. Jugel - */ -public class Main { - private final static URL location = Main.class.getProtectionDomain().getCodeSource().getLocation(); - - public static void main(String args[]) - throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader(); - if (null == parentClassLoader) { - parentClassLoader = Main.class.getClassLoader(); - } - if (null == parentClassLoader) { - parentClassLoader = ClassLoader.getSystemClassLoader(); - } - URLClassLoader classLoader = new URLClassLoader(initClassPath(), parentClassLoader); - Thread.currentThread().setContextClassLoader(classLoader); - - System.setSecurityManager(null); - - try { - Policy.getPolicy().refresh(); - } catch (Exception e) { - e.printStackTrace(); - } - - Class mainClass = classLoader.loadClass("com.thinkberg.moxo.MoxoJettyRunner"); - @SuppressWarnings({"RedundantArrayCreation"}) - final Method main = mainClass.getDeclaredMethod("main", new Class[]{String[].class}); - main.invoke(null, new Object[]{args}); - } - - /** - * Read the jar manifest and add class-path entries to the classpath. - * - * @return the classpath - */ - @SuppressWarnings({"ConstantConditions"}) - private static URL[] initClassPath() { - List urlArray = new ArrayList(); - InputStream manifestIn = null; - InputStream jarIn = null; - try { - manifestIn = location.openStream(); - JarInputStream launcherJarIs = new JarInputStream(manifestIn); - StringBuffer classPath = new StringBuffer(location.getFile()); - List classpathList = new ArrayList(urlArray); - JarEntry jarEntry; - while (null != (jarEntry = launcherJarIs.getNextJarEntry())) { - if (!jarEntry.isDirectory() && jarEntry.getName().endsWith(".jar")) { - try { - URL classPathEntry = getResourceUrl(jarEntry.getName()); - if (!classpathList.contains(classPathEntry)) { - urlArray.add(classPathEntry); - classPath.append(File.pathSeparatorChar); - classPath.append(classPathEntry.getFile()); - } - } catch (IOException e) { - System.err.println("ignored '" + jarEntry.getName() + "'"); - } - } - } - - System.setProperty("java.class.path", classPath.toString()); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - manifestIn.close(); - } catch (Throwable ignore) { - // ignore errors - } - try { - jarIn.close(); - } catch (Throwable ignore) { - // ignore errors - } - } - return urlArray.toArray(new URL[urlArray.size()]); - } - - /** - * Get URL. - * - * @param resource resource name/path - * @return the url pointing to the resource - * @throws IOException if the resource cannot be accessed - */ - private static URL getResourceUrl(String resource) throws IOException { - File directoryBase = new File(location.getFile()).getParentFile(); - File file = new File(resource); - if (file.isAbsolute() && file.exists()) { - return file.toURL(); - } - file = new File(directoryBase, resource); - if (file.exists()) { - return file.toURL(); - } - - URL resourceURL = Main.class.getResource("/" + resource); - if (null != resourceURL) { - return extract(resourceURL); - } - - throw new MalformedURLException(resource); - } - - /** - * Extract file from launcher jar to be able to access is via classpath. - * - * @param resource the jar resource to be extracted - * @return a url pointing to the new file - * @throws IOException if the extraction was not possible - */ - private static URL extract(URL resource) throws IOException { - File f = File.createTempFile("launcher_", ".jar"); - f.deleteOnExit(); - if (f.getParentFile() != null) { - f.getParentFile().mkdirs(); - } - InputStream is = new BufferedInputStream(resource.openStream()); - FileOutputStream os = new FileOutputStream(f); - byte[] arr = new byte[8192]; - for (int i = 0; i >= 0; i = is.read(arr)) { - os.write(arr, 0, i); - } - is.close(); - os.close(); - return f.toURL(); - } -} \ No newline at end of file blob - 81fa814c760d3f3302548ef451f1fcad06157e6d (mode 644) blob + /dev/null --- src/main/java/com/thinkberg/moxo/MoxoJettyRunner.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2007 Matthias L. Jugel. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.thinkberg.moxo; - -import org.mortbay.jetty.Server; -import org.mortbay.xml.XmlConfiguration; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; - -/** - * The Java Webserver starter uses jetty. - * - * @author Matthias L. Jugel - */ -public class MoxoJettyRunner { - private static final String CONF_JETTY_XML = "/jetty.xml"; - - public static void main(String[] args) { - System.out.println("Moxo S3 DAV Proxy (c) 2007 Matthias L. Jugel"); - - // set encoding of the JVM and make sure Jetty decodes URIs correctly - System.setProperty("file.encoding", "UTF-8"); - System.setProperty("org.mortbay.util.URI.charset", "UTF-8"); - - try { - Server server = new Server(); - XmlConfiguration xmlConfiguration = new XmlConfiguration(getXmlConfigurationUrl()); - xmlConfiguration.configure(server); - server.start(); - server.join(); - } catch (Exception e) { - System.err.println("Can't start server: " + e.getMessage()); - System.exit(1); - } - } - - private static URL getXmlConfigurationUrl() { - String configFile = System.getProperty("jetty.xml", CONF_JETTY_XML); - URL url = MoxoJettyRunner.class.getResource(configFile); - if (null == url) { - try { - url = new File(configFile).toURL(); - System.err.println("Loading configuration from file: " + url.toExternalForm()); - } catch (MalformedURLException e) { - // ignore ... - } - } - return url; - } -} blob - ee8611fc7310c54462bf8672a9ff9845cbab912a (mode 644) blob + /dev/null --- src/main/resources/commons-logging.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2007 Matthias L. Jugel. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger -org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \ No newline at end of file blob - 71c406fc4d38c233930be39548d9d3767b2a5d3b (mode 644) blob + /dev/null --- src/main/resources/jetty.xml +++ /dev/null @@ -1,206 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - 10 - 50 - 250 - - - - - - - - - - - - - - - - - - - - 30000 - 2 - 8443 - - - - - - - - 8443 - 30000 - /.keystore - - OBF:1fvu20731x191vul1vup1x1d20731ftg - OBF:1fvu20731x191vul1vup1x1d20731ftg - /.keystore - - OBF:1fvu20731x191vul1vup1x1d20731ftg - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / - - - - - com.thinkberg.webdav.servlet.MoxoWebDAVServlet - /* - - vfs.uri - ram:/ - - - vfs.auth.domain - - - - vfs.auth.user - theuser - - - vfs.auth.password - thepassword - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /yyyy_mm_dd.request.log - - 90 - true - false - GMT - - - - - - - - true - - true - - blob - 06d0ba45d0947de8c84d470d4bc1a1fd74c4346a (mode 644) blob + /dev/null --- src/main/resources/simplelog.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Copyright 2007 Matthias L. Jugel. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -org.apache.commons.logging.simplelog.defaultlog=error -org.apache.commons.logging.simplelog.log.com.thinkberg.vfs.s3=info -org.apache.commons.logging.simplelog.log.com.thinkberg.webdav=info \ No newline at end of file