Commit cfd309b6 authored by Matija Obreza's avatar Matija Obreza
Browse files

Logging reduced

- LocaleWrappedServletResponse
- LocaleURLFilter
parent 54a2b807
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.servlet.filter; package org.genesys2.server.servlet.filter;
...@@ -34,6 +34,9 @@ import org.apache.commons.lang.StringUtils; ...@@ -34,6 +34,9 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
* Handles the very important locale selection by URL
*/
public class LocaleURLFilter implements Filter { public class LocaleURLFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(LocaleURLFilter.class); private static final Logger LOG = LoggerFactory.getLogger(LocaleURLFilter.class);
...@@ -75,14 +78,11 @@ public class LocaleURLFilter implements Filter { ...@@ -75,14 +78,11 @@ public class LocaleURLFilter implements Filter {
@Override @Override
public void destroy() { public void destroy() {
if (LOG.isDebugEnabled()) { LOG.info("Destroying LocaleURLFilter");
LOG.debug("Destroying LocaleURLFilter");
}
} }
@Override @Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
final HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; final HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
final String url = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()); final String url = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length());
...@@ -92,9 +92,7 @@ public class LocaleURLFilter implements Filter { ...@@ -92,9 +92,7 @@ public class LocaleURLFilter implements Filter {
return; return;
} }
if (LOG.isDebugEnabled()) { LOG.trace("Incoming URL: {}", url);
LOG.debug("Incoming URL: {}", url);
}
final Matcher matcher = localeUrlMatcher.matcher(url); final Matcher matcher = localeUrlMatcher.matcher(url);
if (matcher.matches()) { if (matcher.matches()) {
...@@ -132,33 +130,29 @@ public class LocaleURLFilter implements Filter { ...@@ -132,33 +130,29 @@ public class LocaleURLFilter implements Filter {
httpRequest.setAttribute(REQUEST_LOCALE_ATTR, urlLocale); httpRequest.setAttribute(REQUEST_LOCALE_ATTR, urlLocale);
httpRequest.setAttribute(REQUEST_INTERNAL_URL, getInternalUrl(remainingUrl, httpRequest.getQueryString())); httpRequest.setAttribute(REQUEST_INTERNAL_URL, getInternalUrl(remainingUrl, httpRequest.getQueryString()));
if (LOG.isDebugEnabled()) { if (LOG.isTraceEnabled()) {
LOG.debug("URL matches! lang={} remaining={}", urlLanguage, remainingUrl); LOG.trace("URL matches! lang={} remaining={}", urlLanguage, remainingUrl);
LOG.debug("Country: {} Lang: {} locale={}", urlLocale.getCountry(), urlLocale.getLanguage(), urlLocale); LOG.trace("Country: {} Lang: {} locale={}", urlLocale.getCountry(), urlLocale.getLanguage(), urlLocale);
final Enumeration<String> attrNames = httpRequest.getAttributeNames(); final Enumeration<String> attrNames = httpRequest.getAttributeNames();
while (attrNames.hasMoreElements()) { while (attrNames.hasMoreElements()) {
final String attrName = attrNames.nextElement(); final String attrName = attrNames.nextElement();
LOG.debug("Request attr {} = {}", attrName, httpRequest.getAttribute(attrName)); LOG.trace("Request attr {} = {}", attrName, httpRequest.getAttribute(attrName));
} }
LOG.debug("Proxying request to remaining URL {}", remainingUrl); LOG.trace("Proxying request to remaining URL {}", remainingUrl);
} }
final LocaleWrappedServletResponse localeResponse = new LocaleWrappedServletResponse(httpResponse, localeUrlMatcher, urlLanguage, final LocaleWrappedServletResponse localeResponse = new LocaleWrappedServletResponse(httpResponse, localeUrlMatcher, urlLanguage, defaultLocale.toLanguageTag());
defaultLocale.toLanguageTag());
final LocaleWrappedServletRequest localeRequest = new LocaleWrappedServletRequest(httpRequest, url, remainingUrl); final LocaleWrappedServletRequest localeRequest = new LocaleWrappedServletRequest(httpRequest, url, remainingUrl);
// request.getRequestDispatcher(remainingUrl == null ? "/" : // request.getRequestDispatcher(remainingUrl == null ? "/" :
// remainingUrl).forward(servletRequest, localeResponse); // remainingUrl).forward(servletRequest, localeResponse);
filterChain.doFilter(localeRequest, localeResponse); filterChain.doFilter(localeRequest, localeResponse);
} else { } else {
if (LOG.isDebugEnabled()) { LOG.trace("No match on url {}", url);
LOG.debug("No match on url {}", url);
}
httpRequest.setAttribute(REQUEST_INTERNAL_URL, getInternalUrl(url, httpRequest.getQueryString())); httpRequest.setAttribute(REQUEST_INTERNAL_URL, getInternalUrl(url, httpRequest.getQueryString()));
final LocaleWrappedServletResponse localeResponse = new LocaleWrappedServletResponse(httpResponse, localeUrlMatcher, null, final LocaleWrappedServletResponse localeResponse = new LocaleWrappedServletResponse(httpResponse, localeUrlMatcher, null, defaultLocale.toLanguageTag());
defaultLocale.toLanguageTag());
filterChain.doFilter(servletRequest, localeResponse); filterChain.doFilter(servletRequest, localeResponse);
} }
} }
......
...@@ -51,9 +51,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper { ...@@ -51,9 +51,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper {
return super.encodeURL(url); return super.encodeURL(url);
} else { } else {
String encodedURL = prefix + super.encodeURL(url); String encodedURL = prefix + super.encodeURL(url);
if (LOG.isDebugEnabled()) { LOG.trace("encodeURL {} to {}", url, encodedURL);
LOG.debug("encodeURL {} to {}", url, encodedURL);
}
return encodedURL; return encodedURL;
} }
} }
...@@ -65,9 +63,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper { ...@@ -65,9 +63,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper {
return super.encodeUrl(url); return super.encodeUrl(url);
} else { } else {
String encodedURL = prefix + super.encodeUrl(url); String encodedURL = prefix + super.encodeUrl(url);
if (LOG.isDebugEnabled()) { LOG.trace("encodeUrl {} to {}", url, encodedURL);
LOG.debug("encodeUrl {} to {}", url, encodedURL);
}
return encodedURL; return encodedURL;
} }
} }
...@@ -78,9 +74,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper { ...@@ -78,9 +74,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper {
return super.encodeRedirectURL(url); return super.encodeRedirectURL(url);
} else { } else {
String encodedURL = prefix + super.encodeRedirectURL(url); String encodedURL = prefix + super.encodeRedirectURL(url);
if (LOG.isDebugEnabled()) { LOG.trace("encodeRedirectURL {} to {}", url, encodedURL);
LOG.debug("encodeRedirectURL {} to {}", url, encodedURL);
}
return encodedURL; return encodedURL;
} }
} }
...@@ -92,9 +86,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper { ...@@ -92,9 +86,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper {
return super.encodeRedirectUrl(url); return super.encodeRedirectUrl(url);
} else { } else {
String encodedURL = prefix + super.encodeRedirectUrl(url); String encodedURL = prefix + super.encodeRedirectUrl(url);
if (LOG.isDebugEnabled()) { LOG.trace("encodeRedirectUrl {} to {}", url, encodedURL);
LOG.debug("encodeRedirectUrl {} to {}", url, encodedURL);
}
return encodedURL; return encodedURL;
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment