moto web application
修訂 | 44d27d5dd6004d015e6251dc4aa1d96c10318604 (tree) |
---|---|
時間 | 2014-01-23 19:00:05 |
作者 | astoria-d <astoria-d@mail...> |
Commiter | astoria-d |
fix...
@@ -0,0 +1,6 @@ | ||
1 | +build/* | |
2 | +dist/* | |
3 | +deleted/* | |
4 | +this-proj-is-jsf2.0-named-annotation.txt | |
5 | +data-source-memo.txt | |
6 | +aaa.txt |
@@ -0,0 +1,25 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!-- | |
3 | + JBoss, Home of Professional Open Source | |
4 | + Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual | |
5 | + contributors by the @authors tag. See the copyright.txt in the | |
6 | + distribution for a full listing of individual contributors. | |
7 | + | |
8 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
9 | + you may not use this file except in compliance with the License. | |
10 | + You may obtain a copy of the License at | |
11 | + http://www.apache.org/licenses/LICENSE-2.0 | |
12 | + Unless required by applicable law or agreed to in writing, software | |
13 | + distributed under the License is distributed on an "AS IS" BASIS, | |
14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | + See the License for the specific language governing permissions and | |
16 | + limitations under the License. | |
17 | +--> | |
18 | +<!-- This file can be an empty text file (0 bytes) --> | |
19 | +<!-- We're declaring the schema to save you time if you do have to configure | |
20 | + this in the future --> | |
21 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
22 | + xsi:schemaLocation=" | |
23 | + http://java.sun.com/xml/ns/javaee | |
24 | + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
25 | +</beans> |
@@ -0,0 +1,258 @@ | ||
1 | +package motoSample; | |
2 | + | |
3 | +import java.io.Serializable; | |
4 | +import javax.faces.bean.ManagedBean; | |
5 | +import javax.faces.bean.ViewScoped; | |
6 | +import javax.faces.bean.ManagedProperty; | |
7 | +import javax.faces.context.FacesContext; | |
8 | +import javax.servlet.http.HttpServletRequest; | |
9 | + | |
10 | +import java.util.logging.Logger; | |
11 | +import javax.inject.Inject; | |
12 | +import java.sql.Connection; | |
13 | +import java.sql.SQLException; | |
14 | +import java.sql.ResultSet; | |
15 | +import java.sql.Statement; | |
16 | +import java.sql.PreparedStatement; | |
17 | + | |
18 | + | |
19 | +import java.util.ArrayList; | |
20 | +import javax.faces.model.SelectItem; | |
21 | +import javax.faces.event.ValueChangeEvent; | |
22 | +import javax.annotation.PostConstruct; | |
23 | +import javax.faces.component.html.HtmlCommandLink; | |
24 | + | |
25 | + | |
26 | +import java.util.Date; | |
27 | +import java.text.SimpleDateFormat; | |
28 | + | |
29 | + | |
30 | +@ManagedBean | |
31 | +@ViewScoped | |
32 | +public class ChatBean implements Serializable { | |
33 | + | |
34 | + @Inject | |
35 | + private Logger log; | |
36 | + | |
37 | + @Inject | |
38 | + private FacesContext context; | |
39 | + | |
40 | + //inject user bean | |
41 | + @ManagedProperty("#{userBean}") | |
42 | + private UserBean userBean; | |
43 | + | |
44 | + private String msg; | |
45 | + private String chatRoom; | |
46 | + private int oldestChatId; | |
47 | + private ArrayList<ChatMessage> msgList; | |
48 | + private HtmlCommandLink loadLink; | |
49 | + | |
50 | + public final static int LIST_LOAD_SIZE = 10; | |
51 | + | |
52 | + public void setMsg(String msg) { | |
53 | + this.msg = msg; | |
54 | + } | |
55 | + public String getMsg() { | |
56 | + return ""; | |
57 | + } | |
58 | + | |
59 | + public void setChatRoom(String chatRoom) { | |
60 | + this.chatRoom = chatRoom; | |
61 | + } | |
62 | + public String getChatRoom() { | |
63 | + return chatRoom; | |
64 | + } | |
65 | + public void setLoadLink(HtmlCommandLink loadLink) { | |
66 | + //log.info("setLoadLink"); | |
67 | + this.loadLink = loadLink; | |
68 | + } | |
69 | + public HtmlCommandLink getLoadLink() { | |
70 | + //log.info("getLoadLink"); | |
71 | + return loadLink; | |
72 | + } | |
73 | + | |
74 | + | |
75 | + //userBean injection. setter only. | |
76 | + public void setUserBean(UserBean userBean) { | |
77 | + this.userBean = userBean; | |
78 | + } | |
79 | + | |
80 | + ///chat list data | |
81 | + public class ChatMessage { | |
82 | + private String uname; | |
83 | + private String msg; | |
84 | + private String date; | |
85 | + public String getUname() { | |
86 | + return uname; | |
87 | + } | |
88 | + public String getMsg() { | |
89 | + return msg; | |
90 | + } | |
91 | + public String getDate() { | |
92 | + return date; | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + private void initMsgList(){ | |
97 | + log.info("initMsgList: " + chatRoom); | |
98 | + try { | |
99 | + Connection conn = Resources.getConnection(); | |
100 | + String uid = userBean.getUid(); | |
101 | + String sqlString = "select user_id, message, msg_date, msg_id from tb_chat_msg where chat_room=\'" + chatRoom +"\' order by msg_id desc"; | |
102 | + | |
103 | + Statement statement = conn.createStatement(); | |
104 | + ResultSet rs = statement.executeQuery(sqlString); | |
105 | + | |
106 | + if (msgList == null) { | |
107 | + msgList = new ArrayList<ChatMessage>(); | |
108 | + } | |
109 | + else { | |
110 | + msgList.clear(); | |
111 | + } | |
112 | + int load_cnt = 0; | |
113 | + while (rs.next()) { | |
114 | + ChatMessage m = new ChatMessage(); | |
115 | + m.uname = rs.getString("user_id"); | |
116 | + m.msg = rs.getString("message"); | |
117 | + m.date = rs.getString("msg_date"); | |
118 | + oldestChatId = rs.getInt("msg_id"); | |
119 | + msgList.add(0, m); | |
120 | + if (++load_cnt == LIST_LOAD_SIZE) | |
121 | + break; | |
122 | + } | |
123 | + log.info("oldestChatId: " + oldestChatId); | |
124 | + | |
125 | + rs.close(); | |
126 | + conn.close(); | |
127 | + } | |
128 | + catch (SQLException se) { | |
129 | + log.severe("sql err!!!"); | |
130 | + } | |
131 | + } | |
132 | + | |
133 | + public ArrayList<ChatMessage> getMsgList(){ | |
134 | + //log.info("getMsgList: " + chatRoom); | |
135 | + return msgList; | |
136 | + } | |
137 | + | |
138 | + public void doPost() { | |
139 | + //skip empty message.... | |
140 | + if (msg.equals("")) | |
141 | + return; | |
142 | + | |
143 | + Date d = new Date(); | |
144 | + SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); | |
145 | + | |
146 | + /* | |
147 | + log.info("user = " + userBean.getUid()); | |
148 | + log.info("chat room = " + chatRoom); | |
149 | + log.info("date = " + df.format(d)); | |
150 | + */ | |
151 | + | |
152 | + try { | |
153 | + Connection conn = Resources.getConnection(); | |
154 | + String sqlString = "insert into tb_chat_msg (user_id , chat_room , message , msg_date, deleted) values (?, ?, ?, ?, ?)"; | |
155 | + //log.info("sql = " + sqlString); | |
156 | + | |
157 | + PreparedStatement ps= conn.prepareStatement(sqlString); | |
158 | + ps.setString(1, userBean.getUid()); | |
159 | + ps.setString(2, chatRoom); | |
160 | + ps.setString(3, msg); | |
161 | + ps.setString(4, df.format(d)); | |
162 | + ps.setString(5, "false"); | |
163 | + | |
164 | + int cnt = ps.executeUpdate(); | |
165 | + log.info(cnt + " records inserted."); | |
166 | + | |
167 | + conn.close(); | |
168 | + | |
169 | + //add msgList... | |
170 | + ChatMessage m = new ChatMessage(); | |
171 | + m.uname = userBean.getUid(); | |
172 | + m.msg = msg; | |
173 | + m.date = df.format(d); | |
174 | + if (msgList == null) { | |
175 | + msgList = new ArrayList<ChatMessage>(); | |
176 | + } | |
177 | + msgList.add(m); | |
178 | + } | |
179 | + catch (SQLException se) { | |
180 | + log.severe("sql err!!!"); | |
181 | + } | |
182 | + | |
183 | + } | |
184 | + | |
185 | + public void loadOldMsg() { | |
186 | + //log.info("loadOldMsg oldestChatId: " + oldestChatId); | |
187 | + try { | |
188 | + Connection conn = Resources.getConnection(); | |
189 | + String uid = userBean.getUid(); | |
190 | + String sqlString = "select user_id, message, msg_date, msg_id from tb_chat_msg where chat_room=\'" | |
191 | + + chatRoom +"\' and msg_id < " + oldestChatId + " order by msg_id desc"; | |
192 | + | |
193 | + Statement statement = conn.createStatement(); | |
194 | + ResultSet rs = statement.executeQuery(sqlString); | |
195 | + | |
196 | + int load_cnt = 0; | |
197 | + while (rs.next()) { | |
198 | + ChatMessage m = new ChatMessage(); | |
199 | + m.uname = rs.getString("user_id"); | |
200 | + m.msg = rs.getString("message"); | |
201 | + m.date = rs.getString("msg_date"); | |
202 | + oldestChatId = rs.getInt("msg_id"); | |
203 | + msgList.add(0, m); | |
204 | + if (++load_cnt == LIST_LOAD_SIZE) | |
205 | + break; | |
206 | + } | |
207 | + log.info("oldestChatId: " + oldestChatId); | |
208 | + | |
209 | + rs.close(); | |
210 | + conn.close(); | |
211 | + if (load_cnt == 0) { | |
212 | + log.info("no more old msg..."); | |
213 | + loadLink.setDisabled(true); | |
214 | + loadLink.setValue("no more old messages...."); | |
215 | + } | |
216 | + } | |
217 | + catch (SQLException se) { | |
218 | + log.severe("sql err!!!"); | |
219 | + } | |
220 | + } | |
221 | + | |
222 | + void initLoadLink() { | |
223 | + loadLink.setDisabled(false); | |
224 | + loadLink.setValue("load old messages..."); | |
225 | + } | |
226 | + | |
227 | + ///chat room menu value changed listener | |
228 | + public void chatRoomChanged(ValueChangeEvent e) { | |
229 | + //chat room is changed. initialize the msg list. | |
230 | + chatRoom = e.getNewValue().toString(); | |
231 | + log.info("chat room changed: " + this.chatRoom); | |
232 | + initMsgList(); | |
233 | + initLoadLink(); | |
234 | + } | |
235 | + | |
236 | + @PostConstruct | |
237 | + public void postInit() { | |
238 | + log.info("postInit"); | |
239 | + //log.info("PostConstruct userBean: " + userBean); | |
240 | + //log.info("PostConstruct getFlights: " + userBean.getFlights()); | |
241 | + ArrayList<SelectItem> flights = userBean.getFlights(); | |
242 | + if (flights != null) { | |
243 | + chatRoom = userBean.getFlights().get(0).getValue().toString(); | |
244 | + | |
245 | + log.info("method: " + ((HttpServletRequest) context.getExternalContext().getRequest()).getMethod()); | |
246 | + if (((HttpServletRequest) context.getExternalContext().getRequest()).getMethod().equals("GET")) { | |
247 | + log.info("get access. init chat list"); | |
248 | + //in get access, the chat room is not selected.. | |
249 | + initMsgList(); | |
250 | + if (loadLink == null) | |
251 | + loadLink = new HtmlCommandLink(); | |
252 | + initLoadLink(); | |
253 | + } | |
254 | + } | |
255 | + | |
256 | + } | |
257 | + | |
258 | +} |
@@ -0,0 +1,63 @@ | ||
1 | +package motoSample; | |
2 | + | |
3 | +import java.io.IOException; | |
4 | +import java.util.logging.Logger; | |
5 | + | |
6 | + | |
7 | +import javax.servlet.Filter; | |
8 | +import javax.servlet.FilterChain; | |
9 | +import javax.servlet.FilterConfig; | |
10 | +import javax.servlet.ServletException; | |
11 | +import javax.servlet.ServletRequest; | |
12 | +import javax.servlet.ServletResponse; | |
13 | +import javax.servlet.http.HttpSession; | |
14 | +import javax.servlet.http.HttpServletRequest; | |
15 | +import javax.servlet.http.HttpServletResponse; | |
16 | + | |
17 | + | |
18 | +/** | |
19 | + * Filter checks if LoginBean has loginIn property set to true. | |
20 | + * If it is not set then request is being redirected to the login.xhml page. | |
21 | + * | |
22 | + * @author itcuties | |
23 | + * | |
24 | + */ | |
25 | +public class LoginFilter implements Filter { | |
26 | + Logger logger = Logger.getLogger(getClass().getName()); | |
27 | + | |
28 | + /** | |
29 | + * Checks if user is logged in. If not it redirects to the login.xhtml page. | |
30 | + */ | |
31 | + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | |
32 | + | |
33 | + HttpSession session = ((HttpServletRequest)request).getSession(); | |
34 | + // Get the userBean from session attribute | |
35 | + UserBean ubean = (UserBean)session.getAttribute("userBean"); | |
36 | + | |
37 | + logger.info("cpath:" + ((HttpServletRequest) request).getContextPath()); | |
38 | + logger.info("uri:" + ((HttpServletRequest) request).getRequestURI()); | |
39 | + | |
40 | + String req_url = ((HttpServletRequest) request).getRequestURI().replace(((HttpServletRequest) request).getContextPath(), ""); | |
41 | + logger.info("request_url:" + req_url); | |
42 | + session.setAttribute("request_url", req_url); | |
43 | + | |
44 | + // For the first application request there is no userBean in the session so user needs to log in | |
45 | + // For other requests userBean is present but we need to check if user has logged in successfully | |
46 | + if (ubean == null || !ubean.isLoggedIn()) { | |
47 | + String contextPath = ((HttpServletRequest)request).getContextPath(); | |
48 | + ((HttpServletResponse)response).sendRedirect(contextPath + "/login.jsf"); | |
49 | + } | |
50 | + | |
51 | + chain.doFilter(request, response); | |
52 | + | |
53 | + } | |
54 | + | |
55 | + public void init(FilterConfig config) throws ServletException { | |
56 | + // Nothing to do here! | |
57 | + } | |
58 | + | |
59 | + public void destroy() { | |
60 | + // Nothing to do here! | |
61 | + } | |
62 | + | |
63 | +} |
@@ -0,0 +1,63 @@ | ||
1 | +package motoSample; | |
2 | + | |
3 | +import javax.inject.Inject; | |
4 | +import javax.enterprise.inject.Produces; | |
5 | +import javax.enterprise.inject.spi.InjectionPoint; | |
6 | +import java.util.logging.Logger; | |
7 | + | |
8 | +import javax.enterprise.context.RequestScoped; | |
9 | +import javax.faces.context.FacesContext; | |
10 | + | |
11 | +import javax.naming.InitialContext; | |
12 | +import javax.naming.NamingException; | |
13 | +import javax.sql.DataSource; | |
14 | +import java.sql.Connection; | |
15 | +import java.sql.SQLException; | |
16 | + | |
17 | + | |
18 | +import javax.faces.context.FacesContext; | |
19 | +import javax.faces.context.ExternalContext; | |
20 | +import javax.servlet.http.HttpServletRequest; | |
21 | +import javax.servlet.http.HttpSession; | |
22 | + | |
23 | +public class Resources { | |
24 | + | |
25 | + private static Logger log = Logger.getLogger(Resources.class.getName()); | |
26 | + | |
27 | + //injection producer.... | |
28 | + @Produces | |
29 | + public Logger produceLog(InjectionPoint injectionPoint) { | |
30 | + return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); | |
31 | + } | |
32 | + | |
33 | + @Produces | |
34 | + @RequestScoped | |
35 | + public FacesContext produceFacesContext() { | |
36 | + return FacesContext.getCurrentInstance(); | |
37 | + } | |
38 | + | |
39 | + public static Connection getConnection() { | |
40 | + try { | |
41 | + InitialContext ctx = new InitialContext(); | |
42 | + DataSource ds = (DataSource) ctx.lookup("java:jboss/datasource/moto-web-app-ds"); | |
43 | + Connection conn = ds.getConnection(); | |
44 | + return conn; | |
45 | + } | |
46 | + catch (NamingException ne) { | |
47 | + log.severe("context not found!!!"); | |
48 | + } | |
49 | + catch (SQLException se) { | |
50 | + log.severe("sql get connection err!!!"); | |
51 | + } | |
52 | + return null; | |
53 | + } | |
54 | + | |
55 | + | |
56 | + public static HttpSession getSession() { | |
57 | + FacesContext context = FacesContext.getCurrentInstance(); | |
58 | + ExternalContext exContext = context.getExternalContext(); | |
59 | + HttpServletRequest req = (HttpServletRequest) exContext.getRequest(); | |
60 | + HttpSession session = req.getSession(); | |
61 | + return session; | |
62 | + } | |
63 | +} |
@@ -0,0 +1,134 @@ | ||
1 | +package motoSample; | |
2 | + | |
3 | +import java.io.Serializable; | |
4 | +import javax.faces.bean.ManagedBean; | |
5 | +import javax.faces.bean.SessionScoped; | |
6 | + | |
7 | +import java.util.logging.Logger; | |
8 | +import javax.inject.Inject; | |
9 | +import java.sql.Connection; | |
10 | +import java.sql.SQLException; | |
11 | +import java.sql.ResultSet; | |
12 | +import java.sql.Statement; | |
13 | + | |
14 | +import javax.servlet.http.HttpSession; | |
15 | + | |
16 | +import java.util.ArrayList; | |
17 | +import javax.faces.model.SelectItem; | |
18 | + | |
19 | +@ManagedBean | |
20 | +@SessionScoped | |
21 | +public class UserBean implements Serializable { | |
22 | + | |
23 | + @Inject | |
24 | + private Logger log; | |
25 | + | |
26 | + private String uid; | |
27 | + private String pwd; | |
28 | + private String uname; | |
29 | + | |
30 | + private ArrayList<SelectItem> flights; | |
31 | + | |
32 | + private boolean login = false; | |
33 | + | |
34 | + public boolean isLoggedIn() { | |
35 | + return login; | |
36 | + } | |
37 | + | |
38 | + public String getUid() { | |
39 | + return uid; | |
40 | + } | |
41 | + public String getPwd() { | |
42 | + return pwd; | |
43 | + } | |
44 | + public String getUname() { | |
45 | + return uname; | |
46 | + } | |
47 | + public void setUid(String uid) { | |
48 | + this.uid = uid; | |
49 | + } | |
50 | + public void setPwd(String pwd) { | |
51 | + this.pwd = pwd; | |
52 | + } | |
53 | + | |
54 | + public ArrayList<SelectItem> getFlights() { | |
55 | + return flights; | |
56 | + } | |
57 | + | |
58 | + private void initUserFlights(Connection conn) { | |
59 | + if (flights == null) { | |
60 | + flights = new ArrayList<SelectItem>(); | |
61 | + } | |
62 | + flights.clear(); | |
63 | + | |
64 | + try { | |
65 | + String sqlString = "select flight_name from tb_user_flights where user_id=\'" + uid +"\'"; | |
66 | + Statement statement = conn.createStatement(); | |
67 | + ResultSet rs = statement.executeQuery(sqlString); | |
68 | + while(rs.next()) { | |
69 | + String ft = rs.getString("flight_name"); | |
70 | + flights.add(new SelectItem(ft, ft)); | |
71 | + } | |
72 | + statement.close(); | |
73 | + } | |
74 | + catch (SQLException se) { | |
75 | + log.severe("sql flight err!!!"); | |
76 | + } | |
77 | + } | |
78 | + | |
79 | + public String doLogin() { | |
80 | + | |
81 | + try { | |
82 | + Connection conn = Resources.getConnection(); | |
83 | + | |
84 | + String sqlString = "select user_password, user_name from tb_users where user_id=\'" + uid +"\'"; | |
85 | + | |
86 | + Statement statement = conn.createStatement(); | |
87 | + statement.setQueryTimeout(30); // set timeout to 30 sec. | |
88 | + | |
89 | + ResultSet rs = statement.executeQuery(sqlString); | |
90 | + if(rs.next()) | |
91 | + { | |
92 | + // read the result set | |
93 | + String db_pwd = rs.getString("user_password"); | |
94 | + //log.info("pwd = " + db_pwd); | |
95 | + //log.info("name = " + rs.getString("user_name")); | |
96 | + | |
97 | + if (pwd.equals(db_pwd)) { | |
98 | + login = true; | |
99 | + this.uname = rs.getString("user_name"); | |
100 | + statement.close(); | |
101 | + | |
102 | + initUserFlights(conn); | |
103 | + | |
104 | + conn.close(); | |
105 | + | |
106 | + HttpSession session = Resources.getSession(); | |
107 | + | |
108 | + ///after login, redirect to the user specified url. | |
109 | + return session.getAttribute("request_url").toString() + "?faces-redirect=true"; | |
110 | + } | |
111 | + | |
112 | + } | |
113 | + else { | |
114 | + log.info("uid " + uid + "not found..."); | |
115 | + } | |
116 | + | |
117 | + statement.close(); | |
118 | + conn.close(); | |
119 | + } | |
120 | + catch (SQLException se) { | |
121 | + log.severe("sql err!!!"); | |
122 | + } | |
123 | + /* | |
124 | + */ | |
125 | + | |
126 | + return ""; | |
127 | + } | |
128 | + | |
129 | + public String doLogout() { | |
130 | + login = false; | |
131 | + return "/login.jsf"; | |
132 | + } | |
133 | + | |
134 | +} |
@@ -0,0 +1,15 @@ | ||
1 | +<?xml version="1.0"?> | |
2 | +<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" | |
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> | |
4 | + | |
5 | + <application> | |
6 | + <!-- push topic initializer registration --> | |
7 | + <!-- not needed ???? | |
8 | + system-event-listener> | |
9 | + <system-event-listener-class>motoSample.TopicsInitializer</system-event-listener-class> | |
10 | + <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class> | |
11 | + </system-event-listener --> | |
12 | + </application> | |
13 | + | |
14 | + | |
15 | +</faces-config> | |
\ No newline at end of file |
@@ -0,0 +1,9 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<jboss-deployment-structure> | |
3 | + <deployment> | |
4 | + <dependencies> | |
5 | + <module name="org.w3c.css.sac" /> | |
6 | + <module name="net.sourceforge.cssparser" /> | |
7 | + </dependencies> | |
8 | + </deployment> | |
9 | +</jboss-deployment-structure> |
@@ -0,0 +1,10 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | + | |
3 | +<datasources xmlns="http://www.jboss.org/ironjacamar/schema" | |
4 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
5 | + xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd"> | |
6 | + <datasource jndi-name="java:jboss/datasource/moto-web-app-ds" pool-name="moto-web-app-ds-pool" enabled="true" > | |
7 | + <connection-url>jdbc:sqlite:C:/Users/dmotooka/AppData/sqlite/moto-test2.db</connection-url> | |
8 | + <driver>sqlite</driver> | |
9 | + </datasource> | |
10 | +</datasources> |
@@ -0,0 +1,26 @@ | ||
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 | +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | +<html xmlns="http://www.w3.org/1999/xhtml" | |
4 | + xmlns:h="http://java.sun.com/jsf/html" | |
5 | + xmlns:composite="http://java.sun.com/jsf/composite" | |
6 | + xmlns:f="http://java.sun.com/jsf/core" | |
7 | + xmlns:ui="http://java.sun.com/jsf/facelets"> | |
8 | +<h:head> | |
9 | +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
10 | + | |
11 | +<title> | |
12 | + <ui:insert name="pageTitle">JFS Template</ui:insert> | |
13 | +</title> | |
14 | +</h:head> | |
15 | + | |
16 | +<body> | |
17 | + | |
18 | + <div id="pageHeader" style="FONT-FAMILY: 'Britannic Bold'; BACKGROUND-COLOR: #800000; color:#FFF"> | |
19 | + <h1>moto chat app</h1> | |
20 | + </div> | |
21 | + | |
22 | + <!-- c. 各ページで異なるコンテンツを表示する領域 --> | |
23 | + <ui:insert name="body">ページごとのコンテンツ</ui:insert> | |
24 | + | |
25 | +</body> | |
26 | +</html> | |
\ No newline at end of file |
@@ -0,0 +1,68 @@ | ||
1 | +<?xml version='1.0' encoding='UTF-8'?> | |
2 | + | |
3 | +<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_3_0.xsd" | |
4 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | |
5 | + version="3.0"> | |
6 | + | |
7 | + <display-name>hellojsf</display-name> | |
8 | + <description>JSF start guide</description> | |
9 | + | |
10 | + <!-- Faces Servlet --> | |
11 | + <servlet> | |
12 | + <servlet-name>Faces Servlet</servlet-name> | |
13 | + <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> | |
14 | + <load-on-startup>1</load-on-startup> | |
15 | + </servlet> | |
16 | + | |
17 | + | |
18 | + <!-- Faces Servlet Mapping --> | |
19 | + <servlet-mapping> | |
20 | + <servlet-name>Faces Servlet</servlet-name> | |
21 | + <url-pattern>*.jsf</url-pattern> | |
22 | + </servlet-mapping> | |
23 | + | |
24 | + | |
25 | + <!-- Login filter --> | |
26 | + <filter> | |
27 | + <filter-name>LoginFilter</filter-name> | |
28 | + <filter-class>motoSample.LoginFilter</filter-class> | |
29 | + </filter> | |
30 | + <!-- all files under /secured/* are filtered by login filter --> | |
31 | + <filter-mapping> | |
32 | + <filter-name>LoginFilter</filter-name> | |
33 | + <url-pattern>/secured/*</url-pattern> | |
34 | + </filter-mapping> | |
35 | + | |
36 | + <!-- block .xhtml access --> | |
37 | + <security-constraint> | |
38 | + <display-name>XHTML Security</display-name> | |
39 | + <web-resource-collection> | |
40 | + <web-resource-name>Protected Area</web-resource-name> | |
41 | + <url-pattern>*.xhtml</url-pattern> | |
42 | + </web-resource-collection> | |
43 | + <auth-constraint> | |
44 | + </auth-constraint> | |
45 | + </security-constraint> | |
46 | + | |
47 | + <!-- enable richfaces push/jms --> | |
48 | + <context-param> | |
49 | + <param-name>org.richfaces.push.initializeOnStartup</param-name> | |
50 | + <param-value>true</param-value> | |
51 | + </context-param> | |
52 | + <context-param> | |
53 | + <param-name>org.richfaces.push.jms.enabled</param-name> | |
54 | + <param-value>false</param-value> | |
55 | + </context-param> | |
56 | + <context-param> | |
57 | + <param-name>org.richfaces.push.jms.connectionUsername</param-name> | |
58 | + <param-value>jmsuser</param-value> | |
59 | + </context-param> | |
60 | + <context-param> | |
61 | + <param-name>org.richfaces.push.jms.connectionPassword</param-name> | |
62 | + <param-value>jmspassword</param-value> | |
63 | + </context-param> | |
64 | + <session-config> | |
65 | + <session-timeout>15</session-timeout> | |
66 | + </session-config> | |
67 | + | |
68 | +</web-app> |
@@ -0,0 +1,90 @@ | ||
1 | +<project default="dist" basedir="."> | |
2 | + | |
3 | +<!-- TODO: set project name here... --> | |
4 | + <property name="proj_name" value="moto_web_app" /> | |
5 | + | |
6 | + <!-- set global properties for this build --> | |
7 | + <property environment="env"/> | |
8 | + <property name="top" value="."/> | |
9 | + <property name="build" value="build"/> | |
10 | + <property name="dist" value="dist"/> | |
11 | + <property name="war_dir" value="${dist}/lib"/> | |
12 | + <property name="war_file" value="${war_dir}/${proj_name}.war"/> | |
13 | + | |
14 | + <property name="webinf" value="${top}/WEB-INF"/> | |
15 | + <property name="web.xml" value="${webinf}/web.xml"/> | |
16 | + <property name="classes" value="${webinf}/classes"/> | |
17 | + <property name="lib" value="${top}/WEB-INF/lib"/> | |
18 | + <property name="deploy" value="${env.JBOSS_HOME}/standalone/deployments"/> | |
19 | + <property name="faceletsrc" value="."/> | |
20 | + <property name="javasrc" value="${classes}"/> | |
21 | + | |
22 | + | |
23 | +<!-- JSF jar files --> | |
24 | + <property name="jsf" value="${env.JBOSS_HOME}\modules\javax\faces\api\main\jboss-jsf-api_2.1_spec-2.0.0.Final.jar"/> | |
25 | + <property name="inject" value="${env.JBOSS_HOME}\modules\javax\inject\api\main\javax.inject-1.jar"/> | |
26 | + <property name="servlet" value="${env.JBOSS_HOME}\modules\javax\servlet\api\main\jboss-servlet-api_3.0_spec-1.0.0.Final.jar"/> | |
27 | + <property name="cdi" value="${env.JBOSS_HOME}\modules\javax\enterprise\api\main\cdi-api-1.0-SP4.jar"/> | |
28 | + <property name="richfaces" value="${lib}\richfaces-components-api-4.3.4.Final.jar:${lib}\richfaces-components-ui-4.3.4.Final.jar:${lib}\richfaces-core-api-4.3.4.Final.jar:${lib}\richfaces-core-impl-4.3.4.Final.jar"/> | |
29 | + <property name="jms" value="${env.JBOSS_HOME}\modules\javax\jms\api\main\jboss-jms-api_1.1_spec-1.0.0.Final.jar"/> | |
30 | + | |
31 | + <target name="clean"> | |
32 | + <!-- Delete our the ${build} and ${dist} directory trees --> | |
33 | + <delete dir="${build}"/> | |
34 | + <delete dir="${dist}"/> | |
35 | + <delete dir="${war_dir}"/> | |
36 | + </target> | |
37 | + | |
38 | + <target name="init"> | |
39 | + <!-- Create the build directory structure used by compile and dist --> | |
40 | + <mkdir dir="${build}"/> | |
41 | + <mkdir dir="${dist}"/> | |
42 | + <mkdir dir="${war_dir}"/> | |
43 | + </target> | |
44 | + | |
45 | + <target name="compile" depends="init"> | |
46 | + <!-- Compile the java code from ${src} into ${build} --> | |
47 | + <javac | |
48 | + srcdir="${javasrc}" | |
49 | + destdir="${build}" | |
50 | + debug="true" | |
51 | + classpath="${jsf}:${inject}:${servlet}:${cdi}:${richfaces}:${jms}"/> | |
52 | + | |
53 | + </target> | |
54 | + | |
55 | + <target name="dist" depends="compile"> | |
56 | + | |
57 | + <!-- Put everything in a war file --> | |
58 | + <war warfile="${war_file}" webxml="${web.xml}"> | |
59 | + <!-- include all facelets in root level, and all .properties files anywhere --> | |
60 | + | |
61 | + <fileset dir="${faceletsrc}"> | |
62 | + <include name="**/*.xhtml"/> | |
63 | + <include name="**/*.properties"/> | |
64 | + </fileset> | |
65 | + | |
66 | + <!-- include all .xml config files, | |
67 | + but not web.xml (that's handled separately) --> | |
68 | + <webinf dir="${webinf}"> | |
69 | + <include name="*.xml"/> | |
70 | + <include name="templates/*.xhtml"/> | |
71 | + <exclude name="web.xml"/> | |
72 | + </webinf> | |
73 | + | |
74 | + <!-- include all libraries in WEB-INF/lib --> | |
75 | + <lib dir="${lib}"/> | |
76 | + | |
77 | + <!-- include all compiled classes --> | |
78 | + <classes dir="${build}"/> | |
79 | + | |
80 | + </war> | |
81 | + </target> | |
82 | + | |
83 | + <target name="deploy"> | |
84 | + <!-- Copy the war file to the JBoss deploy directory --> | |
85 | + <copy file="${war_file}" todir="${deploy}"/> | |
86 | + </target> | |
87 | + | |
88 | + <target name="all" depends="clean,dist,deploy"/> | |
89 | + | |
90 | +</project> |
@@ -0,0 +1,24 @@ | ||
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | +<html xmlns="http://www.w3.org/1999/xhtml" | |
3 | + xmlns:h="http://java.sun.com/jsf/html" | |
4 | + xmlns:f="http://java.sun.com/jsf/core" | |
5 | + xmlns:ui="http://java.sun.com/jsf/facelets"> | |
6 | + | |
7 | + <ui:composition template="/WEB-INF/templates/moto-template.xhtml"> | |
8 | + <ui:define name="pageTitle">log in</ui:define> | |
9 | + <ui:define name="pageHeader" /> | |
10 | + <ui:define name="body"> | |
11 | + | |
12 | + <h:form> | |
13 | + | |
14 | +user id : <h:inputText value="#{userBean.uid}"/> | |
15 | +password : <h:inputSecret value="#{userBean.pwd}"/> | |
16 | + | |
17 | +<h:commandButton value="login" action="#{userBean.doLogin}" /> | |
18 | + | |
19 | + | |
20 | + </h:form> | |
21 | + </ui:define> | |
22 | + </ui:composition> | |
23 | + | |
24 | +</html> | |
\ No newline at end of file |
@@ -0,0 +1,93 @@ | ||
1 | +1. download guava module from google web site. | |
2 | + then place it in 010.jal-mobile-dev\ws\moto_web_app\WEB-INF\lib directory. | |
3 | + | |
4 | + | |
5 | +1.1 download atomsphere library and put them in the web-inf/lib directory. | |
6 | +atmosphere-compat-jbossweb-1.0.17.jar | |
7 | +atmosphere-runtime-1.0.17.jar | |
8 | +atmosphere-compat-tomcat-1.0.17.jar | |
9 | +atmosphere-compat-tomcat7-1.0.17.jar | |
10 | + | |
11 | + | |
12 | +2. css/parse module dependency setting | |
13 | + create jboss-deployment-structure.xml in the 010.jal-mobile-dev\ws\moto_web_app\WEB-INF\lib directory as follows | |
14 | + | |
15 | + | |
16 | +----------- | |
17 | +<?xml version="1.0" encoding="UTF-8"?> | |
18 | +<jboss-deployment-structure> | |
19 | + <deployment> | |
20 | + <dependencies> | |
21 | + <module name="org.w3c.css.sac" /> | |
22 | + <module name="net.sourceforge.cssparser" /> | |
23 | + </dependencies> | |
24 | + </deployment> | |
25 | +</jboss-deployment-structure> | |
26 | + | |
27 | + | |
28 | +3. enable jms in WEB-INF/web.xml | |
29 | + | |
30 | +----------- | |
31 | +<?xml version='1.0' encoding='UTF-8'?> | |
32 | + | |
33 | +<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_3_0.xsd" | |
34 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | |
35 | + version="3.0"> | |
36 | + ^^^^^^^^^^^^^^ | |
37 | +: | |
38 | +: | |
39 | +: | |
40 | +: | |
41 | + <!-- enable richfaces push/jms --> | |
42 | + <context-param> | |
43 | + <param-name>org.richfaces.push.initializeOnStartup</param-name> | |
44 | + <param-value>true</param-value> | |
45 | + </context-param> | |
46 | + <context-param> | |
47 | + <param-name>org.richfaces.push.jms.disabled</param-name> | |
48 | + <param-value>true</param-value> | |
49 | + </context-param> | |
50 | + <context-param> | |
51 | + <param-name>org.richfaces.push.jms.connectionUsername</param-name> | |
52 | + <param-value>jmsuser</param-value> | |
53 | + </context-param> | |
54 | + <context-param> | |
55 | + <param-name>org.richfaces.push.jms.connectionPassword</param-name> | |
56 | + <param-value>jmspassword</param-value> | |
57 | + </context-param> | |
58 | +: | |
59 | +: | |
60 | +: | |
61 | +: | |
62 | + | |
63 | + | |
64 | + | |
65 | +!!!!!! ========== 4.1 nor 4.2 NOT required????? =========== | |
66 | +4.1 topic initialization | |
67 | +Add topic initializer class in the project and WEB-INF/faces-config.xml as follows. | |
68 | + | |
69 | +------------ | |
70 | +<?xml version="1.0"?> | |
71 | +<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" | |
72 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> | |
73 | + | |
74 | + <application> | |
75 | + <system-event-listener> | |
76 | + <system-event-listener-class>motoSample.TopicsInitializer</system-event-listener-class> | |
77 | + <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class> | |
78 | + </system-event-listener> | |
79 | + </application> | |
80 | + | |
81 | + | |
82 | +</faces-config> | |
83 | + | |
84 | + | |
85 | +4.2 jms topic add | |
86 | + | |
87 | +# jms-topic add --topic-address=motoTestTopic --entries=topic/motoTest,java:jboss/exported/jms/topic/motoTest | |
88 | + | |
89 | +# cd /subsystem=messaging/hornetq-server=default/jms-queue=testQueue | |
90 | +# jms-topic remove --topic-address=motoTestTopic | |
91 | + | |
92 | + | |
93 | + |