You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2009/02/03 02:26:47 UTC
svn commit: r740180 - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry5/internal/services/
tapestry-core/src/test/java/org/apache/tapestry5/internal/services/
tapestry-hibernate/src/site/apt/
Author: hlship
Date: Tue Feb 3 01:26:47 2009
New Revision: 740180
URL: http://svn.apache.org/viewvc?rev=740180&view=rev
Log:
TAP5-485: Tracking issue for changes required by com.formos.tapestry:tapestry-template
- Expose a method to determine the content type of a resource
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamer.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamer.java?rev=740180&r1=740179&r2=740180&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamer.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamer.java Tue Feb 3 01:26:47 2009
@@ -32,4 +32,14 @@
* Streams the content of the resource to the client.
*/
void streamResource(Resource resource) throws IOException;
+
+ /**
+ * Analyzes the resource to determine what its content type is, possibly using the service's configuration.
+ *
+ * @param resource to analyze
+ * @return content type
+ * @throws IOException
+ * @since 5.1.0.0
+ */
+ String getContentType(Resource resource) throws IOException;
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java?rev=740180&r1=740179&r2=740180&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java Tue Feb 3 01:26:47 2009
@@ -129,6 +129,11 @@
}
}
+ public String getContentType(Resource resource) throws IOException
+ {
+ return identifyContentType(resource, resourceCache.getStreamableResource(resource));
+ }
+
private String identifyContentType(Resource resource, StreamableResource streamble) throws IOException
{
String contentType = streamble.getContentType();
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java?rev=740180&r1=740179&r2=740180&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java Tue Feb 3 01:26:47 2009
@@ -14,15 +14,13 @@
package org.apache.tapestry5.internal.services;
-import org.apache.tapestry5.internal.InternalConstants;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
import org.apache.tapestry5.services.*;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.endsWith;
import org.testng.annotations.Test;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -56,23 +54,10 @@
HttpServletRequest hsRequest = mockHttpServletRequest();
HttpServletResponse hsResponse = mockHttpServletResponse();
Context context = mockContext();
-
- request.setAttribute(InternalConstants.SUPPRESS_COMPRESSION, true);
-
- // We're testing with a fake client that does not support GZIP compression:
-
- expect(hsRequest.getHeader(isA(String.class))).andReturn(null);
-
- train_setContentLength(hsResponse, anyInt());
- train_setDateHeader(hsResponse, eq("Last-Modified"), anyLong());
- train_setDateHeader(hsResponse, eq("Expires"), anyLong());
- train_setContentType(hsResponse, contentType);
- train_getOutputStream(hsResponse, new TestServletOutputStream());
-
+
if (consultsContext)
expect(context.getMimeType(endsWith(fileName))).andReturn(null);
-
replay();
Response response = new ResponseImpl(hsResponse);
@@ -88,17 +73,8 @@
Resource resource = new ClasspathResource(path);
- streamer.streamResource(resource);
+ assertEquals(streamer.getContentType(resource), contentType);
verify();
}
-
- private static class TestServletOutputStream extends ServletOutputStream
- {
- @Override
- public void write(int b) throws IOException
- {
- // Empty.
- }
- }
}
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt?rev=740180&r1=740179&r2=740180&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt Tue Feb 3 01:26:47 2009
@@ -159,19 +159,18 @@
}
+---+
- Finally, add a decorator method to your module:
+ Finally, you should use the HibernateTransactionAdviser to add transaction advice:
+---+
@Match("*DAO")
- public static <T> T decorateTransactionally(HibernateTransactionDecorator decorator, Class<T> serviceInterface,
- T delegate,
- String serviceId)
+ public static void adviseTransactions(HibernateTransactionAdviser advisor, MethodAdviceReceiver receiver)
{
- return decorator.build(serviceInterface, delegate, serviceId);
+ advisor.addTransactionCommitAdvice(receiver);
}
+---+
- This one is configured to match against any service whose id ends with "DAO", such as "PersonDAO".
- The HibernateTransactionDecorator
- service builds an interceptor around the delegate (which is, basically, the service) that understands
- the @CommitAfter annotation. Methods that don't have @CommitAfter pass right on through unchanged.
\ No newline at end of file
+ This advice method is configured to match against any service whose id ends with "DAO", such as "PersonDAO".
+
+ The advisor scans the service interface and identifies any methods with the @CommitAfter annotation.
+
+