Author: nbelaevski
Date: 2008-09-12 10:02:57 -0400 (Fri, 12 Sep 2008)
New Revision: 10436
Modified:
trunk/framework/api/src/main/java/org/ajax4jsf/resource/ResourceContext.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/FacesResourceContext.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java
trunk/framework/test/src/test/java/org/ajax4jsf/resource/InternetResourceServiceTestCase.java
trunk/framework/test/src/test/java/org/ajax4jsf/resource/ResourceServiceThreadsTestCase.java
Log:
https://jira.jboss.org/jira/browse/RF-4427
Modified: trunk/framework/api/src/main/java/org/ajax4jsf/resource/ResourceContext.java
===================================================================
---
trunk/framework/api/src/main/java/org/ajax4jsf/resource/ResourceContext.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/api/src/main/java/org/ajax4jsf/resource/ResourceContext.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -122,6 +122,12 @@
*/
public abstract void setContentType(String contentType);
+ /**
+ * Setup response content length as {@see
javax.servlet.ServletResponse#setContentLength(int)}
+ * @param contentLength
+ */
+ public abstract void setContentLength(int contentLength);
+
public abstract String getInitParameter(String name);
public Object getResourceData() {
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -128,6 +128,10 @@
public void setContentType(String contentType) {
this.content.setContentType(contentType);
}
+
+ public void setContentLength(int contentLength) {
+ this.content.setContentLength(contentLength);
+ }
public Object getResourceData() {
return parent.getResourceData();
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/FacesResourceContext.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/FacesResourceContext.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/FacesResourceContext.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -193,7 +193,12 @@
response.setContentType(contentType);
}
+
+ public void setContentLength(int contentLength) {
+ response.setContentLength(contentLength);
+ }
+
public String getInitParameter(String name) {
// TODO Auto-generated method stub
return externalContext.getInitParameter(name);
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -378,7 +378,7 @@
if (isCacheable(context)) {
if (context instanceof CachedResourceContext) {
CachedResourceContext cachedContext = (CachedResourceContext) context;
- cachedContext.getContent().setIntHeader("Content-Length", total);
+ cachedContext.getContent().setContentLength(total);
} else {
setContentLength(total);
}
@@ -405,8 +405,7 @@
int contentLength = getContentLength(context);
if (cached) {
if (contentLength > 0) {
- context.setIntHeader("Content-Length",
- contentLength);
+ context.setContentLength(contentLength);
}
long expired = getExpired(context);
if (expired < 0 ) {
@@ -418,8 +417,7 @@
+ (expired / 1000L));
} else {
if (contentLength > 0) {
- context.setIntHeader("Content-Length",
- contentLength);
+ context.setContentLength(contentLength);
// } else {
// context.setHeader("Transfer-Encoding", "chunked");
}
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -130,6 +130,10 @@
response.setContentType(contentType);
}
+ public void setContentLength(int contentLength) {
+ response.setContentLength(contentLength);
+ }
+
public String getInitParameter(String name) {
// TODO Auto-generated method stub
return context.getInitParameter(name);
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java 2008-09-12
14:00:52 UTC (rev 10435)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -74,6 +74,8 @@
private String contentType;
+ private Integer contentLength;
+
/**
* Send saved content to http responce
*
@@ -118,6 +120,11 @@
realContentLength = outputStream.getLength();
}
} // TODO - calculate content-lenght for writer ?
+
+ if (realContentLength <= 0 && contentLength != null) {
+ realContentLength = contentLength.intValue();
+ }
+
for (Iterator<Entry<String, Object>> iter = headers.entrySet()
.iterator(); iter.hasNext();) {
Entry<String, Object> element = iter.next();
@@ -130,8 +137,13 @@
} else if (headerValue instanceof Integer) {
Integer value = (Integer) headerValue;
// Check real content length.
- if ( !(realContentLength > 0
- && "Content-Length".equals(header))) {
+ if ("Content-Length".equals(header)) {
+ if (realContentLength <= 0) {
+ realContentLength = value.intValue();
+ } else {
+ //do nothing
+ }
+ } else {
response.setIntHeader(header, value.intValue());
}
} else {
@@ -148,7 +160,7 @@
+ headerValue, e);
}
if(realContentLength > 0){
- response.setIntHeader("Content-Length", realContentLength);
+ response.setContentLength(realContentLength);
}
if (null != contentType) {
response.setContentType(this.contentType);
@@ -307,4 +319,16 @@
out.flush();
}
}
+
+ public int getContentLength() {
+ if (contentLength == null) {
+ throw new IllegalStateException("Content length hasn't been set yet!");
+ }
+
+ return contentLength.intValue();
+ }
+
+ public void setContentLength(int contentLength) {
+ this.contentLength = contentLength;
+ }
}
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockFacesResourceContext.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -44,6 +44,7 @@
//used to encode headers properly
private MockHttpServletResponse mockResponse = new MockHttpServletResponse();
private Set headerSet = new LinkedHashSet();
+ private Integer contentLength;
public void setContentType(String contentType) {
this.contentType = contentType;
@@ -53,6 +54,18 @@
return contentType;
}
+ public void setContentLength(int contentLength) {
+ this.contentLength = contentLength;
+ }
+
+ public int getContentLength() {
+ if (contentLength == null) {
+ throw new IllegalStateException("Content length hasn't been set yet!");
+ }
+
+ return contentLength.intValue();
+ }
+
public void setDateHeader(String name, long value) {
headerSet.add(name);
mockResponse.setDateHeader(name, value);
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/resource/InternetResourceServiceTestCase.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/resource/InternetResourceServiceTestCase.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/resource/InternetResourceServiceTestCase.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -24,6 +24,7 @@
import java.io.IOException;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.shale.test.mock.MockHttpServletResponse;
import org.apache.shale.test.mock.MockServletOutputStream;
/**
@@ -44,6 +45,19 @@
*/
public void setUp() throws Exception {
super.setUp();
+
+ //TODO fix when setContentLength in shale-test will start function
+ //
https://issues.apache.org/struts/browse/SHALE-495
+ this.response = new MockHttpServletResponse() {
+
+ public int getContentLength() {
+ return Integer.parseInt(getHeader("Content-Length"));
+ }
+
+ public void setContentLength(int length) {
+ addIntHeader("Content-Length", length);
+ }
+ };
}
/* (non-Javadoc)
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/resource/ResourceServiceThreadsTestCase.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/resource/ResourceServiceThreadsTestCase.java 2008-09-12
14:00:52 UTC (rev 10435)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/resource/ResourceServiceThreadsTestCase.java 2008-09-12
14:02:57 UTC (rev 10436)
@@ -96,6 +96,16 @@
format.setTimeZone(TimeZone.getTimeZone("GMT"));
addHeader(name, format.format(new Date(value)));
}
+
+ //TODO fix when setContentLength in shale-test will start function
+ //
https://issues.apache.org/struts/browse/SHALE-495
+ public int getContentLength() {
+ return Integer.parseInt(getHeader("Content-Length"));
+ }
+
+ public void setContentLength(int length) {
+ addIntHeader("Content-Length", length);
+ }
};
MockHttpServletRequest req = new MockHttpServletRequest(session);