mraible commented on code in PR #171: URL: https://github.com/apache/roller/pull/171#discussion_r3891439511
########## app/src/main/java/org/apache/roller/weblogger/ui/core/filters/XmlRpcEnabledFilter.java: ########## @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. The ASF licenses this file to You + * under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. For additional information regarding + * copyright in this work, please see the NOTICE file in the top level + * directory of this distribution. + */ + +package org.apache.roller.weblogger.ui.core.filters; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.roller.weblogger.config.WebloggerRuntimeConfig; + +/** + * Gates the XML-RPC endpoint on <code>webservices.enableXmlRpc</code>, ahead of + * the servlet, so a disabled service is not reachable. + */ +public class XmlRpcEnabledFilter implements Filter { + + private static final Log LOG = LogFactory.getLog(XmlRpcEnabledFilter.class); + + @Override + public void init(FilterConfig filterConfig) { + // nothing to configure + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (!WebloggerRuntimeConfig.getBooleanProperty("webservices.enableXmlRpc")) { + if (LOG.isDebugEnabled()) { + LOG.debug("XML-RPC service is disabled; rejecting request"); + } + ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND); Review Comment: `sendError(404)` gets routed to `/roller-ui/errors/404.jsp`, so a disabled endpoint now answers a desktop client's POST with an HTML page instead of the XML-RPC fault `BLOGGERAPI_DISABLED_MSG` that `BaseAPIHandler` still produces (line 152) but can no longer reach. Clients like `MarsEdit` will show a generic "invalid response". Consider writing a small XML-RPC fault with `text/xml` here, or at least `setStatus(404)` with a plain-text body so the error JSP isn't rendered. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
