diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules')
4 files changed, 45 insertions, 8 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/pom.xml b/sca-java-2.x/trunk/modules/binding-http-runtime/pom.xml index ca1456a663..33fb5664a4 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/pom.xml +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/pom.xml @@ -36,6 +36,12 @@ <version>2.0-SNAPSHOT</version> </dependency> + <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> diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java index 80881f7859..3e8e396927 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java @@ -26,13 +26,13 @@ import java.net.URLDecoder; import java.text.ParseException; import javax.servlet.ServletException; -import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.binding.http.HTTPCacheContext; +import org.apache.tuscany.sca.common.http.HTTPContentTypeMapper; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -124,6 +124,14 @@ public class HTTPBindingListenerServlet extends HttpServlet { throw new ServletException((Throwable)responseMessage.getBody()); } + if(response.getContentType() == null || response.getContentType().length() == 0){ + // Calculate content-type based on extension + String contentType = HTTPContentTypeMapper.getContentType(id); + if(contentType != null && contentType.length() >0) { + response.setContentType(contentType); + } + } + // Write the response from the service implementation to the response // output stream InputStream is = (InputStream)responseMessage.getBody(); 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]; |