2015-10-22 44 views
0

我正在使用MobileFirst Platform Foundation 7.1(7.1.0.00.20150913-2345),并且我正在使用Java适配器,并且我有一个定制登录模块和一个自定义身份验证器,我的代码类似于this 。在我的情况下,我有一些非ASCII字符串。例如:CustomAuthenticator和/或CustomLoginModule中的非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\":\"ユーザー名とパスワードを入力してください\"}"); 
    ... 
} 

在CustomLoginModule在login我有一些例外与非ASCII字符串:

public boolean login(Map<String, Object> authenticationData) { 
    ... 
     // Invalid credentials 
    throw new RuntimeException("有効なユーザーIDとパスワードを入力してください"); 
} 

从iOS本地应用程序调用适配器时:在Mac OSX中,它的效果很好但生产服务器在Windows中,并且iPad应用程序收到errorMessage为乱码文本(mojibake文字化け)。有没有办法解决这个问题?


另外我有过的UserIdentity对象一些非ASCII数据,当我尝试访问它在Java适配器是乱码太:

@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的适配器(共享相同的自定义认证和登录模块)和获取信息从那里是OK:

// Javascript Adapter 
function myProcedure(p){ 
    var user = WL.Server.getActiveUser(); 
    // user.displayName is OK in windows and OSX 
} 

它看起来像用户数据的序列化是越野车?有人知道这在某些环境中是真的是错误还是错误?

回答

0

听起来这可能实际上是由于应用程序服务器编码。
查看是否存在以下帮助:IBM Worklight - Error charset/encoding in data response from webservice

如果远程服务器的WebSphere自由,找到jvm.options文件,并添加以下内容:

-Dfile.encoding = UTF-8
-Duser.language = en
-Duser.country = US

如果远程服务器WebSphere ND有一个管理面板,您可以在其中设置编码。 http://www-01.ibm.com/support/knowledgecenter/SSEQTJ_8.5.5/com.ibm.websphere.nd.doc/ae/xrun_jvm.html

如果远程服务器是Tomcat的:与WebShere文档咨询Change Tomcat's Charset.defaultCharset in windows

+0

感谢!让我来试试这些后来将报告:) – nacho4d