From e0b4977c26901a8fba08d6da551bd6f36e3a7ffa Mon Sep 17 00:00:00 2001 From: lresende Date: Sat, 20 Feb 2010 08:38:54 +0000 Subject: 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 --- .../web/javascript/dojo/DojoResourceServlet.java | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca') 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]; -- cgit v1.2.3