summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/web-javascript-dojo
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-02-20 08:38:54 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-02-20 08:38:54 +0000
commite0b4977c26901a8fba08d6da551bd6f36e3a7ffa (patch)
treedb330af83645d71023f0a7912e0fd9bc6771da14 /sca-java-2.x/trunk/modules/web-javascript-dojo
parent4f7f10f97d60a5e7083f9a5b190c2818de7359a1 (diff)
Properly setting contentType for known files, to avoid issues with htmlUnit
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@912093 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/web-javascript-dojo')
-rw-r--r--sca-java-2.x/trunk/modules/web-javascript-dojo/pom.xml6
-rw-r--r--sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java31
2 files changed, 30 insertions, 7 deletions
diff --git a/sca-java-2.x/trunk/modules/web-javascript-dojo/pom.xml b/sca-java-2.x/trunk/modules/web-javascript-dojo/pom.xml
index db7430c374..fa0c0140be 100644
--- a/sca-java-2.x/trunk/modules/web-javascript-dojo/pom.xml
+++ b/sca-java-2.x/trunk/modules/web-javascript-dojo/pom.xml
@@ -38,6 +38,12 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-common-http</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-http</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
diff --git a/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java b/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java
index 86d04a05b5..20c9fe4959 100644
--- a/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java
+++ b/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java
@@ -28,6 +28,9 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.tuscany.sca.common.http.HTTPConstants;
+import org.apache.tuscany.sca.common.http.HTTPContentTypeMapper;
+
/**
* A Resource servlet used to serve dojo files
@@ -41,22 +44,36 @@ public class DojoResourceServlet extends HttpServlet {
}
-
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
- String path = URLDecoder.decode(request.getRequestURI(), "UTF-8");
-
- if( path.startsWith("/dojo")) {
- //this is a workaround where we need to have dojo files in its own folder
- //to avoid clean target to clean other non dojo resources
- path = "dojo" + path;
+ String path = URLDecoder.decode(request.getRequestURI(), HTTPConstants.CHARACTER_ENCODING_UTF8);
+
+ if( path.startsWith("/dojo") ) {
+ if( ! path.contains("tuscany/AtomService.js")) {
+ //this is a workaround where we need to have dojo files in its own folder
+ //to avoid clean target to clean other non dojo resources
+ path = "/dojo" + path;
+ }
} else if( path.startsWith("/")) {
path = path.substring(1);
}
+ if(response.getContentType() == null || response.getContentType().length() == 0){
+ // Calculate content-type based on extension
+ String contentType = HTTPContentTypeMapper.getContentType(path);
+ if(contentType != null && contentType.length() >0) {
+ response.setContentType(contentType);
+ }
+ }
+
+ response.setCharacterEncoding(HTTPConstants.CHARACTER_ENCODING_UTF8);
+
// Write the response from the service implementation to the response
// output stream
InputStream is = this.getClass().getClassLoader().getResourceAsStream(path);
+ if (is == null) {
+ is = this.getClass().getResourceAsStream(path);
+ }
if(is != null) {
OutputStream os = response.getOutputStream();
byte[] buffer = new byte[2048];