You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2008/10/20 22:06:36 UTC
svn commit: r706396 - in
/mina/ftpserver/trunk/examples/ftpserver-example-spring-war: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/ftpserver/
src/main/java/org/apache/ftpserver/example/ src/main...
Author: ngn
Date: Mon Oct 20 13:06:35 2008
New Revision: 706396
URL: http://svn.apache.org/viewvc?rev=706396&view=rev
Log:
Initial import of FtpServer in WAR with Spring example. Based on David Latorre's code and mine.
Added:
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/pom.xml
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerListener.java
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerServlet.java
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/ftpserver.jks (with props)
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/log4j.properties
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/users.properties
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/applicationContext.xml
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/web.xml
Modified:
mina/ftpserver/trunk/examples/ftpserver-example-spring-war/ (props changed)
Propchange: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Oct 20 13:06:35 2008
@@ -0,0 +1,5 @@
+.settings
+res
+.classpath
+.project
+target
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/pom.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/pom.xml?rev=706396&view=auto
==============================================================================
--- mina/ftpserver/trunk/examples/ftpserver-example-spring-war/pom.xml (added)
+++ mina/ftpserver/trunk/examples/ftpserver-example-spring-war/pom.xml Mon Oct 20 13:06:35 2008
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.ftpserver.examples</groupId>
+ <artifactId>ftpserver-spring-war</artifactId>
+ <packaging>war</packaging>
+ <version>0.0.1-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>2.5.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ftpserver</groupId>
+ <artifactId>ftpserver-core</artifactId>
+ <version>1.0.0-M4-SNAPSHOT</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.0</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>ftpserver-spring-war</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>6.1.8</version>
+ <configuration>
+ <contextPath>/</contextPath>
+ <scanIntervalSeconds>5</scanIntervalSeconds>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerListener.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerListener.java?rev=706396&view=auto
==============================================================================
--- mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerListener.java (added)
+++ mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerListener.java Mon Oct 20 13:06:35 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ftpserver.example.springwar;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.ftpserver.FtpServer;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+public class FtpServerListener implements ServletContextListener {
+
+ public static final String FTPSERVER_CONTEXT_NAME = "org.apache.ftpserver";
+
+ public void contextDestroyed(ServletContextEvent sce) {
+ System.out.println("Stopping FtpServer");
+
+ FtpServer server = (FtpServer) sce.getServletContext().getAttribute(FTPSERVER_CONTEXT_NAME);
+
+ if(server != null) {
+ server.stop();
+
+ sce.getServletContext().removeAttribute(FTPSERVER_CONTEXT_NAME);
+
+ System.out.println("FtpServer stopped");
+ } else {
+ System.out.println("No running FtpServer found");
+ }
+
+ }
+
+ public void contextInitialized(ServletContextEvent sce) {
+ System.out.println("Starting FtpServer");
+
+ WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
+
+ FtpServer server = (FtpServer) ctx.getBean("myServer");
+
+ sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);
+
+ try {
+ server.start();
+ System.out.println("FtpServer started");
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to start FtpServer", e);
+ }
+ }
+
+}
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerServlet.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerServlet.java?rev=706396&view=auto
==============================================================================
--- mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerServlet.java (added)
+++ mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/java/org/apache/ftpserver/example/springwar/FtpServerServlet.java Mon Oct 20 13:06:35 2008
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ftpserver.example.springwar;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ftpserver.FtpServer;
+
+public class FtpServerServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 5539642787624981705L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ FtpServer server = (FtpServer) getServletContext().getAttribute(FtpServerListener.FTPSERVER_CONTEXT_NAME);
+
+ PrintWriter wr = resp.getWriter();
+
+ wr.print("<html>");
+ wr.print("<head>");
+ wr.print("<title>FtpServer status servlet</title>");
+ wr.print("</head>");
+ wr.print("<body>");
+ wr.print("<form method='post'>");
+
+
+ if(server.isStopped()) {
+ wr.print("<p>FtpServer is stopped.</p>");
+ } else {
+ if(server.isSuspended()) {
+ wr.print("<p>FtpServer is suspended.</p>");
+ wr.print("<p><input type='submit' name='resume' value='Resume'></p>");
+ wr.print("<p><input type='submit' name='stop' value='Stop'></p>");
+ } else {
+ wr.print("<p>FtpServer is running.</p>");
+ wr.print("<p><input type='submit' name='suspend' value='Suspend'></p>");
+ wr.print("<p><input type='submit' name='stop' value='Stop'></p>");
+ }
+ }
+
+ wr.print("</form>");
+ wr.print("</body>");
+ wr.print("</html>");
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ FtpServer server = (FtpServer) getServletContext().getAttribute(FtpServerListener.FTPSERVER_CONTEXT_NAME);
+
+ if(req.getParameter("stop") != null) {
+ server.stop();
+ } else if(req.getParameter("resume") != null) {
+ server.resume();
+ } else if(req.getParameter("suspend") != null) {
+ server.suspend();
+ }
+
+ resp.sendRedirect("/");
+ }
+
+}
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/ftpserver.jks
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/ftpserver.jks?rev=706396&view=auto
==============================================================================
Binary file - no diff available.
Propchange: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/ftpserver.jks
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/log4j.properties?rev=706396&view=auto
==============================================================================
--- mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/log4j.properties (added)
+++ mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/log4j.properties Mon Oct 20 13:06:35 2008
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+
+log4j.rootLogger=DEBUG, C
+log4j.appender.C=org.apache.log4j.ConsoleAppender
+log4j.appender.C.layout=org.apache.log4j.PatternLayout
+log4j.appender.C.layout.ConversionPattern=[%5p] %d [%X{userName}] [%X{remoteIp}] %m%n
+
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/users.properties
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/users.properties?rev=706396&view=auto
==============================================================================
--- mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/users.properties (added)
+++ mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/resources/users.properties Mon Oct 20 13:06:35 2008
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+
+# Password is "admin"
+ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3
+ftpserver.user.admin.homedirectory=/tmp
+ftpserver.user.admin.enableflag=true
+ftpserver.user.admin.writepermission=true
+ftpserver.user.admin.maxloginnumber=0
+ftpserver.user.admin.maxloginperip=0
+ftpserver.user.admin.idletime=0
+ftpserver.user.admin.uploadrate=0
+ftpserver.user.admin.downloadrate=0
+
+ftpserver.user.anonymous.userpassword=
+ftpserver.user.anonymous.homedirectory=/tmp
+ftpserver.user.anonymous.enableflag=true
+ftpserver.user.anonymous.writepermission=false
+ftpserver.user.anonymous.maxloginnumber=20
+ftpserver.user.anonymous.maxloginperip=2
+ftpserver.user.anonymous.idletime=300
+ftpserver.user.anonymous.uploadrate=4800
+ftpserver.user.anonymous.downloadrate=4800
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/applicationContext.xml?rev=706396&view=auto
==============================================================================
--- mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/applicationContext.xml (added)
+++ mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/applicationContext.xml Mon Oct 20 13:06:35 2008
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you 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.
+ -->
+<server xmlns="http://mina.apache.org/ftpserver/spring/v1"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd
+ "
+ id="myServer">
+ <listeners>
+ <nio-listener name="default" port="2121">
+ <ssl>
+ <keystore file="ftpserver.jks" password="password" />
+ </ssl>
+ </nio-listener>
+ </listeners>
+ <file-user-manager file="users.properties" />
+</server>
\ No newline at end of file
Added: mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/web.xml?rev=706396&view=auto
==============================================================================
--- mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/web.xml (added)
+++ mina/ftpserver/trunk/examples/ftpserver-example-spring-war/src/main/webapp/WEB-INF/web.xml Mon Oct 20 13:06:35 2008
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="WebApp_ID" version="2.5">
+
+ <display-name>ftpserver-spring-war</display-name>
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value> /WEB-INF/applicationContext.xml </param-value>
+ </context-param>
+
+
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.apache.ftpserver.example.springwar.FtpServerListener</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>status</servlet-name>
+ <servlet-class>org.apache.ftpserver.example.springwar.FtpServerServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>status</servlet-name>
+ <url-pattern>/</url-pattern>
+ </servlet-mapping>
+
+</web-app>
\ No newline at end of file