mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-15 14:56:41 +00:00
Bug 4454: The client locale is now implicitly given to RPC services
using an http header
This commit is contained in:
1 parent
9b3c2a3669
commit
7b90a187cb
3 files changed
+35
-1
No files matched your search
@@ -2,7 +2,11 @@ package com.sap.sse.gwt.client;
|
||||
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.http.client.RequestBuilder;
|
||||
import com.google.gwt.i18n.client.LocaleInfo;
|
||||
import com.google.gwt.user.client.rpc.RpcRequestBuilder;
|
||||
import com.google.gwt.user.client.rpc.ServiceDefTarget;
|
||||
import com.sap.sse.gwt.shared.RpcConstants;
|
||||
|
||||
public class EntryPointHelper {
|
||||
/**
|
||||
@@ -18,6 +22,13 @@ public class EntryPointHelper {
|
||||
String moduleBaseURL = GWT.getModuleBaseURL();
|
||||
String baseURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf('/', moduleBaseURL.length()-2)+1);
|
||||
serviceToRegister.setServiceEntryPoint(baseURL + servicePath);
|
||||
serviceToRegister.setRpcRequestBuilder(new RpcRequestBuilder() {
|
||||
@Override
|
||||
protected void doFinish(RequestBuilder rb) {
|
||||
super.doFinish(rb);
|
||||
rb.setHeader(RpcConstants.HEADER_LOCALE, LocaleInfo.getCurrentLocale().getLocaleName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+19
-1
@@ -1,6 +1,7 @@
|
||||
package com.sap.sse.gwt.dispatch.servlets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -10,6 +11,7 @@ import com.google.gwt.user.client.rpc.SerializationException;
|
||||
import com.google.gwt.user.server.rpc.RPCServletUtils;
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.google.gwt.user.server.rpc.SerializationPolicy;
|
||||
import com.sap.sse.gwt.shared.RpcConstants;
|
||||
|
||||
/**
|
||||
* Using GWT in a proxyfied environment can be tricky and leads to strange errors
|
||||
@@ -66,5 +68,21 @@ public abstract class ProxiedRemoteServiceServlet extends RemoteServiceServlet {
|
||||
} else {
|
||||
super.doUnexpectedFailure(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Locale getClientLocale() {
|
||||
final HttpServletRequest request = getThreadLocalRequest();
|
||||
if (request != null) {
|
||||
final String localeString = request.getHeader(RpcConstants.HEADER_LOCALE);
|
||||
if (localeString != null && ! localeString.isEmpty()) {
|
||||
try {
|
||||
return Locale.forLanguageTag(localeString);
|
||||
} catch (Exception e) {
|
||||
// non-parseable locales are ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
// Using default locale if the client locale could not be determined
|
||||
return Locale.ENGLISH;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sap.sse.gwt.shared;
|
||||
|
||||
public interface RpcConstants {
|
||||
public static final String HEADER_LOCALE = "X-Client-Locale";
|
||||
}
|
||||
Reference in new issue
Block a user