我使用的是MobileFirst Platform Foundation 7.1(7.1.0.00.20150913-2345),我正在使用Java适配器,我有一个带有自定义身份验证器的自定义登录模块,我的代码类似于this。在我的情况下,我有一些非ascii字符串。例如:
在CustomAuthenticator中而不是:
public AuthenticationResult processRequest(HttpServletRequest request, HttpServletResponse response, boolean isAccessToProtectedResource) throws IOException, ServletException {
...
response.getWriter()
.print("{\"authStatus\":\"required\", \"errorMessage\":\"Please enter username and password\"}");
...
}
我有:
public AuthenticationResult processRequest(HttpServletRequest request, HttpServletResponse response, boolean isAccessToProtectedResource) throws IOException, ServletException {
...
response.getWriter()
.print("{\"authStatus\":\"required\", \"errorMessage\":\"ユーザー名とパスワードを入力してください\"}");
...
}
在login
的CustomLoginModule中,我对非ascii字符串有一些例外:
public boolean login(Map<String, Object> authenticationData) {
...
// Invalid credentials
throw new RuntimeException("有効なユーザーIDとパスワードを入力してください");
}
从iOS本机应用程序调用适配器时:在Mac OSX中它运行良好,但生产服务器在Windows中,而iPad应用程序收到errorMessage
乱码文本(mojibake文字化け)。有没有办法解决这个问题?
另外我在userIdentity对象中有一些非ascii数据,当我尝试在Java Adapter中访问它时,它也是乱码:
@POST
@Produces("application/json")
@Path("/enter")
@OAuthSecurity(scope="MyRealm")
public Response enter(){
SecurityAPI security = serverAPI.getSecurityAPI();
String displayName = security.getSecurityContext().getUserIdentity().getDisplayName();
// At this point displayName is garbled text when server is in windows. in OSX is OK.
}
奇怪的是,我有另一个javascript适配器(它共享相同的自定义验证器和登录模块)并从那里获取信息是好的:
// Javascript Adapter
function myProcedure(p){
var user = WL.Server.getActiveUser();
// user.displayName is OK in windows and OSX
}
看起来用户数据的序列化是错误的吗?有人知道在某些情况下这是真的是错误还是错误?
答案 0 :(得分:0)
听起来这实际上可能是由于应用程序服务器编码造成的 看看以下内容是否有帮助:IBM Worklight - Error charset/encoding in data response from webservice
如果远程服务器是WebSphere Liberty,请找到jvm.options文件并添加以下内容:
-Dfile.encoding = UTF-8
-Duser.language = EN
-Duser.country = US
如果是远程服务器WebSphere ND,则有一个Admin面板,您可以在其中设置编码。请参阅WebShere文档:http://www-01.ibm.com/support/knowledgecenter/SSEQTJ_8.5.5/com.ibm.websphere.nd.doc/ae/xrun_jvm.html
如果远程服务器是Tomcat:Change Tomcat's Charset.defaultCharset in windows