0

I am using MobileFirst Platform Foundation 7.1 (7.1.0.00.20150913-2345) and I am using Java adapters and I have a custom login module with a custom authenticator and my code resembles this. In my case I have some non-ascii strings. For example:

In CustomAuthenticator instead of :

public AuthenticationResult processRequest(HttpServletRequest request, HttpServletResponse response, boolean isAccessToProtectedResource) throws IOException,   ServletException {
    ...
    response.getWriter()
      .print("{\"authStatus\":\"required\", \"errorMessage\":\"Please enter username and password\"}");
    ...
}

I have:

public AuthenticationResult processRequest(HttpServletRequest request, HttpServletResponse response, boolean isAccessToProtectedResource) throws IOException,   ServletException {
    ...
    response.getWriter()
      .print("{\"authStatus\":\"required\", \"errorMessage\":\"ユーザー名とパスワードを入力してください\"}");
    ...
}

In CustomLoginModule in login I have some exceptions with non-ascii strings:

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

When calling the adapter from an iOS native app: In Mac OSX it works great but the production server is in Windows and the iPad app receives the errorMessage as garbled text (mojibake 文字化け). Is there a way I can solve this?


In addition I have some non-ascii data in userIdentity object and when I try to access it in the Java Adapter it is garbled too:

@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.
}

What is weird is that I have another javascript adapter (that shares the same custom authenticator and login module) and getting the info from there is OK:

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

It looks like serialization of user data is buggy? Does anybody know if this is really a bug or a a mistake in some settings?

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
nacho4d
  • 43,720
  • 45
  • 157
  • 240

1 Answers1

0

It sounds like this could actually be due to the application server encoding.
See if the following helps: IBM Worklight - Error charset/encoding in data response from webservice

If the remote server is WebSphere Liberty, locate the jvm.options file and add the following:

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

If the remote server WebSphere ND, there is an Admin panel where you can set the encoding at. Consult with the WebShere documentation: http://www-01.ibm.com/support/knowledgecenter/SSEQTJ_8.5.5/com.ibm.websphere.nd.doc/ae/xrun_jvm.html

If the remote server is Tomcat: Change Tomcat's Charset.defaultCharset in windows

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89