Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
dfdfe6d0
Commit
dfdfe6d0
authored
Nov 06, 2014
by
Matija Obreza
Browse files
Locale filter cleanup
parent
cc209fb2
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/servlet/controller/HtmlController.java
View file @
dfdfe6d0
...
...
@@ -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
(
"
r
edirecting
!"
);
return
"redirect:/"
+
requestLocale
.
ge
tLanguage
()
+
"/welcome"
;
_logger
.
info
(
"
R
edirecting
to request locale: "
+
requestLocale
.
toLanguageTag
()
);
return
"redirect:/"
+
requestLocale
.
t
o
Language
Tag
().
toLowerCase
()
+
"/welcome"
;
}
return
"redirect:/welcome"
;
...
...
src/main/java/org/genesys2/server/servlet/filter/LocaleURLFilter.java
View file @
dfdfe6d0
/**
* 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
;
...
...
src/main/java/org/genesys2/server/servlet/filter/LocaleURLMatcher.java
View file @
dfdfe6d0
/**
* 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
;
...
...
src/main/java/org/genesys2/server/servlet/filter/LocaleWrappedServletRequest.java
View file @
dfdfe6d0
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
;
...
...
src/main/java/org/genesys2/server/servlet/filter/LocaleWrappedServletResponse.java
View file @
dfdfe6d0
/**
* 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
;
...
...
src/main/resources/log4j.properties
View file @
dfdfe6d0
...
...
@@ -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
src/main/webapp/WEB-INF/web.xml
View file @
dfdfe6d0
...
...
@@ -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>
...
...
src/test/java/org/genesys2/server/test/UrlrewriteTest.java
View file @
dfdfe6d0
/**
* 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
.*;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment