diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-20 08:38:54 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-20 08:38:54 +0000 |
commit | e0b4977c26901a8fba08d6da551bd6f36e3a7ffa (patch) | |
tree | db330af83645d71023f0a7912e0fd9bc6771da14 /sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java | |
parent | 4f7f10f97d60a5e7083f9a5b190c2818de7359a1 (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/src/main/java')
-rw-r--r-- | sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java | 31 |
1 files changed, 24 insertions, 7 deletions
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]; |