0

I have created a PHP script to start/stop GlassFish server. In the PHP, I am using the shell_exec method to execute the start-domain and stop-domain commands.

To start the server

shell_exec("sudo -u root /usr/local/glassfish3/bin/asadmin start-domain domain1");

To stop the server

shell_exec("sudo -u root /usr/local/glassfish3/bin/asadmin stop-domain domain1");

While the script does start and stop the server, there is an issue I can't figure out. The character encoding changes to something different and the special characters coming from the client requests are no longer formatted correctly.

Characters with correct charset

enter image description here

Characters with incorrect charset

enter image description here

Seems that the settings for UTF-8 are getting ignored and it falls back to a different charset what I believe to "ISO-8859-1".

domain.xml

<jdbc-connection-pool connection-validation-method="auto-commit" ...>
  <property name="characterEncoding" value="UTF-8"></property>
</jdbc-connection-pool>

sun-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
  <context-root>/some-directory-war</context-root>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class java code.</description>
    </property>
  </jsp-config>
  <!-- Change the default character encoding from ISO-8859-1 to UTF-8 -->
  <parameter-encoding default-charset="UTF-8"/>
</sun-web-app>

During my investigation I found numerous articles stating to define the character set in the sun-web.xml (older version of glassfish - my case) but does not help.

After some testing, I have noticed that if I login with www-data in the console, the default shell used is /bin/sh and starting the domain from that causes the same issue. However, if I switch to /bin/bash, then it works.

Does anyone have a clue what could be the difference?

Any information on this will be much appreciated!

Attila Antal
  • 101
  • 3

1 Answers1

0

Apparently the shell locale has an impact on how the GlassFish server interprets requests. I don't find it logical since the domain has its own settings file for that...

The following user comment actually helped: shell_exec

$locale = "en_US.UTF-8";
setlocale(LC_CTYPE, $locale);
putenv('LC_CTYPE=' . $locale);

shell_exec("sudo -u root /usr/local/glassfish3/bin/asadmin start-domain domain1");

It works like a charm!

Attila Antal
  • 101
  • 3