Permalink
Browse files

added support for declaring the response content-type when a route is…

… defined, example:

    <route path="echo/{echo}" action="Echo.bsh" content-type="json"/>
  see: the 'content-type' attribute above and the related web app example in modules/restpathactions/web
  • Loading branch information...
florin.patrascu@gmail.com
florin.patrascu@gmail.com committed Sep 21, 2011
1 parent 452414a commit 8b3fcc9102223054726c13cf2f0be3fae663a892
View
@@ -1,8 +1,9 @@
JPublish 4 change log:
-[2011.08.07]
- - the RestPathActions module allows the user to optionally define request method(s) that
- can be used for route matching.
+[2011-09-21]
+ - RPAModule; added support for declaring the response content-type when a route is defined, example:
+ <route path="echo/{echo}" action="Echo.bsh" content-type="json"/>
+ see: the 'content-type' attribute above and the related web app example in modules/restpathactions/web
[2011.06.22]
- RESTPATHACTIONS demo cleanup and module improvements, see RestPathActions module's own
@@ -27,7 +27,6 @@
import org.jpublish.util.FileCopyUtils;
import org.jpublish.util.PathUtilities;
-import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MultivaluedMap;
import java.io.ByteArrayInputStream;
@@ -92,7 +91,7 @@ public void execute(JPublishContext context, Configuration configuration) throws
String content = null;
final String pagePath = rm.getPage();
- String viewType = null;
+ String viewType = rm.getContentType();
if (pagePath != null) {
RepositoryWrapper repository = (RepositoryWrapper) context.get(module.getDefaultRepository());
@@ -200,7 +199,7 @@ private void setResponseContentType(JPublishContext context, String path, String
private String getMimeTypeWithCharset(String mimeType, String charSet) {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append(mimeType).append("; charset=").append(charSet);
return buffer.toString();
}
@@ -30,6 +30,7 @@
private String action;
private String page;
private String methods;
+ private String contentType;
private Configuration configuration;
private UriTemplateProcessor templateProcessor;
@@ -80,11 +81,20 @@ public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
@Override
public String toString() {
return "path='" + path + '\'' +
- ", action='" + action + '\'' +
- ", page='" + page + '\'' +
+ (action != null ? ", action='" + action + '\'' : "")+
+ (contentType != null ? ", content-type='" + contentType + '\'' : "" )+
+ (page != null ? ", page='" + page + '\'': "" )+
", methods='" + methods + '\'';
}
}
@@ -122,6 +122,7 @@ public void load(Configuration configuration) throws ConfigurationException {
restModel.setAction(routeConfiguration.getAttribute("action"));
restModel.setPage(routeConfiguration.getAttribute("page"));
restModel.setMethods(routeConfiguration.getAttribute("method", "GET"));
+ restModel.setContentType(routeConfiguration.getAttribute("content-type"));
restModel.setConfiguration(routeConfiguration);
restModels.add(restModel);
@@ -0,0 +1,3 @@
+import org.jpublish.module.restpathactions.*;
+
+context.put( RestPathActionsModule.RESPONSE, "{\"echo\": \""+context.get( "echo")+"\"}");
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright (c) 2010, Florin T.PATRASCU
+ ~ Copyright (c) 2011, Florin T.PATRASCU
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
<routes>
<route path="search/{query}/page/{pageNo}" action="Search.bsh" page="search/index.html"/>
+ <route path="echo/{echo}" action="Echo.bsh" content-type="json"/>
<route path="demo/foo" action="rest/RestDemo.bsh">
<foo>bar</foo>

0 comments on commit 8b3fcc9

Please sign in to comment.