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

Locale filter cleanup

parent cc209fb2
......@@ -85,11 +85,13 @@ public class HtmlController extends BaseController {
Locale requestLocale = request.getLocale();
Locale requestedLocale = (Locale) request.getAttribute(LocaleURLFilter.REQUEST_LOCALE_ATTR);
System.err.println("Request locale: " + requestLocale + " detected: " + requestedLocale);
if (_logger.isDebugEnabled()) {
_logger.debug("Request locale: " + requestLocale + " requested: " + requestedLocale);
}
if (requestedLocale == null && requestLocale != null) {
System.err.println("redirecting!");
return "redirect:/" + requestLocale.getLanguage() + "/welcome";
_logger.info("Redirecting to request locale: " + requestLocale.toLanguageTag());
return "redirect:/" + requestLocale.toLanguageTag().toLowerCase() + "/welcome";
}
return "redirect:/welcome";
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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.
**/
package org.genesys2.server.servlet.filter;
import java.io.IOException;
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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.
**/
package org.genesys2.server.servlet.filter;
import java.util.regex.Matcher;
......
package org.genesys2.server.servlet.filter;
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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.
**/
import java.io.IOException;
import java.util.Collection;
package org.genesys2.server.servlet.filter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.Part;
import org.apache.log4j.Logger;
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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.
**/
package org.genesys2.server.servlet.filter;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
public class LocaleWrappedServletResponse extends HttpServletResponseWrapper {
......@@ -74,11 +91,7 @@ public class LocaleWrappedServletResponse extends HttpServletResponseWrapper {
}
private String updatePrefix(String language) {
if (language == null || language.length() != 2) {
language = null;
}
if (language == null) {
if (StringUtils.isBlank(language)) {
return "";
} else {
return "/" + language;
......
......@@ -25,7 +25,6 @@ log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %t %5p %c{1}:%L - %m
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=info, stdout
log4j.category.org.genesys2.server.servlet.filter=debug
#log4j.category.org.genesys2=debug
#log4j.category.org.hibernate.search=debug
#log4j.category.org.apache.tomcat.jdbc.pool=debug
......@@ -38,4 +37,5 @@ log4j.category.org.genesys2.server.servlet.filter=debug
#log4j.category.com.hazelcast.web=debug
#log4j.category.com.hazelcast.aws=trace
#log4j.category.org.eclipse.jetty.servlets=trace
log4j.category.org.tuckey.web=trace
\ No newline at end of file
#LocaleURLFilter
#log4j.category.org.genesys2.server.servlet.filter=debug
......@@ -45,24 +45,24 @@
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>sysout:DEBUG</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>10</param-value>
</init-param>
<!-- <init-param>
<param-name>logLevel</param-name>
<param-value>sysout:DEBUG</param-value>
</init-param> -->
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<filter-name>localeURLFilter</filter-name>
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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.
**/
package org.genesys2.server.test;
import static org.junit.Assert.*;
......
Markdown is supported
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