Author: cziegeler
Date: Sun Mar 6 04:55:05 2005
New Revision: 156307
URL: http://svn.apache.org/viewcvs?view=rev&rev=156307
Log:
<action dev="CZ" type="fix" fixes-bug="10277">
Change the mime-type setting of a reader. See also bug #25121.
</action>
Added:
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.foo
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.xml
- copied, changed from r156303,
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.html
Removed:
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.html
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
cocoon/branches/BRANCH_2_1_X/src/test/anteater/reader-mime-type.xml
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/explain-test.xml
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/sitemap.xmap
cocoon/branches/BRANCH_2_1_X/status.xml
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java?view=diff&r1=156306&r2=156307
==============================================================================
---
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
(original)
+++
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
Sun Mar 6 04:55:05 2005
@@ -564,14 +564,30 @@
* Set the mime-type for a reader
* @param environment The current environment
*/
- protected void setMimeTypeForReader(Environment environment) {
- String mimeType = this.reader.getMimeType();
- if ( mimeType != null ) {
- environment.setContentType(mimeType);
- } else if ( readerMimeType != null ) {
+ protected void setMimeTypeForReader(Environment environment)
+ throws ProcessingException {
+ // Set the mime-type
+ // the behaviour has changed from 2.1.6 to 2.1.7 according to bugs
#10277 and #25121:
+ // MIME type declared in the sitemap (instance or declaration, in this
order)
+ // Ask the Reader for a MIME type:
+ // A *.doc reader could peek into the file
+ // and return either text/plain or application/vnd.msword or
+ // the reader can use MIME type declared in WEB-INF/web.xml or
+ // by the server.
+ if ( this.readerMimeType != null ) {
+ // there was a mime-type defined on map:read in the sitemap
environment.setContentType(this.readerMimeType);
- } else {
+ } else if ( this.sitemapReaderMimeType != null ) {
+ // there was a mime-type defined on map:reader in the sitemap
environment.setContentType(this.sitemapReaderMimeType);
+ } else {
+ // ask to the component itself
+ final String mimeType = this.reader.getMimeType();
+ if (mimeType != null) {
+ environment.setContentType(mimeType);
+ }
+ // If no mimeType available, leave to to upstream proxy
+ // or browser to deduce content-type from URL extension.
}
}
@@ -585,21 +601,25 @@
// internal processing: text/xml
environment.setContentType("text/xml");
} else {
- String mimeType = this.serializer.getMimeType();
- if (mimeType != null) {
- // we have a mimeType from the component itself
- environment.setContentType (mimeType);
- } else if (serializerMimeType != null) {
- // there was a mimeType specified in the sitemap pipeline
- environment.setContentType (serializerMimeType);
- } else if (this.sitemapSerializerMimeType != null) {
- // use the mimeType specified in the sitemap component
declaration
- environment.setContentType (this.sitemapSerializerMimeType);
+ // Set the mime-type
+ // the behaviour has changed from 2.1.6 to 2.1.7 according to bugs
#10277 and #25121:
+ if (serializerMimeType != null) {
+ // there was a mime-type defined on map:serialize in the
sitemap
+ environment.setContentType(serializerMimeType);
+ } else if (sitemapSerializerMimeType != null) {
+ // there was a mime-type defined on map:serializer in the
sitemap
+ environment.setContentType(sitemapSerializerMimeType);
} else {
- // No mimeType available
- String message = "Unable to determine MIME type for " +
- environment.getURIPrefix() + "/" + environment.getURI();
- throw new ProcessingException(message);
+ // ask to the component itself
+ String mimeType = this.serializer.getMimeType();
+ if (mimeType != null) {
+ environment.setContentType (mimeType);
+ } else {
+ // No mimeType available
+ final String message = "Unable to determine MIME type for
" +
+ environment.getURIPrefix() + "/" +
environment.getURI();
+ throw new ProcessingException(message);
+ }
}
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/test/anteater/reader-mime-type.xml
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/anteater/reader-mime-type.xml?view=diff&r1=156306&r2=156307
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/anteater/reader-mime-type.xml
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/anteater/reader-mime-type.xml Sun Mar
6 04:55:05 2005
@@ -21,84 +21,109 @@
<property name="usetidy" value="false"/>
</group>
- <!-- Check mime-types (bugzilla 25212) -->
+ <!-- Check mime-types (bugzilla 25121) -->
<target name="reader-mime-type">
<property name="baseUrl"
value="${anteater.env.cocoon}/samples/test/reader-mime-type"/>
- <httpRequest href="${baseUrl}/test10.html" description="Check
content-type">
- <match>
- <header name="Content-type" value="text/html"/>
+ <!--
+ Each httpRequest repeated twice to check caching pipeline.
+ Check for text/xml instead of text/html in order not to be fooled
+ by 404 or 500 error pages.
+ -->
+
+ <!-- Check that content-type is *not* derived from URL extension. -->
+ <!-- FIXME: no easier way to check absence of header with anteater? -->
+ <httpRequest href="${baseUrl}/test10.xml" description="Check
content-type">
+ <match assign="test10-failed-1">
+ <echo message="Ignore following message text: message doesn't
match because header 'content-type' is not present"/>
+ <header name="Content-type" pattern=".*"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test10.html" description="Check
content-type (cached)">
- <match>
- <header name="Content-type" value="text/html"/>
+ <fail if="test10-failed-1"/>
+ <httpRequest href="${baseUrl}/test10.xml" description="Check
content-type (cached)">
+ <match assign="test10-failed-2">
+ <echo message="Ignore following message text: message doesn't
match because header 'content-type' is not present"/>
+ <header name="Content-type" pattern=".*"/>
</match>
</httpRequest>
+ <fail if="test10-failed-2"/>
- <httpRequest href="${baseUrl}/test20.html" description="Check
content-type">
+ <!-- Check content-type derived from map:read/@src -->
+ <httpRequest href="${baseUrl}/test20.x20" description="Check
content-type">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test20.html" description="Check
content-type (cached)">
+ <httpRequest href="${baseUrl}/test20.x20" description="Check
content-type (cached)">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test30.html" description="Check
content-type">
+ <!-- Check content-type derived from map:read/@mime-type -->
+ <httpRequest href="${baseUrl}/test30.x30" description="Check
content-type">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test30.html" description="Check
content-type (cached)">
+ <httpRequest href="${baseUrl}/test30.x30" description="Check
content-type (cached)">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test40.html" description="Check
content-type">
+ <!-- Check content-type derived from map:reader/@mime-type -->
+ <httpRequest href="${baseUrl}/test40.x40" description="Check
content-type">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test40.html" description="Check
content-type (cached)">
+ <httpRequest href="${baseUrl}/test40.x40" description="Check
content-type (cached)">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test50.html" description="Check
content-type">
- <match>
- <header name="Content-type" value="text/html"/>
+ <!-- Check that content-type is *not* inherited across cocoon:/ -->
+ <!-- See bugzilla 25121 why this not possible. -->
+ <httpRequest href="${baseUrl}/test50.xml" description="Check
content-type">
+ <match assign="test50-failed-1">
+ <echo message="Ignore following message text: message doesn't
match because header 'content-type' is not present"/>
+ <header name="Content-type" pattern=".*"/>
</match>
+ <match assign="test50-passed-1"/>
</httpRequest>
- <httpRequest href="${baseUrl}/test50.html" description="Check
content-type (cached)">
- <match>
- <header name="Content-type" value="text/html"/>
+ <fail if="test50-failed-1"/>
+ <httpRequest href="${baseUrl}/test50.xml" description="Check
content-type (cached)">
+ <match assign="test50-failed-2">
+ <echo message="Ignore following message text: message doesn't
match because header 'content-type' is not present"/>
+ <header name="Content-type" pattern=".*"/>
</match>
+ <match/>
</httpRequest>
+ <fail if="test50-failed-2"/>
- <httpRequest href="${baseUrl}/test60.html" description="Check
content-type">
+ <!-- Check content-type derived from map:read/@src -->
+ <httpRequest href="${baseUrl}/test60.x60" description="Check
content-type">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test60.html" description="Check
content-type (cached)">
+ <httpRequest href="${baseUrl}/test60.x60" description="Check
content-type (cached)">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test70.html" description="Check
content-type">
+ <!-- Check content-type derived from map:read/@mime-type -->
+ <httpRequest href="${baseUrl}/test70.x70" description="Check
content-type">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
- <httpRequest href="${baseUrl}/test70.html" description="Check
content-type (cached)">
+ <httpRequest href="${baseUrl}/test70.x70" description="Check
content-type (cached)">
<match>
- <header name="Content-type" value="text/html"/>
+ <header name="Content-type" value="text/xml"/>
</match>
</httpRequest>
Modified:
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/explain-test.xml
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/explain-test.xml?view=diff&r1=156306&r2=156307
==============================================================================
---
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/explain-test.xml
(original)
+++
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/explain-test.xml
Sun Mar 6 04:55:05 2005
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
- Copyright 1999-2004 The Apache Software Foundation
+ Copyright 1999-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,20 +22,27 @@
<content>
<para>Test harness for
<a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=25121">
- bugzilla 25212
+ bugzilla 25121
</a>, test mime-types on map:reader.
</para>
<para>
Test links:
<ul>
- <li><link href="test10.html">test10.html</link></li>
- <li><link href="test20.html">test20.html</link></li>
- <li><link href="test30">test30</link></li>
- <li><link href="test40.html">test40.html</link></li>
- <li><link href="test50.html">test50.html</link></li>
- <li><link href="test60.html">test60.html</link></li>
- <li><link href="test70.html">test70.html</link></li>
+ <li><link href="test10.xml">test10.xml</link></li>
+ <li><link href="test20.x20">test20.x20</link></li>
+ <li><link href="test30.x30">test30.x30</link></li>
+ <li><link href="test40.x40">test40.x40</link></li>
+ <li><link href="test50.x50">test50.x50</link></li>
+ <li><link href="test60.x60">test60.x60</link></li>
+ <li><link href="test70.x70">test70.x70</link></li>
</ul>
+ </para>
+ <para>
+ test10 and test50 don't have any Content-type header defined that
the
+ browser will invent one, most likely text/html.
+ </para>
+ <para>
+ The other tests should all have Content-type text/xml.
</para>
</content>
</page>
Modified:
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/sitemap.xmap
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/sitemap.xmap?view=diff&r1=156306&r2=156307
==============================================================================
---
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/sitemap.xmap
(original)
+++
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/sitemap.xmap
Sun Mar 6 04:55:05 2005
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
- Copyright 1999-2004 The Apache Software Foundation
+ Copyright 1999-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,52 +17,34 @@
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+ <map:components>
+ <map:readers default="resource">
+ <map:reader logger="sitemap.reader.resource" mime-type="text/xml"
name="xml-resource" pool-max="32"
src="org.apache.cocoon.reading.ResourceReader"/>
+ <map:reader logger="sitemap.reader.resource" mime-type="text/foo"
name="foo-resource" pool-max="32"
src="org.apache.cocoon.reading.ResourceReader"/>
+ </map:readers>
+ </map:components>
<map:pipelines>
<map:pipeline type="caching">
- <map:match pattern="test10.html">
- <map:read src="test.html"/>
+ <map:match pattern="test10.*">
+ <map:read src="test.xzy"/>
</map:match>
- <map:match pattern="test20.html">
- <map:read src="cocoon:/test10.html"/>
+ <map:match pattern="test20.*">
+ <map:read src="test.xml"/>
</map:match>
- <map:match pattern="test30">
- <map:read src="test.html"/>
+ <map:match pattern="test30.*">
+ <map:read src="test.foo" mime-type="text/xml" type="foo-resource"/>
</map:match>
- <map:match pattern="test40.html">
- <map:read src="cocoon:/test10.html"/>
+ <map:match pattern="test40.*">
+ <map:read src="test.foo" type="xml-resource"/>
</map:match>
- <map:match pattern="test50.html">
- <map:read src="cocoon:/test30"/>
+ <map:match pattern="test50.*">
+ <map:read src="cocoon:/test20.x50"/>
</map:match>
- <map:match pattern="test60.html">
- <map:read src="cocoon:/test10.html" mime-type="text/html"/>
+ <map:match pattern="test60.*">
+ <map:read src="cocoon:/test10.xml"/>
</map:match>
- <map:match pattern="test70.html">
- <map:read src="cocoon:/test30" mime-type="text/html"/>
- </map:match>
- </map:pipeline>
-
- <map:pipeline type="noncaching">
- <map:match pattern="test15.html">
- <map:read src="test.html"/>
- </map:match>
- <map:match pattern="test25.html">
- <map:read src="cocoon:/test15.html"/>
- </map:match>
- <map:match pattern="test35">
- <map:read src="test.html"/>
- </map:match>
- <map:match pattern="test45.html">
- <map:read src="cocoon:/test15.html"/>
- </map:match>
- <map:match pattern="test55.html">
- <map:read src="cocoon:/test35"/>
- </map:match>
- <map:match pattern="test65.html">
- <map:read src="cocoon:/test15.html" mime-type="text/html"/>
- </map:match>
- <map:match pattern="test75.html">
- <map:read src="cocoon:/test35" mime-type="text/html"/>
+ <map:match pattern="test70.*">
+ <map:read src="cocoon:/test30.x70" mime-type="text/xml"
type="foo-resource"/>
</map:match>
</map:pipeline>
</map:pipelines>
Added:
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.foo
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.foo?view=auto&rev=156307
==============================================================================
---
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.foo
(added)
+++
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.foo
Sun Mar 6 04:55:05 2005
@@ -0,0 +1,20 @@
+<!--
+ Copyright 2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+ <body>
+ This should have the text/xml mime type.
+ </body>
+</html>
Copied:
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.xml
(from r156303,
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.html)
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.xml?view=diff&rev=156307&p1=cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.html&r1=156303&p2=cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.xml&r2=156307
==============================================================================
---
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.html
(original)
+++
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/reader-mime-type/test.xml
Sun Mar 6 04:55:05 2005
@@ -1,5 +1,5 @@
<!--
- Copyright 1999-2004 The Apache Software Foundation
+ Copyright 1999-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -15,6 +15,6 @@
-->
<html>
<body>
- This should have the text/html mime type.
+ This should have the text/xml mime type.
</body>
</html>
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&r1=156306&r2=156307
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Sun Mar 6 04:55:05 2005
@@ -202,6 +202,9 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="CZ" type="fix" fixes-bug="10277">
+ Change the mime-type setting of a reader. See also bug #25121.
+ </action>
<action dev="LG" type="fix" fixes-bug="33836" due-to="Niklas Therning"
due-to-email="[EMAIL PROTECTED]">
Fix thread safety problem in JXTemplateGenerator.setup() concerning
template script reparsing.
</action>