Add CORS support for servlet based impl with REST binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1341952 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
98c732a3f4
commit
c918a7b508
3 changed files with 9 additions and 0 deletions
|
@ -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.HTTPContentTypeMapper;
|
||||||
import org.apache.tuscany.sca.common.http.HTTPContext;
|
import org.apache.tuscany.sca.common.http.HTTPContext;
|
||||||
import org.apache.tuscany.sca.common.http.HTTPHeader;
|
import org.apache.tuscany.sca.common.http.HTTPHeader;
|
||||||
|
import org.apache.tuscany.sca.common.http.cors.CORSHeaderProcessor;
|
||||||
import org.apache.tuscany.sca.invocation.Invoker;
|
import org.apache.tuscany.sca.invocation.Invoker;
|
||||||
import org.apache.tuscany.sca.invocation.Message;
|
import org.apache.tuscany.sca.invocation.Message;
|
||||||
import org.apache.tuscany.sca.invocation.MessageFactory;
|
import org.apache.tuscany.sca.invocation.MessageFactory;
|
||||||
|
@ -78,6 +79,9 @@ public class RESTBindingListenerServlet extends HttpServlet {
|
||||||
|
|
||||||
@Override
|
@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) {
|
if( binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) {
|
||||||
HTTPContext bindingContext = new HTTPContext();
|
HTTPContext bindingContext = new HTTPContext();
|
||||||
bindingContext.setHttpRequest(request);
|
bindingContext.setHttpRequest(request);
|
||||||
|
|
|
@ -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.HTTPCacheContext;
|
||||||
import org.apache.tuscany.sca.common.http.HTTPContext;
|
import org.apache.tuscany.sca.common.http.HTTPContext;
|
||||||
import org.apache.tuscany.sca.common.http.HTTPHeader;
|
import org.apache.tuscany.sca.common.http.HTTPHeader;
|
||||||
|
import org.apache.tuscany.sca.common.http.cors.CORSHeaderProcessor;
|
||||||
import org.apache.tuscany.sca.invocation.Invoker;
|
import org.apache.tuscany.sca.invocation.Invoker;
|
||||||
import org.apache.tuscany.sca.invocation.Message;
|
import org.apache.tuscany.sca.invocation.Message;
|
||||||
import org.apache.tuscany.sca.invocation.MessageFactory;
|
import org.apache.tuscany.sca.invocation.MessageFactory;
|
||||||
|
@ -82,6 +83,9 @@ public class RESTServiceListenerServlet extends HttpServlet implements Servlet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
if (binding.isCORS()) {
|
||||||
|
CORSHeaderProcessor.processCORS(binding.getCORSConfiguration(), request, response);
|
||||||
|
}
|
||||||
HTTPContext bindingContext = new HTTPContext();
|
HTTPContext bindingContext = new HTTPContext();
|
||||||
bindingContext.setHttpRequest(request);
|
bindingContext.setHttpRequest(request);
|
||||||
bindingContext.setHttpResponse(response);
|
bindingContext.setHttpResponse(response);
|
||||||
|
|
|
@ -205,6 +205,7 @@ public class RESTBindingProcessor extends BaseStAXArtifactProcessor implements S
|
||||||
restBinding.setResponseWireFormat((WireFormat)extension);
|
restBinding.setResponseWireFormat((WireFormat)extension);
|
||||||
} else if(extension instanceof OperationSelector) {
|
} else if(extension instanceof OperationSelector) {
|
||||||
restBinding.setOperationSelector((OperationSelector)extension);
|
restBinding.setOperationSelector((OperationSelector)extension);
|
||||||
|
restBinding.setCORS(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue