PDA

View Full Version : Quercus corrupts strings wehn they are read from Java objects


samol
01-19-2010, 01:04 PM
We have the following code:
$aff = AffirmationsRestService::getRandomAffirmation($loc ale, $field);

It returns a Java object, that has a field String text.

If we access this field with
$afftext = $aff->text;

The content of afftext is corrupted if text contains non ASCII characters.

For now we use a workarround:
$afftext = $aff->binText;

that calls this method:

public byte[] getBinText() {
try {
return text.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
return null;
}
}

As UTF-8 is the default encoding for converting bin content to strings, this works.

Regards
Samo

nam
01-20-2010, 10:26 PM
Quercus follows PHP in assuming strings are single-byte encoded (specifically ISO-8859-1). You may want to turn on unicode semantics by setting:

<web-app xmlns="http://caucho.com/ns/resin">
<servlet-mapping url-pattern="*.php"
servlet-class="com.caucho.quercus.servlet.QuercusServlet">
<init>
<php-ini>
<unicode-semantics>1</unicode-semantics>
</php-ini>
</init>
</servlet>
</web-app>

or by setting it in <ini-file>WEB-INF/php.ini</ini-file>

markostamcar
01-21-2010, 10:30 AM
nam,

We tried

<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
<init>
<php-ini>
<unicode.semantics>on</unicode.semantics>
<unicode.runtime_encoding>utf-8</unicode.runtime_encoding>
<unicode.output_encoding>utf-8</unicode.output_encoding>
</php-ini>
</init>
</servlet-mapping>

but it didn't help. What we wish to accomplish is to have a Unicode aware translation from Java String object to PHP variable. Any further advice would be much appreciated.

Setor
08-24-2011, 05:47 PM
If you have same problem as markostamcar, try


<web-app xmlns="http://caucho.com/ns/resin">
<servlet servlet-name="resin-php"
servlet-class="com.caucho.quercus.servlet.QuercusServlet"/>

<servlet-mapping url-pattern="*.php" servlet-name="resin-php" servlet-class="com.caucho.quercus.servlet.QuercusServlet">
<init>
<script-encoding>UTF-8</script-encoding>
<php-ini>
<unicode.semantics>on</unicode.semantics>
<unicode.runtime_encoding>UTF-8</unicode.runtime_encoding>
<unicode.output_encoding>UTF-8</unicode.output_encoding>
<unicode.http_input_encoding>UTF-8</unicode.http_input_encoding>
</php-ini>
</init>
</servlet-mapping>

</web-app>


Tag "servlet-mapping" MUST HAVE attribute servlet-class="com.caucho.quercus.servlet.QuercusServlet" !