diff options
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java index 0ee63b1668..1dac8a2c9a 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java @@ -20,6 +20,9 @@ package org.apache.tuscany.sca.binding.rest.provider; import java.io.IOException; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; import javax.servlet.Servlet; import javax.servlet.ServletConfig; @@ -29,7 +32,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.rest.RESTBinding; +import org.apache.tuscany.sca.common.http.HTTPCacheContext; import org.apache.tuscany.sca.common.http.HTTPContext; +import org.apache.tuscany.sca.common.http.HTTPHeader; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; @@ -44,7 +50,7 @@ public class RESTServiceListenerServlet extends HttpServlet implements Servlet { private static final long serialVersionUID = -5543706958107836637L; - transient private Binding binding; + transient private RESTBinding binding; transient private ServletConfig config; transient private MessageFactory messageFactory; transient private Invoker serviceInvoker; @@ -53,7 +59,7 @@ public class RESTServiceListenerServlet extends HttpServlet implements Servlet { * Constructs a new HTTPServiceListenerServlet. */ public RESTServiceListenerServlet(Binding binding, Invoker serviceInvoker, MessageFactory messageFactory) { - this.binding = binding; + this.binding = (RESTBinding) binding; this.serviceInvoker = serviceInvoker; this.messageFactory = messageFactory; } @@ -90,6 +96,23 @@ public class RESTServiceListenerServlet extends HttpServlet implements Servlet { //throw new ServletException((Throwable)responseMessage.getBody()); Throwable e = (Throwable)responseMessage.getBody(); ((HttpServletResponse)response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); + } else { + //handles declarative headers configured on the composite + for(HTTPHeader header : binding.getHttpHeaders()) { + //treat special headers that need to be calculated + if(header.getName().equalsIgnoreCase("Expires")) { + GregorianCalendar calendar = new GregorianCalendar(); + calendar.setTime(new Date()); + + calendar.add(Calendar.HOUR, Integer.parseInt(header.getValue())); + + response.setHeader("Expires", HTTPCacheContext.RFC822DateFormat.format( calendar.getTime() )); + } else { + //default behaviour to pass the header value to HTTP response + response.setHeader(header.getName(), header.getValue()); + } + + } } } } |