Why is the characterset changing if starting Glassfish using php_exec compared to starting it in the console?

by Attila Antal   Last Updated October 09, 2019 23:00 PM

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!



Related Questions


Updated June 30, 2016 08:00 AM

Updated August 01, 2018 15:00 PM

Updated July 24, 2015 13:00 PM

Updated July 13, 2019 05:00 AM

Updated January 14, 2016 12:00 PM