Author: alexsmirnov
Date: 2008-11-12 15:27:42 -0500 (Wed, 12 Nov 2008)
New Revision: 11125
Added:
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/ajax-web.xml
Removed:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/collections/
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
Log:
Merge trunk changes
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -20,9 +20,13 @@
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
import javax.faces.webapp.FacesServlet;
+import javax.servlet.Filter;
import org.junit.After;
import org.junit.Before;
+import org.richfaces.test.staging.FilterContainer;
+import org.richfaces.test.staging.RequestChain;
+import org.richfaces.test.staging.ServletContainer;
/**
* @author asmirnov
@@ -51,7 +55,7 @@
contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
this.getClass().getClassLoader());
- InputStream stream = FacesServerTest.class
+ InputStream stream = this.getClass()
.getResourceAsStream("logging.properties");
if (null != stream) {
try {
@@ -67,24 +71,23 @@
}
}
facesServer = new StagingServer();
- facesServer.addServlet("*.jsf", new FacesServlet());
- facesServer.addResource("/WEB-INF/web.xml",
- "org/richfaces/test/web.xml");
- facesServer.addResource("/WEB-INF/faces-config.xml",
- "org/richfaces/test/faces-config.xml");
- facesServer.addInitParameter(
- StateManager.STATE_SAVING_METHOD_PARAM_NAME,
- StateManager.STATE_SAVING_METHOD_SERVER);
- facesServer.addInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME,
- ".xhtml");
- facesServer.addInitParameter("com.sun.faces.validateXml", "true");
- facesServer.addInitParameter("com.sun.faces.verifyObjects",
"true");
+ setupFacesServlet();
+ setupFacesListener();
+ setupWebContent();
+ facesServer.init();
+ }
+
+ /**
+ *
+ */
+ protected void setupFacesListener() {
EventListener listener = null;
try {
Class<? extends EventListener> listenerClass = contextClassLoader
.loadClass("com.sun.faces.config.ConfigureListener")
.asSubclass(EventListener.class);
listener = listenerClass.newInstance();
+ setupSunFaces();
} catch (ClassNotFoundException e) {
// No JSF RI listener
Class<? extends EventListener> listenerClass;
@@ -94,6 +97,7 @@
"org.apache.myfaces.webapp.StartupServletContextListener")
.asSubclass(EventListener.class);
listener = listenerClass.newInstance();
+ setupMyFaces();
} catch (ClassNotFoundException e1) {
throw new TestException("No JSF listeners have been found", e1);
} catch (Exception e2) {
@@ -103,11 +107,51 @@
throw new TestException("Error instantiate JSF RI listener", e);
}
facesServer.addWebListener(listener);
- setupWebContent(facesServer);
- facesServer.init();
}
- protected void setupWebContent(StagingServer facesServer){
+ /**
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ protected void setupFacesServlet() {
+ ServletContainer facesServletContainer = new ServletContainer("*.jsf", new
FacesServlet());
+ facesServletContainer.setName("Faces Servlet");
+ try {
+ // Check for an ajax4jsf filter.
+ Class<? extends Filter> ajaxFilterClass = contextClassLoader
+ .loadClass("org.ajax4jsf.Filter")
+ .asSubclass(Filter.class);
+ Filter ajaxFilter = ajaxFilterClass.newInstance();
+ FilterContainer filterContainer = new
FilterContainer(ajaxFilter,facesServletContainer);
+ filterContainer.setName("ajax4jsf");
+ facesServer.addResource("/WEB-INF/web.xml",
+ "org/richfaces/test/ajax-web.xml");
+ facesServer.addServlet(filterContainer);
+ } catch (ClassNotFoundException e) {
+ // No Richfaces filter, uses servlet directly.
+ facesServer.addResource("/WEB-INF/web.xml",
+ "org/richfaces/test/web.xml");
+ facesServer.addServlet(facesServletContainer);
+ } catch (Exception e) {
+ throw new TestException(e);
+ }
+ facesServer.addInitParameter(
+ StateManager.STATE_SAVING_METHOD_PARAM_NAME,
+ StateManager.STATE_SAVING_METHOD_SERVER);
+ facesServer.addInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME,
+ ".xhtml");
+ }
+
+ protected void setupMyFaces() {
+ // Do nothing by default.
+ }
+
+ protected void setupSunFaces() {
+ facesServer.addInitParameter("com.sun.faces.validateXml", "true");
+ facesServer.addInitParameter("com.sun.faces.verifyObjects",
"true");
+ }
+
+ protected void setupWebContent(){
}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -4,6 +4,7 @@
package org.richfaces.test;
import com.gargoylesoftware.htmlunit.BrowserVersion;
+import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebConnection;
@@ -24,6 +25,7 @@
public LocalWebClient(StagingServer server) {
super();
this.server = server;
+ setAjaxController(new NicelyResynchronizingAjaxController());
}
/**
@@ -32,6 +34,7 @@
public LocalWebClient(StagingServer server,BrowserVersion browserVersion) {
super(browserVersion);
this.server = server;
+ setAjaxController(new NicelyResynchronizingAjaxController());
}
/**
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -8,7 +8,9 @@
import javax.servlet.ServletException;
import org.apache.commons.httpclient.NameValuePair;
+import org.richfaces.test.staging.StagingHttpRequest;
+import com.gargoylesoftware.htmlunit.FormEncodingType;
import com.gargoylesoftware.htmlunit.WebConnection;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
@@ -29,6 +31,18 @@
for (NameValuePair param : settings.getRequestParameters()) {
connection.addRequestParameter(param.getName(), param.getValue());
}
+ HttpMethod httpMethod = HttpMethod.valueOf(settings.getHttpMethod().toString());
+ connection.setMethod(httpMethod);
+ StagingHttpRequest request = connection.getRequest();
+ request.setCharacterEncoding(settings.getCharset());
+ String body = settings.getRequestBody();
+ String contentType = settings.getEncodingType().getName();
+ request.setRequestBody(body);
+ request.setContentType(contentType);
+ request.addHeaders(settings.getAdditionalHeaders());
+ if(null != body &&
FormEncodingType.URL_ENCODED.getName().equals(contentType)){
+ connection.parseFormParameters(body);
+ }
try {
connection.execute();
} catch (ServletException e) {
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -8,8 +8,10 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map.Entry;
import org.apache.commons.httpclient.NameValuePair;
@@ -75,7 +77,12 @@
}
public List<NameValuePair> getResponseHeaders() {
- // TODO Auto-generated method stub
- return Collections.emptyList();
+ ArrayList<NameValuePair> headers = new ArrayList<NameValuePair>(10);
+ for (Entry<String, String[]> entry :
serverConnection.getResponse().getHeaders().entrySet()) {
+ for (String value : entry.getValue()) {
+ headers.add(new NameValuePair(entry.getKey(),value));
+ }
+ };
+ return headers;
}
}
\ No newline at end of file
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -4,15 +4,18 @@
package org.richfaces.test;
import java.io.IOException;
+import java.io.InvalidClassException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
@@ -40,6 +43,8 @@
*/
public class StagingConnection {
+ private static final Logger log = ServerLogger.SERVER.getLogger();
+
private final StagingServer server;
final URL url;
@@ -63,7 +68,7 @@
private final String servletPath;
private boolean finished = false;
-
+
private boolean started = false;
private String queryString;
@@ -84,22 +89,37 @@
this.pathInfo);
this.request.setAttribute("javax.servlet.include.servlet_path",
this.servletPath);
- queryString = url.getQuery();
- if (null != queryString) {
- String[] queryParams = queryString.split("&");
- for (int i = 0; i < queryParams.length; i++) {
- String par = queryParams[i];
- int eqIndex = par.indexOf('=');
- if(eqIndex>=0){
- addRequestParameter(par.substring(0, eqIndex),
par.substring(eqIndex+1));
- } else {
- addRequestParameter(par, null);
- }
- }
- }
+ setQueryString(url.getQuery());
+ if (null != getQueryString()) {
+ parseFormParameters(queryString);
+ }
}
+ public void parseFormParameters(String queryString) {
+ String[] queryParams = queryString.split("&");
+ for (int i = 0; i < queryParams.length; i++) {
+ try {
+ String par = queryParams[i];
+ int eqIndex = par.indexOf('=');
+ if (eqIndex >= 0) {
+ // TODO - decode url-decoded values.
+ String name = URLDecoder.decode(par.substring(0, eqIndex),
+ request.getCharacterEncoding());
+ String value = URLDecoder.decode(
+ par.substring(eqIndex + 1), request
+ .getCharacterEncoding());
+ addRequestParameter(name, value);
+ } else {
+ addRequestParameter(URLDecoder.decode(par, request
+ .getCharacterEncoding()), null);
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new TestException(e);
+ }
+ }
+ }
+
/**
* @return the finished
*/
@@ -114,8 +134,6 @@
return started;
}
-
-
private void checkStarted() {
if (!isFinished()) {
throw new IllegalStateException("request have not been started");
@@ -124,7 +142,8 @@
public void execute() throws ServletException, IOException {
if (isStarted() || isFinished()) {
- throw new IllegalStateException("request have already been executed");
+ throw new IllegalStateException(
+ "request have already been executed");
}
start();
this.servlet.execute(request, response);
@@ -137,6 +156,9 @@
}
public void start() {
+ log.fine("start " + getMethod() + " request processing for file "
+ + url.getFile());
+ log.fine("request parameters: " + requestParameters);
server.requestStarted(request);
started = true;
}
@@ -348,21 +370,21 @@
public HttpSession getSession(boolean create) {
return server.getSession(create);
}
-
+
@Override
public RequestDispatcher getRequestDispatcher(String path) {
RequestDispatcher dispatcher = null;
- if(!path.startsWith("/")){
+ if (!path.startsWith("/")) {
try {
- URL absoluteUrl = new URL(url,path);
+ URL absoluteUrl = new URL(url, path);
path = absoluteUrl.getFile();
} catch (MalformedURLException e) {
return null;
}
}
final RequestChain dispatchedServlet = server.getServlet(path);
- if(null != dispatchedServlet){
- dispatcher = new RequestDispatcher(){
+ if (null != dispatchedServlet) {
+ dispatcher = new RequestDispatcher() {
public void forward(ServletRequest request,
ServletResponse response) throws ServletException,
@@ -376,7 +398,7 @@
IOException {
dispatchedServlet.execute(request, response);
}
-
+
};
}
return dispatcher;
@@ -384,20 +406,20 @@
@Override
protected void attributeAdded(String name, Object o) {
- server.requestAttributeAdded(this,name,o);
-
+ server.requestAttributeAdded(this, name, o);
+
}
@Override
protected void attributeRemoved(String name, Object removed) {
- server.requestAttributeRemoved(this,name,removed);
-
+ server.requestAttributeRemoved(this, name, removed);
+
}
@Override
protected void attributeReplaced(String name, Object o) {
- server.requestAttributeReplaced(this,name,o);
-
+ server.requestAttributeReplaced(this, name, o);
+
}
}
@@ -437,4 +459,19 @@
return response.getErrorMessage();
}
+ /**
+ * @param queryString
+ * the queryString to set
+ */
+ public void setQueryString(String queryString) {
+ this.queryString = queryString;
+ }
+
+ /**
+ * @return the queryString
+ */
+ public String getQueryString() {
+ return queryString;
+ }
+
}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -31,11 +31,10 @@
import org.richfaces.test.staging.ServerResource;
import org.richfaces.test.staging.ServerResourcePath;
import org.richfaces.test.staging.ServerResourcesDirectory;
-import org.richfaces.test.staging.RequestChain;
import org.richfaces.test.staging.ServletContainer;
-import org.richfaces.test.staging.StaticServlet;
import org.richfaces.test.staging.StagingHttpSession;
import org.richfaces.test.staging.StagingServletContext;
+import org.richfaces.test.staging.StaticServlet;
/**
@@ -200,7 +199,7 @@
return getSession(true);
}
- public HttpSession getSession(boolean create){
+ public synchronized HttpSession getSession(boolean create){
if(null == this.session && create){
this.session = new ServerHttpSession();
// inform session listeners.
@@ -262,6 +261,7 @@
}
});
session.destroy();
+ session = null;
}
// Inform listeners
final ServletContextEvent event = new ServletContextEvent(context);
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -15,15 +15,17 @@
import javax.servlet.ServletResponse;
public class FilterContainer implements RequestChain {
-
+
private final Filter filter;
-
+
private final RequestChain next;
-
- private String name = "Default";
+ private String name = "Default";
+
private final Map<String, String> initParameters;
+ private boolean initialized = false;
+
/**
* @param filter
* @param next
@@ -34,23 +36,31 @@
this.initParameters = new HashMap<String, String>();
}
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
public void execute(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
- FilterChain chain = new FilterChain(){
+ FilterChain chain = new FilterChain() {
public void doFilter(ServletRequest request,
ServletResponse response) throws IOException,
ServletException {
next.execute(request, response);
-
+
}
-
+
};
filter.doFilter(request, response, chain);
-
+
}
-
- public void addInitParameter(String name, String value){
+
+ public void addInitParameter(String name, String value) {
initParameters.put(name, value);
}
@@ -59,32 +69,39 @@
}
public void destroy() {
- next.destroy();
- filter.destroy();
+ if (initialized) {
+ next.destroy();
+ filter.destroy();
+ initialized = false;
+ }
}
- public void init(final StagingServletContext context) throws ServletException {
- filter.init(new FilterConfig(){
+ public void init(final StagingServletContext context)
+ throws ServletException {
+ if (!initialized) {
+ filter.init(new FilterConfig() {
- public String getFilterName() {
- return name;
- }
+ public String getFilterName() {
+ return name;
+ }
- public String getInitParameter(String name) {
- return initParameters.get(name);
- }
+ public String getInitParameter(String name) {
+ return initParameters.get(name);
+ }
- @SuppressWarnings("unchecked")
- public Enumeration getInitParameterNames() {
- return Collections.enumeration(initParameters.keySet());
- }
+ @SuppressWarnings("unchecked")
+ public Enumeration getInitParameterNames() {
+ return Collections.enumeration(initParameters.keySet());
+ }
- public ServletContext getServletContext() {
- return context;
- }
-
- });
- next.init(context);
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ });
+ next.init(context);
+ initialized = true;
+ }
}
public String getPathInfo(String path) {
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -19,31 +19,32 @@
import org.richfaces.test.ServerLogger;
-
/**
* @author asmirnov
- *
+ *
*/
public class ServletContainer implements RequestChain {
-
+
private static final Logger log = ServerLogger.SERVER.getLogger();
-
+
private final Servlet servlet;
-
+
private final boolean prefixMapped;
-
+
private final String mapping;
-
+
private final Map<String, String> initParameters;
-
+
private String name = "Default";
+ private boolean initialized = false;
+
/**
* @param mapping
* @param servlet
*/
public ServletContainer(String mapping, Servlet servlet) {
- if(null == mapping){
+ if (null == mapping) {
this.prefixMapped = true;
this.mapping = "";
} else if (mapping.startsWith("*")) {
@@ -51,18 +52,18 @@
this.mapping = mapping.substring(1);
} else if (mapping.endsWith("*")) {
this.prefixMapped = true;
- this.mapping = mapping.substring(0,mapping.length()-1);
+ this.mapping = mapping.substring(0, mapping.length() - 1);
} else {
- throw new IllegalArgumentException("Invalid mapping "+mapping);
+ throw new IllegalArgumentException("Invalid mapping " + mapping);
}
this.servlet = servlet;
this.initParameters = new HashMap<String, String>();
}
-
-
- public void addInitParameter(String name, String value){
+
+ public void addInitParameter(String name, String value) {
initParameters.put(name, value);
}
+
/**
* @return the name
*/
@@ -71,80 +72,96 @@
}
/**
- * @param name the name to set
+ * @param name
+ * the name to set
*/
public void setName(String name) {
this.name = name;
}
- /* (non-Javadoc)
- * @see org.richfaces.test.staging.RequestChain#isApplicable(java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.richfaces.test.staging.RequestChain#isApplicable(java.lang.String)
*/
public boolean isApplicable(String path) {
- if(prefixMapped && path.startsWith(mapping)){
+ if (prefixMapped && path.startsWith(mapping)) {
return true;
- } else if(!prefixMapped && path.endsWith(mapping)){
+ } else if (!prefixMapped && path.endsWith(mapping)) {
return true;
} else {
return false;
}
}
- public String getServletPath(String path){
+ public String getServletPath(String path) {
if (!isApplicable(path)) {
return null;
}
- if(prefixMapped){
+ if (prefixMapped) {
return mapping;
} else {
return path;
}
}
-
+
public String getPathInfo(String path) {
if (!isApplicable(path)) {
return null;
}
- if(prefixMapped){
+ if (prefixMapped) {
return path.substring(mapping.length());
} else {
return null;
}
-
+
}
-
- public void init(final StagingServletContext context) throws ServletException {
- servlet.init(new ServletConfig(){
- public String getInitParameter(String name) {
- return initParameters.get(name);
- }
+ public void init(final StagingServletContext context)
+ throws ServletException {
+ if (!initialized) {
+ servlet.init(new ServletConfig() {
- @SuppressWarnings("unchecked")
- public Enumeration getInitParameterNames() {
- return Collections.enumeration(initParameters.keySet());
- }
+ public String getInitParameter(String name) {
+ return initParameters.get(name);
+ }
- public ServletContext getServletContext() {
- return context;
- }
+ @SuppressWarnings("unchecked")
+ public Enumeration getInitParameterNames() {
+ return Collections.enumeration(initParameters.keySet());
+ }
- public String getServletName() {
- return name;
- }
-
- });
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ public String getServletName() {
+ return name;
+ }
+
+ });
+ initialized = true;
+ }
}
- /* (non-Javadoc)
- * @see org.richfaces.test.staging.RequestChain#execute(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.richfaces.test.staging.RequestChain#execute(javax.servlet.ServletRequest
+ * , javax.servlet.ServletResponse)
*/
- public void execute(ServletRequest request, ServletResponse response) throws
ServletException, IOException {
+ public void execute(ServletRequest request, ServletResponse response)
+ throws ServletException, IOException {
this.servlet.service(request, response);
-
+
}
public void destroy() {
- this.servlet.destroy();
+ if (initialized) {
+ this.servlet.destroy();
+ initialized = false;
+ }
}
}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -4,28 +4,28 @@
package org.richfaces.test.staging;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
-import javax.servlet.ServletRequestListener;
-import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import org.richfaces.collections.collect.ImmutableCollection;
-import org.richfaces.collections.collect.ImmutableList;
-import org.richfaces.collections.collect.Multimap;
-import org.richfaces.collections.collect.Multimaps;
import org.richfaces.test.ServerLogger;
/**
@@ -41,8 +41,34 @@
public static final String LOCALHOST_IP = "127.0.0.1";
public static final String UTF8 = "UTF-8";
-
+ private String requestBody = null;
+ private String contentType;
+
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ private Map<String, String> headers = new HashMap<String, String>();
+
+ private Collection<Locale> locales = Arrays.asList(Locale.US,
+ Locale.GERMANY);
+
+ private String characterEncoding = UTF8;
+
+ /**
+ * @return the requestBody
+ */
+ public String getRequestBody() {
+ return requestBody;
+ }
+
+ /**
+ * @param requestBody
+ * the requestBody to set
+ */
+ public void setRequestBody(String requestBody) {
+ this.requestBody = requestBody;
+ }
+
/*
* (non-Javadoc)
*
@@ -63,7 +89,6 @@
return StagingServletContext.CONTEXT_PATH;
}
-
/*
* (non-Javadoc)
*
@@ -71,8 +96,14 @@
* javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
*/
public long getDateHeader(String name) {
- // TODO create headers support
- log.info("unimplemented request method getDateHeader");
+ String value = headers.get(name);
+ if(null != value){
+ try {
+ return DateFormat.getDateInstance(DateFormat.FULL,
getLocale()).parse(value).getTime();
+ } catch (ParseException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
return -1;
}
@@ -82,9 +113,7 @@
* @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
*/
public String getHeader(String name) {
- // TODO create headers support
- log.info("unimplemented request method getHeader");
- return null;
+ return headers.get(name);
}
/*
@@ -94,9 +123,7 @@
*/
@SuppressWarnings("unchecked")
public Enumeration getHeaderNames() {
- // TODO create headers support
- log.info("unimplemented request method getHeaderNames");
- return null;
+ return Collections.enumeration(headers.keySet());
}
/*
@@ -106,9 +133,15 @@
*/
@SuppressWarnings("unchecked")
public Enumeration getHeaders(String name) {
- // TODO create headers support
- log.info("unimplemented request method getHeaders");
- return Collections.enumeration(Collections.EMPTY_LIST);
+ Set<String> values;
+ String value = headers.get(name);
+ if (null != value) {
+ values = Collections.singleton(value);
+
+ } else {
+ values = Collections.emptySet();
+ }
+ return Collections.enumeration(values);
}
/*
@@ -117,11 +150,21 @@
* @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
*/
public int getIntHeader(String name) {
- // TODO create headers support
- log.info("unimplemented request method getIntHeader");
+ String value = headers.get(name);
+ if(null != value){
+ return Integer.parseInt(value);
+ }
return -1;
}
+ public void addHeader(String name, String value) {
+ headers.put(name, value);
+ }
+
+ public void addHeaders(Map<String, String> headers) {
+ this.headers.putAll(headers);
+ }
+
/*
* (non-Javadoc)
*
@@ -132,7 +175,6 @@
return null;
}
-
/*
* (non-Javadoc)
*
@@ -144,7 +186,6 @@
return null;
}
-
/*
* (non-Javadoc)
*
@@ -165,8 +206,6 @@
return StagingHttpSession.SESSION_ID;
}
-
-
/*
* (non-Javadoc)
*
@@ -228,8 +267,6 @@
return false;
}
- private Map<String, Object> attributes = new HashMap<String, Object>();
-
/*
* (non-Javadoc)
*
@@ -255,7 +292,7 @@
* @see javax.servlet.ServletRequest#getCharacterEncoding()
*/
public String getCharacterEncoding() {
- return UTF8;
+ return characterEncoding;
}
/*
@@ -264,7 +301,8 @@
* @see javax.servlet.ServletRequest#getContentLength()
*/
public int getContentLength() {
- return -1;
+ String body = getRequestBody();
+ return null == body ? -1 : body.length();
}
/*
@@ -273,18 +311,36 @@
* @see javax.servlet.ServletRequest#getContentType()
*/
public String getContentType() {
- log.info("unimplemented request method getContentType");
- return null;
+ return contentType;
}
+ /**
+ * @param contentType
+ * the contentType to set
+ */
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getInputStream()
*/
public ServletInputStream getInputStream() throws IOException {
- // TODO implement post stream.
- log.info("unimplemented request method getInputStream");
+ String body = getRequestBody();
+ if(null != body){
+ final ByteArrayInputStream input = new
ByteArrayInputStream(body.getBytes(getCharacterEncoding()));
+ return new ServletInputStream(){
+
+ @Override
+ public int read() throws IOException {
+ // TODO Auto-generated method stub
+ return input.read();
+ }
+
+ };
+ }
return null;
}
@@ -324,9 +380,6 @@
return Locale.US;
}
- private final ImmutableCollection<Locale> locales = ImmutableList.of(
- Locale.US, Locale.GERMANY);
-
/*
* (non-Javadoc)
*
@@ -337,8 +390,6 @@
return Collections.enumeration(locales);
}
- private String characterEncoding;
-
/*
* (non-Javadoc)
*
@@ -354,8 +405,10 @@
* @see javax.servlet.ServletRequest#getReader()
*/
public BufferedReader getReader() throws IOException {
- // TODO implements request buffer.
- log.info("unimplemented request method getReader");
+ String body = getRequestBody();
+ if(null != body){
+ return new BufferedReader(new StringReader(body));
+ }
return null;
}
@@ -450,8 +503,8 @@
public void removeAttribute(String name) {
// TODO - inform listeners
Object removed = attributes.remove(name);
- if(null != removed){
- attributeRemoved(name,removed);
+ if (null != removed) {
+ attributeRemoved(name, removed);
}
}
@@ -464,14 +517,14 @@
* java.lang.Object)
*/
public void setAttribute(String name, Object o) {
- if(null == o){
+ if (null == o) {
removeAttribute(name);
} else {
Object oldValue = attributes.put(name, o);
- if(null != oldValue){
- attributeReplaced(name,o);
+ if (null != oldValue) {
+ attributeReplaced(name, o);
} else {
- attributeAdded(name,o);
+ attributeAdded(name, o);
}
}
@@ -488,7 +541,7 @@
*/
public void setCharacterEncoding(String env)
throws UnsupportedEncodingException {
- this.characterEncoding=env;
+ this.characterEncoding = env;
}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -7,9 +7,13 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.text.DateFormat;
import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.logging.Logger;
import javax.servlet.ServletOutputStream;
@@ -17,6 +21,7 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpStatus;
+import org.junit.internal.matchers.SubstringMatcher;
import org.richfaces.test.ServerLogger;
/**
@@ -52,6 +57,16 @@
private String encoding = StagingHttpRequest.UTF8;
+ private final Map<String, String[]> headers= new HashMap<String,
String[]>();
+
+
+ /**
+ * @return the headers
+ */
+ public Map<String, String[]> getHeaders() {
+ return headers;
+ }
+
/*
* (non-Javadoc)
*
@@ -60,9 +75,8 @@
* long)
*/
public void addDateHeader(String name, long date) {
- log.info("unimplemented response method addDateHeader");
- // TODO Auto-generated method stub
-
+ // TODO - locale support ?
+ addHeader(name, new Date(date).toString());
}
/*
@@ -72,8 +86,16 @@
* java.lang.String)
*/
public void addHeader(String name, String value) {
- // TODO Auto-generated method stub
- log.info("unimplemented response method addHeader");
+ String[] values = headers.get(name);
+ if (null == values) {
+ values = new String[1];
+ } else {
+ String[] newValues = new String[values.length + 1];
+ System.arraycopy(values, 0, newValues, 0, values.length);
+ values = newValues;
+ }
+ values[values.length - 1] = value;
+ headers.put(name, values);
}
@@ -85,9 +107,7 @@
* int)
*/
public void addIntHeader(String name, int value) {
- // TODO Auto-generated method stub
- log.info("unimplemented response method addIntHeader");
-
+ addHeader(name, String.valueOf(value));
}
/*
@@ -97,9 +117,7 @@
* javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String)
*/
public boolean containsHeader(String name) {
- // TODO Auto-generated method stub
- log.info("unimplemented response method containsHeader");
- return false;
+ return headers.containsKey(name);
}
/*
@@ -181,8 +199,8 @@
* long)
*/
public void setDateHeader(String name, long date) {
- // TODO Auto-generated method stub
- log.info("unimplemented response method setDateHeader");
+ // TODO - locale support ?
+ setHeader(name, new Date(date).toString());
}
/*
@@ -192,8 +210,7 @@
* java.lang.String)
*/
public void setHeader(String name, String value) {
- // TODO Auto-generated method stub
- log.info("unimplemented response method setHeader");
+ headers.put(name, new String[]{value});
}
/*
@@ -204,8 +221,7 @@
* int)
*/
public void setIntHeader(String name, int value) {
- // TODO Auto-generated method stub
- log.info("unimplemented response method setIntHeader");
+ setHeader(name, String.valueOf(value));
}
/*
@@ -399,7 +415,21 @@
* @see javax.servlet.ServletResponse#setContentType(java.lang.String)
*/
public void setContentType(String type) {
- contentType = type;
+ if(null == type){
+ throw new NullPointerException();
+ }
+ int i = type.indexOf(';');
+ if(i>=0){
+ setHeader("Content-Type", type);
+ contentType = type.substring(0, i).trim();
+ i=type.lastIndexOf('=');
+ if(i>=0){
+ setCharacterEncoding(type.substring(i+1).trim());
+ }
+ } else {
+ setHeader("Content-Type",
type+";charset="+getCharacterEncoding());
+ contentType = type;
+ }
}
/*
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -9,6 +9,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
@@ -26,11 +27,11 @@
public static final String SESSION_ID = "1234567890";
- private final Map<String, Object> attributes = new HashMap<String,
Object>();
+ private final Map<String, Object> attributes = new ConcurrentHashMap<String,
Object>();
private final long creationTime;
- private int inactiveTime = DEFAULT_INACTIVE_TIME;
+ private volatile int inactiveTime = DEFAULT_INACTIVE_TIME;
private boolean valid;
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -13,6 +13,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -36,7 +37,7 @@
public static final String CONTEXT_PATH = "";
private static final String APPLICATION_NAME = "stub";
- private final Map<String, Object> attributes = new HashMap<String,
Object>();
+ private final Map<String, Object> attributes = new ConcurrentHashMap<String,
Object>();
private Map<String,String> initParameters = new HashMap<String, String>();
/* (non-Javadoc)
Copied:
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/ajax-web.xml
(from rev 11124,
trunk/framework/jsf-test/src/main/resources/org/richfaces/test/ajax-web.xml)
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/ajax-web.xml
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/ajax-web.xml 2008-11-12
20:27:42 UTC (rev 11125)
@@ -0,0 +1,71 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
+
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-app_2_5.xsd">
+
+ <display-name>Stub test</display-name>
+ <description>
+ Stub testing server
+ </description>
+ <context-param>
+ <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+ <param-value>server</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+ <context-param>
+ <description>
+ Set this flag to true if you want the JavaServer Faces
+ Reference Implementation to validate the XML in your
+ faces-config.xml resources against the DTD. Default
+ value is false.
+ </description>
+ <param-name>com.sun.faces.validateXml</param-name>
+ <param-value>true</param-value>
+ </context-param>
+ <context-param>
+ <description>
+ Set this flag to true if you want the JavaServer Faces
+ Reference Implementation to verify that all of the application
+ objects you have configured (components, converters,
+ renderers, and validators) can be successfully created.
+ Default value is false.
+ </description>
+ <param-name>com.sun.faces.verifyObjects</param-name>
+ <param-value>true</param-value>
+ </context-param>
+ <filter>
+ <display-name>Ajax4jsf Filter</display-name>
+ <filter-name>ajax4jsf</filter-name>
+ <filter-class>org.ajax4jsf.Filter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>ajax4jsf</filter-name>
+ <servlet-name>Faces Servlet</servlet-name>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+
+ <!-- Faces Servlet -->
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ </servlet>
+
+
+ <!-- Faces Servlet Mapping -->
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+
+
+</web-app>
+
+
Property changes on:
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/ajax-web.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml 2008-11-12
20:27:42 UTC (rev 11125)
@@ -1,69 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
-<!--
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-
- Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
-
- The contents of this file are subject to the terms of either the GNU
- General Public License Version 2 only ("GPL") or the Common Development
- and Distribution License("CDDL") (collectively, the "License").
You
- may not use this file except in compliance with the License. You can obtain
- a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL.html
- or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
- language governing permissions and limitations under the License.
-
- When distributing the software, include this License Header Notice in each
- file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
- Sun designates this particular file as subject to the "Classpath" exception
- as provided by Sun in the GPL Version 2 section of the License file that
- accompanied this code. If applicable, add the following below the License
- Header, with the fields enclosed by brackets [] replaced by your own
- identifying information: "Portions Copyrighted [year]
- [name of copyright owner]"
-
- Contributor(s):
-
- If you wish your version of this file to be governed by only the CDDL or
- only the GPL Version 2, indicate your decision by adding "[Contributor]
- elects to include this software in this distribution under the [CDDL or GPL
- Version 2] license." If you don't indicate a single choice of license, a
- recipient has the option to distribute your version of this file under
- either the CDDL, the GPL Version 2 or to extend the choice of license to
- its licensees as provided above. However, if you add GPL Version 2 code
- and therefore, elected the GPL Version 2 license, then the option applies
- only if the new code is made subject to such option by the copyright
- holder.
--->
-
-<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
-
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"
- version="2.0">
-
- <!-- our NumberBean we created before -->
- <managed-bean>
- <managed-bean-name>HelloBean</managed-bean-name>
-
<managed-bean-class>org.richfaces.test.HelloBean</managed-bean-class>
- <managed-bean-scope>session</managed-bean-scope>
- </managed-bean>
-
- <!-- going from guess.xhtml to response.xhtml -->
- <navigation-rule>
- <from-view-id>/hello.xhtml</from-view-id>
- <navigation-case>
- <from-outcome>success</from-outcome>
- <to-view-id>/response.xhtml</to-view-id>
- </navigation-case>
- </navigation-rule>
-
- <!-- going from response.xhtml to guess.xhtml -->
- <navigation-rule>
- <from-view-id>/response.xhtml</from-view-id>
- <navigation-case>
- <from-outcome>success</from-outcome>
- <to-view-id>/hello.xhtml</to-view-id>
- </navigation-case>
- </navigation-rule>
-
-</faces-config>
Modified:
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-12
19:56:53 UTC (rev 11124)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-12
20:27:42 UTC (rev 11125)
@@ -48,7 +48,7 @@
}
@Override
- protected void setupWebContent(StagingServer facesServer) {
+ protected void setupWebContent() {
facesServer.addResource("/hello.xhtml",
"org/richfaces/test/hello.xhtml");
facesServer.addResource("/response.xhtml",
"org/richfaces/test/response.xhtml");
facesServer.addResource("/wave.med.gif",
"org/richfaces/test/wave.med.gif");