From afa61ca151560bbdca5471e4e0d1bdd460d2e08e Mon Sep 17 00:00:00 2001 From: rfeng Date: Mon, 10 Sep 2012 22:14:59 +0000 Subject: Enable field name based filtering for json serialization git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1383129 13f79535-47bb-0310-9956-ffa450edef68 --- .../rest/provider/DataBindingJAXRSWriter.java | 49 ++++- .../rest/provider/RESTBindingListenerServlet.java | 229 +++++++++++---------- .../rest/provider/RESTServiceListenerServlet.java | 69 ++++--- 3 files changed, 199 insertions(+), 148 deletions(-) (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java') diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java index ab4173939e..9f3cf7b919 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/DataBindingJAXRSWriter.java @@ -24,6 +24,10 @@ import java.io.OutputStream; import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; @@ -32,6 +36,8 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; +import org.apache.tuscany.sca.common.http.HTTPContext; +import org.apache.tuscany.sca.common.http.ThreadHTTPContext; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; @@ -40,7 +46,7 @@ import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; * The generic JAX-RS message body writer based on Tuscany's databindingframework */ @Provider -@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.WILDCARD}) +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.WILDCARD}) public class DataBindingJAXRSWriter extends DataBindingJAXRSProvider implements MessageBodyWriter { public DataBindingJAXRSWriter(ExtensionPointRegistry registry) { @@ -73,8 +79,7 @@ public class DataBindingJAXRSWriter extends DataBindingJAXRSProvider implemen dataBinding = OutputStream.class.getName(); } else if ("application/x-protobuf".equals(mediaType.toString())) { dataBinding = mediaType.toString() + "#" + OutputStream.class.getName(); - } - else { + } else { dataBinding = dataType.getDataBinding(); write(entityStream, t, type); return; @@ -85,7 +90,43 @@ public class DataBindingJAXRSWriter extends DataBindingJAXRSProvider implemen introspectAnnotations(annotations, targetDataType); - mediator.mediate(t, entityStream, dataType, targetDataType, Collections. emptyMap()); + Map metadata = getFields(); + mediator.mediate(t, entityStream, dataType, targetDataType, metadata); + } + + private Map getFields() { + Map metadata = Collections. emptyMap(); + HTTPContext context = ThreadHTTPContext.getHTTPContext(); + if (context != null) { + metadata = new HashMap(); + String included = context.getHttpRequest().getParameter("includedFields"); + String excluded = context.getHttpRequest().getParameter("excludedFields"); + Set includedFields = tokenize(included); + if (includedFields != null) { + metadata.put("includedFields", includedFields); + } + Set excludedFields = tokenize(excluded); + if (excludedFields != null) { + metadata.put("excludedFields", excludedFields); + } + + } + return metadata; + } + + private Set tokenize(String included) { + if (included == null) { + return null; + } + String[] fields = included.split("(,| )+"); + Set includedFields = new HashSet(); + for (String f : fields) { + String field = f.trim(); + if (field.length() > 0) { + includedFields.add(field); + } + } + return includedFields; } } diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java index 6612ca8df6..7e9b9af293 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java @@ -39,6 +39,7 @@ import org.apache.tuscany.sca.common.http.HTTPCacheContext; import org.apache.tuscany.sca.common.http.HTTPContentTypeMapper; import org.apache.tuscany.sca.common.http.HTTPContext; import org.apache.tuscany.sca.common.http.HTTPHeader; +import org.apache.tuscany.sca.common.http.ThreadHTTPContext; import org.apache.tuscany.sca.common.http.cors.CORSHeaderProcessor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -72,62 +73,68 @@ public class RESTBindingListenerServlet extends HttpServlet { * Constructs a new RESTServiceListenerServlet. */ public RESTBindingListenerServlet(Binding binding, Invoker bindingInvoker, MessageFactory messageFactory) { - this.binding = (RESTBinding) binding; + this.binding = (RESTBinding)binding; this.bindingInvoker = bindingInvoker; this.messageFactory = messageFactory; } @Override - protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { if (binding.isCORS()) { CORSHeaderProcessor.processCORS(binding.getCORSConfiguration(), request, response); } - if( binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) { - HTTPContext bindingContext = new HTTPContext(); - bindingContext.setHttpRequest(request); - bindingContext.setHttpResponse(response); + HTTPContext bindingContext = new HTTPContext(); + bindingContext.setHttpRequest(request); + bindingContext.setHttpResponse(response); + ThreadHTTPContext.setHTTPContext(bindingContext); - // Dispatch the service interaction to the service invoker - Message requestMessage = messageFactory.createMessage(); - requestMessage.setBindingContext(bindingContext); + try { - requestMessage.setBody(new Object[] {request.getInputStream()}); + if (binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) { + // Dispatch the service interaction to the service invoker + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBindingContext(bindingContext); - Message responseMessage = bindingInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {request.getInputStream()}); - // return response to client - if (responseMessage.isFault()) { - // Turn a fault into an exception - Throwable e = (Throwable)responseMessage.getBody(); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); - } else { + Message responseMessage = bindingInvoker.invoke(requestMessage); + + // return response to client + if (responseMessage.isFault()) { + // Turn a fault into an exception + Throwable e = (Throwable)responseMessage.getBody(); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); + } else { - 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()); + 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())); + 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()); + } - 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()); } + //handle void operations + write(response.getOutputStream(), responseMessage.getBody()); + response.getOutputStream().flush(); + response.getOutputStream().close(); } - - //handle void operations - write(response.getOutputStream(), responseMessage.getBody()); - response.getOutputStream().flush(); - response.getOutputStream().close(); + } else { + super.service(request, response); } - } else { - super.service(request, response); + } finally { + ThreadHTTPContext.removeHTTPContext(); } - } @Override @@ -156,8 +163,8 @@ public class RESTBindingListenerServlet extends HttpServlet { } // Route message based on availability of cache info and cache methods - if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalGetInvoker != null )) { - if(id != null && id.length() > 0) { + if ((cacheContext != null) && (cacheContext.isEnabled()) && (conditionalGetInvoker != null)) { + if (id != null && id.length() > 0) { requestMessage.setBody(new Object[] {id, cacheContext}); } else { requestMessage.setBody(new Object[] {cacheContext}); @@ -165,7 +172,7 @@ public class RESTBindingListenerServlet extends HttpServlet { responseMessage = conditionalGetInvoker.invoke(requestMessage); } else { - if(id != null && id.length() > 0) { + if (id != null && id.length() > 0) { requestMessage.setBody(new Object[] {id}); } else { //requestMessage.setBody(new Object[] {id}); @@ -178,18 +185,18 @@ public class RESTBindingListenerServlet extends HttpServlet { Object body = responseMessage.getBody(); int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) { - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + if (-1 < (index = body.getClass().getName().indexOf("NotModifiedException"))) { + if (index > -1) { + response.sendError(HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring(index)); } else { - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); } return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) { - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + } else if (-1 < (index = body.getClass().getName().indexOf("PreconditionFailedException"))) { + if (index > -1) { + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring(index)); } else { - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } @@ -197,10 +204,10 @@ public class RESTBindingListenerServlet extends HttpServlet { throw new ServletException((Throwable)responseMessage.getBody()); } - if(response.getContentType() == null || response.getContentType().length() == 0){ + 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) { + if (contentType != null && contentType.length() > 0) { response.setContentType(contentType); } } @@ -221,10 +228,11 @@ public class RESTBindingListenerServlet extends HttpServlet { } @Override - protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { // Get the request path String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { + if (path.length() == 0) { // Redirect to a URL ending with / to make relative hrefs work // relative to the served resource. response.sendRedirect(request.getRequestURL().append('/').toString()); @@ -243,7 +251,7 @@ public class RESTBindingListenerServlet extends HttpServlet { } // Route message based on availability of cache info and cache methods - if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalDeleteInvoker != null )) { + if ((cacheContext != null) && (cacheContext.isEnabled()) && (conditionalDeleteInvoker != null)) { requestMessage.setBody(new Object[] {id, cacheContext}); responseMessage = conditionalDeleteInvoker.invoke(requestMessage); } else { @@ -254,18 +262,18 @@ public class RESTBindingListenerServlet extends HttpServlet { Object body = responseMessage.getBody(); int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) { - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + if (-1 < (index = body.getClass().getName().indexOf("NotModifiedException"))) { + if (index > -1) { + response.sendError(HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring(index)); } else { - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); } return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) { - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + } else if (-1 < (index = body.getClass().getName().indexOf("PreconditionFailedException"))) { + if (index > -1) { + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring(index)); } else { - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } @@ -292,7 +300,7 @@ public class RESTBindingListenerServlet extends HttpServlet { protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get the request path String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { + if (path.length() == 0) { // Redirect to a URL ending with / to make relative hrefs work // relative to the served resource. response.sendRedirect(request.getRequestURL().append('/').toString()); @@ -311,7 +319,7 @@ public class RESTBindingListenerServlet extends HttpServlet { } // Route message based on availability of cache info and cache methods - if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPutInvoker != null )) { + if ((cacheContext != null) && (cacheContext.isEnabled()) && (conditionalPutInvoker != null)) { requestMessage.setBody(new Object[] {id, cacheContext}); responseMessage = conditionalPutInvoker.invoke(requestMessage); } else { @@ -322,18 +330,18 @@ public class RESTBindingListenerServlet extends HttpServlet { Object body = responseMessage.getBody(); int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) { - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + if (-1 < (index = body.getClass().getName().indexOf("NotModifiedException"))) { + if (index > -1) { + response.sendError(HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring(index)); } else { - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); } return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) { - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + } else if (-1 < (index = body.getClass().getName().indexOf("PreconditionFailedException"))) { + if (index > -1) { + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring(index)); } else { - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } @@ -357,10 +365,11 @@ public class RESTBindingListenerServlet extends HttpServlet { } @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { // Get the request path String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { + if (path.length() == 0) { // Redirect to a URL ending with / to make relative hrefs work // relative to the served resource. response.sendRedirect(request.getRequestURL().append('/').toString()); @@ -374,59 +383,57 @@ public class RESTBindingListenerServlet extends HttpServlet { Message responseMessage = null; HTTPCacheContext cacheContext = null; try { - cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); + cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); } catch (ParseException e) { } // Route message based on availability of cache info and cache methods - if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPostInvoker != null )) { - requestMessage.setBody(new Object[] {cacheContext}); - responseMessage = conditionalPostInvoker.invoke(requestMessage); + if ((cacheContext != null) && (cacheContext.isEnabled()) && (conditionalPostInvoker != null)) { + requestMessage.setBody(new Object[] {cacheContext}); + responseMessage = conditionalPostInvoker.invoke(requestMessage); } else { - requestMessage.setBody(new Object[] {}); - responseMessage = postInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {}); + responseMessage = postInvoker.invoke(requestMessage); } if (responseMessage.isFault()) { - Object body = responseMessage.getBody(); - - int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); - return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); - return; + Object body = responseMessage.getBody(); + + int index = -1; + if (-1 < (index = body.getClass().getName().indexOf("NotModifiedException"))) { + if (index > -1) + response.sendError(HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring(index)); + else + response.sendError(HttpServletResponse.SC_NOT_MODIFIED); + return; + } else if (-1 < (index = body.getClass().getName().indexOf("PreconditionFailedException"))) { + if (index > -1) + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring(index)); + else + response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); + return; } throw new ServletException((Throwable)responseMessage.getBody()); } - // Test if the ETag and LastModified are returned as a cache context. - Object body = responseMessage.getBody(); - if ( body.getClass() == HTTPCacheContext.class ) { - // Transfer to header if so. - HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody(); - if (( cc != null ) && ( cc.isEnabled() )) { - String eTag = cc.getETag(); - if ( eTag != null ) { - response.setHeader( "ETag", cc.getETag() ); - } - String lastModified = cc.getLastModified(); - if ( lastModified != null) { - response.setHeader( "LastModified", cc.getLastModified() ); - } - } - } + Object body = responseMessage.getBody(); + if (body.getClass() == HTTPCacheContext.class) { + // Transfer to header if so. + HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody(); + if ((cc != null) && (cc.isEnabled())) { + String eTag = cc.getETag(); + if (eTag != null) { + response.setHeader("ETag", cc.getETag()); + } + String lastModified = cc.getLastModified(); + if (lastModified != null) { + response.setHeader("LastModified", cc.getLastModified()); + } + } + } } - public void setInvoker(Invoker invoker) { this.invoker = invoker; } @@ -435,7 +442,6 @@ public class RESTBindingListenerServlet extends HttpServlet { return invoker; } - /** * @return the getInvoker */ @@ -554,8 +560,6 @@ public class RESTBindingListenerServlet extends HttpServlet { * */ - - private void write(OutputStream out, Object obj) throws IOException { if (obj == null) { return; @@ -579,5 +583,4 @@ public class RESTBindingListenerServlet extends HttpServlet { } } - } 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 c8b0bbf595..d65163949a 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 @@ -36,6 +36,7 @@ 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.common.http.ThreadHTTPContext; import org.apache.tuscany.sca.common.http.cors.CORSHeaderProcessor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -48,19 +49,19 @@ import org.apache.tuscany.sca.invocation.MessageFactory; * @version $Rev$ $Date$ */ public class RESTServiceListenerServlet extends HttpServlet implements Servlet { - + private static final long serialVersionUID = -5543706958107836637L; - + transient private RESTBinding binding; transient private ServletConfig config; transient private MessageFactory messageFactory; transient private Invoker serviceInvoker; - + /** * Constructs a new HTTPServiceListenerServlet. */ public RESTServiceListenerServlet(Binding binding, Invoker serviceInvoker, MessageFactory messageFactory) { - this.binding = (RESTBinding) binding; + this.binding = (RESTBinding)binding; this.serviceInvoker = serviceInvoker; this.messageFactory = messageFactory; } @@ -78,7 +79,7 @@ public class RESTServiceListenerServlet extends HttpServlet implements Servlet { } public void destroy() { - + } @Override @@ -89,34 +90,40 @@ public class RESTServiceListenerServlet extends HttpServlet implements Servlet { HTTPContext bindingContext = new HTTPContext(); bindingContext.setHttpRequest(request); bindingContext.setHttpResponse(response); - - // Dispatch the service interaction to the service invoker - Message requestMessage = messageFactory.createMessage(); - requestMessage.setBindingContext(bindingContext); - requestMessage.setBody(new Object[]{request, response}); - Message responseMessage = serviceInvoker.invoke(requestMessage); - if (responseMessage.isFault()) { - // Turn a fault into an exception - //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()); - } + ThreadHTTPContext.setHTTPContext(bindingContext); + try { + + // Dispatch the service interaction to the service invoker + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBindingContext(bindingContext); + requestMessage.setBody(new Object[] {request, response}); + Message responseMessage = serviceInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + // Turn a fault into an exception + //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()); + } + + } } + } finally { + ThreadHTTPContext.removeHTTPContext(); } } } -- cgit v1.2.3