1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.ajax;
1819import javax.servlet.http.HttpServletResponse;
2021import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
22import org.apache.jetspeed.pipeline.PipelineException;
23import org.apache.jetspeed.pipeline.valve.AbstractValve;
24import org.apache.jetspeed.pipeline.valve.ValveContext;
25import org.apache.jetspeed.request.RequestContext;
2627/***28 * This should eventually replace the AJAX ServletFilter.29 * 30 * @author <href a="mailto:weaver@apache.org">Scott T. Weaver </a>31 * 32 */33publicclassAJAXValveextendsAbstractValve34 {
35private AJAXService ajaxService;
36private PortletActionSecurityBehavior securityBehavior;
3738publicAJAXValve(AJAXService service, PortletActionSecurityBehavior securityBehavior)
39 {
40super();
41this.ajaxService = service;
42this.securityBehavior = securityBehavior;
43 }
4445publicvoid invoke( RequestContext request, ValveContext context )
46 throws PipelineException
47 {
48 HttpServletResponse response = request.getResponse();
49try50 {
51 response.setContentType("text/xml");
52if (!securityBehavior.checkAccess(request, "edit"))
53 {
54thrownew AJAXException("Access Denied.");
55 }
56 AJAXRequest ajaxRequest = newAJAXRequestImpl(request.getRequest(), response, request.getConfig().getServletContext());
57 ajaxService.processRequest(ajaxRequest);
58 }
59catch (AJAXException e)
60 {
61try62 {
63 response.sendError(500, e.getMessage());
64 }
65catch (Exception e2)
66 {
67thrownew PipelineException(e2.getMessage(), e2);
68 }
69 }
70catch(Exception e)
71 {
72thrownew PipelineException(e.getMessage(), e);
73 }
7475// Pass control to the next Valve in the Pipeline76 context.invokeNext(request);
77 }
7879public String toString()
80 {
81return"AJAXValve";
82 }
83848586 }