diff --git a/.gitignore b/.gitignore index 30e3d38..d7dcfc6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ *.project *.settings target +douyu-examples-classes diff --git a/assembly.xml b/assembly.xml index 6ab688a..7f42759 100644 --- a/assembly.xml +++ b/assembly.xml @@ -10,7 +10,7 @@ - org.douyu:douyu-api + com.codefollower.douyu:douyu-api false @@ -26,7 +26,7 @@ - org.douyu:douyu-javac + com.codefollower.douyu:douyu-javac false @@ -36,7 +36,7 @@ true true - org.douyu:douyu-api + com.codefollower.douyu:douyu-api @@ -45,7 +45,7 @@ - org.douyu:douyu-core + com.codefollower.douyu:douyu-core false @@ -55,7 +55,7 @@ true true - org.douyu:douyu-javac + com.codefollower.douyu:douyu-javac @@ -64,7 +64,7 @@ - org.douyu:douyu-mvc + com.codefollower.douyu:douyu-mvc false @@ -74,7 +74,7 @@ true true - org.douyu:douyu-core + com.codefollower.douyu:douyu-core @@ -83,7 +83,7 @@ - org.douyu:douyu-plugins + com.codefollower.douyu:douyu-plugins false @@ -93,7 +93,7 @@ true true - org.douyu:douyu-api + com.codefollower.douyu:douyu-api diff --git a/douyu-examples/pom.xml b/douyu-examples/pom.xml new file mode 100644 index 0000000..c8f7ca9 --- /dev/null +++ b/douyu-examples/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + com.codefollower.douyu + douyu + 0.1.0 + + + douyu-examples + jar + ${douyu.version} + douyu examples + + + + com.codefollower.douyu + douyu-startup + ${douyu.version} + + + diff --git a/douyu-examples/src/AsyncExample.java b/douyu-examples/src/AsyncExample.java deleted file mode 100644 index 92eabfe..0000000 --- a/douyu-examples/src/AsyncExample.java +++ /dev/null @@ -1,39 +0,0 @@ -import java.io.PrintWriter; -import java.util.Date; - -import douyu.mvc.Async; -import douyu.mvc.Context; -import douyu.mvc.Controller; - -@Controller -public class AsyncExample { - @Async - public void asyncAction(Context c, PrintWriter out) { - out.println("before invokeLongtimeService..."+Thread.currentThread()); - invokeLongtimeService(c, out); - out.println("after invokeLongtimeService..."); - } - - private void invokeLongtimeService(Context c, PrintWriter out) { - out.println("invokeLongtimeService..."); - out.println("at "+ new Date()); - - int seconds = 2; - out.println("sleep "+seconds+" seconds..."); - try { - Thread.sleep(seconds*1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - out.println("at "+ new Date()); - } - - @Async - public void asyncAction2(PrintWriter out) { - out.println("invoke asyncAction2..."+Thread.currentThread()); - } - - public void action3(PrintWriter out) { - out.println("invoke action3..."+Thread.currentThread()); - } -} diff --git a/douyu-examples/src/FileUpload.java b/douyu-examples/src/FileUpload.java deleted file mode 100644 index cf7bc51..0000000 --- a/douyu-examples/src/FileUpload.java +++ /dev/null @@ -1,59 +0,0 @@ -import java.io.File; -import java.io.PrintWriter; - -import douyu.mvc.Context; -import douyu.mvc.Controller; - -import douyu.http.HttpRequest; -import douyu.http.UploadedFile; - -@Controller -public class FileUpload { - public void index(Context c) { - c.out("FileUpload.html"); - } - - public void upload(HttpRequest request, UploadedFile[] uploadedFiles, UploadedFile file1, - String description, PrintWriter out) { - - out.println("说明: "+description); - out.println("file1: "+request.getUploadedFile("file1")); - out.println("uploadedFiles.length: "+uploadedFiles.length); - out.println(); - - if(uploadedFiles != null) { - for(UploadedFile uf : uploadedFiles) { - //注意这里,file1与uploadedFiles中的某一个元素指向同一个对象 - if(file1 == uf) { - out.println("这是文件1:"); - out.println(); - } - - out.println("大小 : "+uf.getSize()+" 字节"); - out.println("类型 : "+uf.getContentType()); - out.println("文件名: "+uf.getSimpleName()); - out.println("全名 : "+uf.getFullName()); - out.println("路径名: "+uf.getPathName()); - - out.println(); - out.println("文件内容:"); - out.println("--------------------------------------"); - out.println(uf.getContent()); - out.println("--------------------------------------"); - - out.println(); - - File file = new File("E:/Douyu/douyu-examples-classes/uploadedFiles", uf.getSimpleName()); - - try { - uf.saveTo(file); - out.println("已保存到: "+file); - } catch(Exception e) { - out.println("出错了: "+e); - } - out.println(); - out.println(); - } - } - } -} diff --git a/douyu-examples/src/HelloWorld.java b/douyu-examples/src/HelloWorld.java deleted file mode 100644 index 2580736..0000000 --- a/douyu-examples/src/HelloWorld.java +++ /dev/null @@ -1,9 +0,0 @@ -import java.io.PrintWriter; -import douyu.mvc.Controller; - -@Controller -public class HelloWorld { - public void index(PrintWriter out) { - out.println("Hello Douyu World!"); - } -} \ No newline at end of file diff --git a/douyu-examples/src/ModelInjectExample.java b/douyu-examples/src/ModelInjectExample.java deleted file mode 100644 index 7d50e75..0000000 --- a/douyu-examples/src/ModelInjectExample.java +++ /dev/null @@ -1,13 +0,0 @@ -import java.io.PrintWriter; - -import douyu.mvc.Controller; -import models.Consumer; - -@Controller -public class ModelInjectExample { - //ModelInjectExample?consumer.name=zhh&consumer.address.country=china&consumer.address.city=hangzhou - - public void index(Consumer consumer, PrintWriter out) { - out.println("consumer=" + consumer); - } -} diff --git a/douyu-examples/src/main/java/AsyncExample.java b/douyu-examples/src/main/java/AsyncExample.java new file mode 100644 index 0000000..3ae9e8f --- /dev/null +++ b/douyu-examples/src/main/java/AsyncExample.java @@ -0,0 +1,58 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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. + */ +import java.io.PrintWriter; +import java.util.Date; + +import douyu.mvc.Async; +import douyu.mvc.Context; +import douyu.mvc.Controller; + +@Controller +public class AsyncExample { + @Async + public void asyncAction(Context c, PrintWriter out) { + out.println("before invokeLongtimeService..." + Thread.currentThread()); + invokeLongtimeService(c, out); + out.println("after invokeLongtimeService..."); + } + + private void invokeLongtimeService(Context c, PrintWriter out) { + out.println("invokeLongtimeService..."); + out.println("at " + new Date()); + + int seconds = 2; + out.println("sleep " + seconds + " seconds..."); + try { + Thread.sleep(seconds * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + out.println("at " + new Date()); + } + + @Async + public void asyncAction2(PrintWriter out) { + out.println("invoke asyncAction2..." + Thread.currentThread()); + } + + public void action3(PrintWriter out) { + out.println("invoke action3..." + Thread.currentThread()); + } +} diff --git a/douyu-examples/src/CometExample.java b/douyu-examples/src/main/java/CometExample.java similarity index 57% rename from douyu-examples/src/CometExample.java rename to douyu-examples/src/main/java/CometExample.java index f07c0fb..26b8882 100644 --- a/douyu-examples/src/CometExample.java +++ b/douyu-examples/src/main/java/CometExample.java @@ -1,3 +1,22 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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. + */ import java.io.IOException; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -19,6 +38,7 @@ public void join(Context c) { public static class MyComet implements Comet { private final static Set members = new CopyOnWriteArraySet(); Context context; + @Override public void onConnect(Context context) { members.add(this); diff --git a/douyu-examples/src/CookieExample.java b/douyu-examples/src/main/java/CookieExample.java similarity index 100% rename from douyu-examples/src/CookieExample.java rename to douyu-examples/src/main/java/CookieExample.java diff --git a/douyu-examples/src/DevTest.java b/douyu-examples/src/main/java/DevTest.java similarity index 72% rename from douyu-examples/src/DevTest.java rename to douyu-examples/src/main/java/DevTest.java index 2c99b20..23bbf4d 100644 --- a/douyu-examples/src/DevTest.java +++ b/douyu-examples/src/main/java/DevTest.java @@ -1,6 +1,26 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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. + */ import java.io.PrintWriter; import java.io.Writer; +import douyu.examples.models.MyModel; import douyu.http.HttpRequest; import douyu.http.HttpResponse; import douyu.mvc.Context; @@ -8,7 +28,6 @@ import douyu.mvc.ControllerManager; import douyu.mvc.ModelManager; import douyu.mvc.ViewManager; -import models.MyModel; @Controller public class DevTest { diff --git a/douyu-examples/src/main/java/FileUpload.java b/douyu-examples/src/main/java/FileUpload.java new file mode 100644 index 0000000..4b5a425 --- /dev/null +++ b/douyu-examples/src/main/java/FileUpload.java @@ -0,0 +1,77 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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. + */ +import java.io.File; +import java.io.PrintWriter; + +import douyu.mvc.Context; +import douyu.mvc.Controller; + +import douyu.http.HttpRequest; +import douyu.http.UploadedFile; + +@Controller +public class FileUpload { + public void index(Context c) { + c.out("FileUpload.html"); + } + + public void upload(HttpRequest request, UploadedFile[] uploadedFiles, UploadedFile file1, String description, PrintWriter out) { + + out.println("说明: " + description); + out.println("file1: " + request.getUploadedFile("file1")); + out.println("uploadedFiles.length: " + uploadedFiles.length); + out.println(); + + if (uploadedFiles != null) { + for (UploadedFile uf : uploadedFiles) { + //注意这里,file1与uploadedFiles中的某一个元素指向同一个对象 + if (file1 == uf) { + out.println("这是文件1:"); + out.println(); + } + + out.println("大小 : " + uf.getSize() + " 字节"); + out.println("类型 : " + uf.getContentType()); + out.println("文件名: " + uf.getSimpleName()); + out.println("全名 : " + uf.getFullName()); + out.println("路径名: " + uf.getPathName()); + + out.println(); + out.println("文件内容:"); + out.println("--------------------------------------"); + out.println(uf.getContent()); + out.println("--------------------------------------"); + + out.println(); + + File file = new File("E:/Douyu/douyu-examples-classes/uploadedFiles", uf.getSimpleName()); + + try { + uf.saveTo(file); + out.println("已保存到: " + file); + } catch (Exception e) { + out.println("出错了: " + e); + } + out.println(); + out.println(); + } + } + } +} diff --git a/douyu-examples/src/FormExample.java b/douyu-examples/src/main/java/FormExample.java similarity index 100% rename from douyu-examples/src/FormExample.java rename to douyu-examples/src/main/java/FormExample.java diff --git a/douyu-examples/src/main/java/HelloWorld.java b/douyu-examples/src/main/java/HelloWorld.java new file mode 100644 index 0000000..f944667 --- /dev/null +++ b/douyu-examples/src/main/java/HelloWorld.java @@ -0,0 +1,29 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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. + */ +import java.io.PrintWriter; +import douyu.mvc.Controller; + +@Controller +public class HelloWorld { + // 用http://localhost:8080/HelloWorld 或 http://localhost:8080/HelloWorld.index 访问 + public void index(PrintWriter out) { + out.println("Hello Douyu World! Date: " + new java.util.Date()); + } +} \ No newline at end of file diff --git a/douyu-examples/src/main/java/ModelInjectExample.java b/douyu-examples/src/main/java/ModelInjectExample.java new file mode 100644 index 0000000..620e775 --- /dev/null +++ b/douyu-examples/src/main/java/ModelInjectExample.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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. + */ +import java.io.PrintWriter; + +import douyu.examples.models.Consumer; +import douyu.mvc.Controller; + +@Controller +public class ModelInjectExample { + //ModelInjectExample?consumer.name=zhh&consumer.address.country=china&consumer.address.city=hangzhou + + public void index(Consumer consumer, PrintWriter out) { + out.println("consumer=" + consumer); + } +} diff --git a/douyu-examples/src/RequestHeaderExample.java b/douyu-examples/src/main/java/RequestHeaderExample.java similarity index 100% rename from douyu-examples/src/RequestHeaderExample.java rename to douyu-examples/src/main/java/RequestHeaderExample.java diff --git a/douyu-examples/src/RequestInfoExample.java b/douyu-examples/src/main/java/RequestInfoExample.java similarity index 100% rename from douyu-examples/src/RequestInfoExample.java rename to douyu-examples/src/main/java/RequestInfoExample.java diff --git a/douyu-examples/src/RequestParamExample.java b/douyu-examples/src/main/java/RequestParamExample.java similarity index 98% rename from douyu-examples/src/RequestParamExample.java rename to douyu-examples/src/main/java/RequestParamExample.java index 6a8c61e..ed6a385 100644 --- a/douyu-examples/src/RequestParamExample.java +++ b/douyu-examples/src/main/java/RequestParamExample.java @@ -21,10 +21,9 @@ import java.io.PrintWriter; import java.util.ResourceBundle; +import douyu.examples.util.HTMLFilter; import douyu.http.HttpResponse; -import util.HTMLFilter; - /** * Example servlet showing request headers * diff --git a/douyu-examples/src/WebSocketExample.java b/douyu-examples/src/main/java/WebSocketExample.java similarity index 56% rename from douyu-examples/src/WebSocketExample.java rename to douyu-examples/src/main/java/WebSocketExample.java index 1140415..feed43e 100644 --- a/douyu-examples/src/WebSocketExample.java +++ b/douyu-examples/src/main/java/WebSocketExample.java @@ -1,3 +1,22 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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. + */ import java.io.IOException; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; diff --git a/douyu-examples/src/main/java/douyu/examples/HelloWorld.java b/douyu-examples/src/main/java/douyu/examples/HelloWorld.java new file mode 100644 index 0000000..273994f --- /dev/null +++ b/douyu-examples/src/main/java/douyu/examples/HelloWorld.java @@ -0,0 +1,36 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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 douyu.examples; + +import java.io.PrintWriter; +import douyu.mvc.Controller; + +@Controller +public class HelloWorld { + // 用http://localhost:8080/douyu/examples/HelloWorld 或 http://localhost:8080/douyu/examples/HelloWorld.index 访问 + public void index(PrintWriter out) { + out.println("index=> Hello Douyu World! Date: " + new java.util.Date()); + } + + // 用http://localhost:8080/douyu/examples/HelloWorld.hello访问 + public void hello(PrintWriter out) { + out.println("hello=> Hello Douyu World! Date: " + new java.util.Date()); + } +} \ No newline at end of file diff --git a/douyu-examples/src/main/java/douyu/examples/models/Address.java b/douyu-examples/src/main/java/douyu/examples/models/Address.java new file mode 100644 index 0000000..18c8dd0 --- /dev/null +++ b/douyu-examples/src/main/java/douyu/examples/models/Address.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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 douyu.examples.models; + +import douyu.mvc.Model; + +@Model +public class Address { + private String country; + private String city; + + public void set(String country, String city) { + this.country = country; + this.city = city; + } + + public String toString() { + return "Address[country=" + country + ", city=" + city + "]"; + } +} diff --git a/douyu-examples/src/main/java/douyu/examples/models/Consumer.java b/douyu-examples/src/main/java/douyu/examples/models/Consumer.java new file mode 100644 index 0000000..f8b0088 --- /dev/null +++ b/douyu-examples/src/main/java/douyu/examples/models/Consumer.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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 douyu.examples.models; + +import douyu.mvc.Model; + +@Model +public class Consumer { + private String name; + private Address address; + + public void set(String name, Address address) { + this.name = name; + this.address = address; + } + + public String toString() { + return "Consumer[name=" + name + ", address=" + address + "]"; + } +} diff --git a/douyu-startup/src/main/java/com/codefollower/douyu/startup/Test.java b/douyu-examples/src/main/java/douyu/examples/models/MyModel.java similarity index 60% rename from douyu-startup/src/main/java/com/codefollower/douyu/startup/Test.java rename to douyu-examples/src/main/java/douyu/examples/models/MyModel.java index 1bcb872..b2aefa5 100644 --- a/douyu-startup/src/main/java/com/codefollower/douyu/startup/Test.java +++ b/douyu-examples/src/main/java/douyu/examples/models/MyModel.java @@ -17,24 +17,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codefollower.douyu.startup; +package douyu.examples.models; -public class Test { - public static void main(String[] args) throws Exception { - Server server = new Server(); - Connector ajp = new AjpConnector(); - Connector http = new HttpConnector(); - // server.addConnectors(ajp, http); +import java.io.PrintWriter; - server.addConnector(ajp); - server.addConnector(http); +import douyu.mvc.Model; - String srcDir = "E:\\Douyu\\trunk\\douyu-examples\\WEB-INF\\src"; - String classesDir = "E:\\Douyu\\douyu-examples-classes"; - server.init("myApp", "UTF-8", srcDir, classesDir, true, null); +@Model +public class MyModel { + private int f1; + private String f2; + private MySubModel subModel; - server.start(); + public void set(int f1, String f2, MySubModel subModel, PrintWriter out) { + this.f1 = f1; + this.f2 = f2; + this.subModel = subModel; - System.out.println("http server started"); + out.println("invoke MyModel.set(): subModel.getParentModel()==this : " + (subModel.getParentModel() == this)); + out.println(); + } + + public String toString() { + return "MyModel[f1=" + f1 + ", f2=" + f2 + ", subModel=" + subModel + "]"; } } diff --git a/douyu-examples/src/main/java/douyu/examples/models/MySubModel.java b/douyu-examples/src/main/java/douyu/examples/models/MySubModel.java new file mode 100644 index 0000000..0232ba1 --- /dev/null +++ b/douyu-examples/src/main/java/douyu/examples/models/MySubModel.java @@ -0,0 +1,44 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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 douyu.examples.models; + +import douyu.mvc.Model; + +@Model +public class MySubModel { + + private int f1; + private String f2; + private MyModel parentModel; + + public void set(int f1, String f2, MyModel parentModel) { + this.f1 = f1; + this.f2 = f2; + this.parentModel = parentModel; + } + + public MyModel getParentModel() { + return parentModel; + } + + public String toString() { + return "MySubModel[f1=" + f1 + ", f2=" + f2 + "]"; + } +} diff --git a/douyu-examples/src/main/java/douyu/examples/start/Startup.java b/douyu-examples/src/main/java/douyu/examples/start/Startup.java new file mode 100644 index 0000000..d829df6 --- /dev/null +++ b/douyu-examples/src/main/java/douyu/examples/start/Startup.java @@ -0,0 +1,56 @@ +/* + * Copyright 2011 The Apache Software Foundation + * + * 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 douyu.examples.start; + +import java.io.File; + +//import com.codefollower.douyu.startup.AjpConnector; +import com.codefollower.douyu.startup.Connector; +import com.codefollower.douyu.startup.HttpConnector; +import com.codefollower.douyu.startup.Server; + +public class Startup { + + public static void main(String[] args) throws Exception { + Server server = new Server(); + // Connector ajp = new AjpConnector(); + Connector http = new HttpConnector(); + // server.addConnectors(ajp, http); + + // server.addConnector(ajp); + server.addConnector(http); + + String baseDir = new File(".").getCanonicalPath(); + String srcDir = new File(baseDir, "src/main/java").getCanonicalPath(); + System.out.println("src dir: " + srcDir); + String resourcesDir = new File(baseDir, "src/main/resources").getCanonicalPath(); + server.getConfig().addClassPath(resourcesDir); + System.out.println("resources dir: " + resourcesDir); + String classesDir = new File(baseDir, "douyu-examples-classes").getCanonicalPath(); + System.out.println("classes dir: " + classesDir); + + System.out.println(); + + server.init("douyu-examples", "UTF-8", srcDir, classesDir, true, null); + server.start(); + + System.out.println("Started douyu http server at port " + http.getPort()); + } +} diff --git a/douyu-examples/src/main/java/douyu/examples/util/HTMLFilter.java b/douyu-examples/src/main/java/douyu/examples/util/HTMLFilter.java new file mode 100644 index 0000000..7b7386a --- /dev/null +++ b/douyu-examples/src/main/java/douyu/examples/util/HTMLFilter.java @@ -0,0 +1,66 @@ +/* +* 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 douyu.examples.util; + +/** + * HTML filter utility. + * + * @author Craig R. McClanahan + * @author Tim Tye + * @version $Id: HTMLFilter.java 939315 2010-04-29 14:11:01Z kkolinko $ + */ + +public final class HTMLFilter { + + /** + * Filter the specified message string for characters that are sensitive + * in HTML. This avoids potential attacks caused by including JavaScript + * codes in the request URL that is often reported in error messages. + * + * @param message The message string to be filtered + */ + public static String filter(String message) { + + if (message == null) + return (null); + + char content[] = new char[message.length()]; + message.getChars(0, message.length(), content, 0); + StringBuilder result = new StringBuilder(content.length + 50); + for (int i = 0; i < content.length; i++) { + switch (content[i]) { + case '<': + result.append("<"); + break; + case '>': + result.append(">"); + break; + case '&': + result.append("&"); + break; + case '"': + result.append("""); + break; + default: + result.append(content[i]); + } + } + return (result.toString()); + + } + +} diff --git a/douyu-examples/src/DevTest.haha.vm b/douyu-examples/src/main/resources/DevTest.haha.vm similarity index 100% rename from douyu-examples/src/DevTest.haha.vm rename to douyu-examples/src/main/resources/DevTest.haha.vm diff --git a/douyu-examples/src/FileUpload.html b/douyu-examples/src/main/resources/FileUpload.html similarity index 100% rename from douyu-examples/src/FileUpload.html rename to douyu-examples/src/main/resources/FileUpload.html diff --git a/douyu-examples/src/FileUpload.vm b/douyu-examples/src/main/resources/FileUpload.vm similarity index 100% rename from douyu-examples/src/FileUpload.vm rename to douyu-examples/src/main/resources/FileUpload.vm diff --git a/douyu-examples/src/LocalStrings.properties b/douyu-examples/src/main/resources/LocalStrings.properties similarity index 100% rename from douyu-examples/src/LocalStrings.properties rename to douyu-examples/src/main/resources/LocalStrings.properties diff --git a/douyu-examples/src/ViewTest.ftl b/douyu-examples/src/main/resources/ViewTest.ftl similarity index 100% rename from douyu-examples/src/ViewTest.ftl rename to douyu-examples/src/main/resources/ViewTest.ftl diff --git a/douyu-examples/src/ViewTest.vm b/douyu-examples/src/main/resources/ViewTest.vm similarity index 100% rename from douyu-examples/src/ViewTest.vm rename to douyu-examples/src/main/resources/ViewTest.vm diff --git a/douyu-examples/src/WebSocketExample.html b/douyu-examples/src/main/resources/WebSocketExample.html similarity index 100% rename from douyu-examples/src/WebSocketExample.html rename to douyu-examples/src/main/resources/WebSocketExample.html diff --git a/douyu-examples/form.html b/douyu-examples/src/main/resources/form.html similarity index 100% rename from douyu-examples/form.html rename to douyu-examples/src/main/resources/form.html diff --git a/douyu-examples/index.html b/douyu-examples/src/main/resources/index.html similarity index 94% rename from douyu-examples/index.html rename to douyu-examples/src/main/resources/index.html index 54f0c78..687fcd0 100644 --- a/douyu-examples/index.html +++ b/douyu-examples/src/main/resources/index.html @@ -14,6 +14,10 @@ HelloWorld + +HelloWorld(With Package Name) + + FormExample diff --git a/douyu-examples/src/models/Address.java b/douyu-examples/src/models/Address.java deleted file mode 100644 index 4e69a23..0000000 --- a/douyu-examples/src/models/Address.java +++ /dev/null @@ -1,18 +0,0 @@ -package models; - -import douyu.mvc.Model; - -@Model -public class Address { - private String country; - private String city; - - public void set(String country, String city) { - this.country = country; - this.city = city; - } - - public String toString() { - return "Address[country=" + country + ", city=" + city + "]"; - } -} diff --git a/douyu-examples/src/models/Consumer.java b/douyu-examples/src/models/Consumer.java deleted file mode 100644 index 66c0c08..0000000 --- a/douyu-examples/src/models/Consumer.java +++ /dev/null @@ -1,18 +0,0 @@ -package models; - -import douyu.mvc.Model; - -@Model -public class Consumer { - private String name; - private Address address; - - public void set(String name, Address address) { - this.name = name; - this.address = address; - } - - public String toString() { - return "Consumer[name=" + name + ", address=" + address + "]"; - } -} diff --git a/douyu-examples/src/models/MyModel.java b/douyu-examples/src/models/MyModel.java deleted file mode 100644 index 00492bf..0000000 --- a/douyu-examples/src/models/MyModel.java +++ /dev/null @@ -1,25 +0,0 @@ -package models; - -import java.io.PrintWriter; - -import douyu.mvc.Model; - -@Model -public class MyModel { - private int f1; - private String f2; - private MySubModel subModel; - - public void set(int f1, String f2, MySubModel subModel, PrintWriter out) { - this.f1 = f1; - this.f2 = f2; - this.subModel = subModel; - - out.println("invoke MyModel.set(): subModel.getParentModel()==this : " + (subModel.getParentModel() == this)); - out.println(); - } - - public String toString() { - return "MyModel[f1=" + f1 + ", f2=" + f2 + ", subModel=" + subModel + "]"; - } -} diff --git a/douyu-examples/src/models/MySubModel.java b/douyu-examples/src/models/MySubModel.java deleted file mode 100644 index c4252ce..0000000 --- a/douyu-examples/src/models/MySubModel.java +++ /dev/null @@ -1,25 +0,0 @@ -package models; - -import douyu.mvc.Model; - -@Model -public class MySubModel { - - private int f1; - private String f2; - private MyModel parentModel; - - public void set(int f1, String f2, MyModel parentModel) { - this.f1 = f1; - this.f2 = f2; - this.parentModel = parentModel; - } - - public MyModel getParentModel() { - return parentModel; - } - - public String toString() { - return "MySubModel[f1=" + f1 + ", f2=" + f2 + "]"; - } -} diff --git a/douyu-examples/src/util/HTMLFilter.java b/douyu-examples/src/util/HTMLFilter.java deleted file mode 100644 index 019aa71..0000000 --- a/douyu-examples/src/util/HTMLFilter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -* 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 util; - -/** - * HTML filter utility. - * - * @author Craig R. McClanahan - * @author Tim Tye - * @version $Id: HTMLFilter.java 939315 2010-04-29 14:11:01Z kkolinko $ - */ - -public final class HTMLFilter { - - - /** - * Filter the specified message string for characters that are sensitive - * in HTML. This avoids potential attacks caused by including JavaScript - * codes in the request URL that is often reported in error messages. - * - * @param message The message string to be filtered - */ - public static String filter(String message) { - - if (message == null) - return (null); - - char content[] = new char[message.length()]; - message.getChars(0, message.length(), content, 0); - StringBuilder result = new StringBuilder(content.length + 50); - for (int i = 0; i < content.length; i++) { - switch (content[i]) { - case '<': - result.append("<"); - break; - case '>': - result.append(">"); - break; - case '&': - result.append("&"); - break; - case '"': - result.append("""); - break; - default: - result.append(content[i]); - } - } - return (result.toString()); - - } - - -} - diff --git a/douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings.properties diff --git a/douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings_es.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings_es.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings_es.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings_es.properties diff --git a/douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings_fr.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings_fr.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings_fr.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings_fr.properties diff --git a/douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings_ja.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings_ja.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/ssl/jsse/res/LocalStrings_ja.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/ssl/jsse/res/LocalStrings_ja.properties diff --git a/douyu-http/src/main/resources/org/douyu/http/util/LocalStrings.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/util/LocalStrings.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings.properties diff --git a/douyu-http/src/main/resources/org/douyu/http/util/LocalStrings_es.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings_es.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/util/LocalStrings_es.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings_es.properties diff --git a/douyu-http/src/main/resources/org/douyu/http/util/LocalStrings_fr.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings_fr.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/util/LocalStrings_fr.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings_fr.properties diff --git a/douyu-http/src/main/resources/org/douyu/http/util/LocalStrings_ja.properties b/douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings_ja.properties similarity index 100% rename from douyu-http/src/main/resources/org/douyu/http/util/LocalStrings_ja.properties rename to douyu-http/src/main/resources/com/codefollower/douyu/http/util/LocalStrings_ja.properties diff --git a/douyu-startup/src/main/java/com/codefollower/douyu/startup/HttpRequestHandler.java b/douyu-startup/src/main/java/com/codefollower/douyu/startup/HttpRequestHandler.java index d227e60..f2daaf6 100644 --- a/douyu-startup/src/main/java/com/codefollower/douyu/startup/HttpRequestHandler.java +++ b/douyu-startup/src/main/java/com/codefollower/douyu/startup/HttpRequestHandler.java @@ -285,7 +285,7 @@ private void executeAction(DouyuHttpRequest request, DouyuHttpResponse response) // 以'/'结尾说明是一个目录 if (path.endsWith("/")) { - return; // TODO + return; // TODO 处理静态资源 } // path格式: /packageName/controllerClassName.actionName @@ -312,7 +312,7 @@ private void executeAction(DouyuHttpRequest request, DouyuHttpResponse response) try { cr = config.getResourceLoader().loadContextClassResource(controllerClassName, javacOut); if (cr == null) { - return; // TODO + return; // TODO 处理静态资源 } dc = (DouyuContext) cr.loadedClass.newInstance(); if (isWebSocket) diff --git a/douyu-startup/src/main/java/com/codefollower/douyu/startup/Server.java b/douyu-startup/src/main/java/com/codefollower/douyu/startup/Server.java index d94ac13..0a23889 100644 --- a/douyu-startup/src/main/java/com/codefollower/douyu/startup/Server.java +++ b/douyu-startup/src/main/java/com/codefollower/douyu/startup/Server.java @@ -51,7 +51,7 @@ public void start() { c.start(config); } - private Config config; + private Config config = new Config(); public ResourceLoader getResourceLoader() { return config.getResourceLoader(); @@ -66,7 +66,6 @@ public Config getConfig() { public void init(String appName, String javacEncoding, String srcDir, String classesDir, boolean isDevMode, String vmpConfig) throws Exception { - config = new Config(); config.appName = appName; config.javacEncoding = javacEncoding; config.srcDir = srcDir; diff --git a/pom.xml b/pom.xml index 9cfc5fb..0b93dc0 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ douyu-netty douyu-startup douyu-logging + douyu-examples