unicode characters in google cloud endpoints - google-cloud-endpoints

I'm developing a backend that should accept JSON objects and input them in the datastore if they meet certain criteria. My problem is that i get crippled content when i send json that has unicode letters . I have tried it with both the api explorer and rest client plugin for Firefox
my endpoint API method looks like this:
#ApiMethod(name = "addObj", httpMethod = "post" , path = "addObj")
public ArtObj addObj(ArtObj obj)
throws OAuthRequestException, IOException,IllegalArgumentException
{
}
and my Json looks like the following
{
someText:"محتوى عربى",
someEnglish : "English content"
}
According to many articles i did add this in my appengine-web.xml
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
<property name="file.encoding" value="UTF-8" />
<property name="DEFAULT_ENCODING" value="UTF-8" />
</system-properties>
but all i receive is a parsed POJO but with garbled unicode letters and perfect english .

I've found an answer to my question . I'm using windows and so the environment variable
JAVA_TOOL_OPTIONS has to be set to -Dfile.encoding=UTF8 to set the default encoding for the JVM . now i get correct JSON .
Thanks

I face the same problem to insert entity in Thai, my solutions is to open project properties window on Eclipse, under "Resource/Text file encoding" click "Other" and select "UTF-8" and it's work.

Related

Is there a REST API to get subfolders of the workspace in Tosca?

I am trying to build a UI based in Angular to retrieve all existing execution lists of Tosca. However, I could not find a REST API that can give the list of folders within a workspace in Tosca. Has anyone tried this route?
You can use the Search task on the projectto find all ExecutionLists.
Example:
{rest_url}/ToscaCommander/{workspace_name}/object/project/task/Search
as a post request with the xml payload:
<Parameters xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Parameter>
<Name>tqlString</Name>
<Type i:nil="true"/>
<Value>->SUBPARTS:TCFolder[Name=?"Execution"]=>SUBPARTS:ExecutionList</Value>
</Parameter>
</Parameters>
This will give you a list of object ids of the ExecustionLists contained in the Execution folder of the project. You can fetch the objects one by one with this request afterwards:
{rest_url}/ToscaCommander/{workspace_name}/object/{object_id}
Credits for this solution go to the development team of ToscaCommander - they provided it.
P.S.: as an answer for your comment:
Yes, there is a json equivalent of the body - but you do not need it. Anyway, here is the equivalent:
[{
"Name":"tqlString",
"Value":"->SUBPARTS:TCFolder[Name=?\"Execution\"]=>SUBPARTS:ExecutionList"
}]
If you want to get a json response (regardless of the request's payload's format) make sure your web.config sets AutomaticFormatSelectionEnabled to true (which should be the case). Then, in your requests, set the accept header accordingly:
Accept: application/json

Match XML elements/nodes that contain 'X' with XPath

I'm using the WP-Property and WP-Property: Importer plugins to manage properties on a WordPress powered website. The importer uses xpath rules to help map fields in an imported XML file to their corresponding field on the site.
e.g. 'Display Address' maps to 'address/full'
I have a set of elements that look like this:
<property>
<feature1>Feature</feature>
<feature2>Feature</feature>
<feature3>Feature</feature>
<feature4>Feature</feature>
<feature5>Feature</feature>
<address>
<full>abc</full>
<street>def</street>
<postcode>ghi</postcode>
</address>
</property>
I want to group these together into one entry rather than setting up separate fields for each one, so I'm looking for a means to match feature* but everything I've tried so far seems to have missed the mark. Goes without saying that I've never dabbled with xpath before today!

Double data output error using Freemarker and Spring mvc

I'm working on a website using freemarker and spring mvc to render json data, But I found the double value such as "14.1234" will be rendered as '14,1234' when client's language has bean setted to 'French'.
I hava the value setted in the freemarker configuration files:
<xml>.....
<prop key="locale">zh_CN</prop>
<prop key="number_format">#.#####</prop>
</xml>
What's going on?
In French you use , as the decimal separator. If you are printing not for humans, but for "computer audience", then you have to write ${myDouble?c}.

Character encoding issue with Spring MVC and HTML form

I'm working with spring mvc. I've set up a web form that has two simple text inputs. On controller, I use #ModelAttribute to let spring build the bean from the web form.
The problem comes when user puts on those text fields specials characters, like 酒店 and this kind of stuff, spring doesn't read it as utf-8, and they become the usual bad-encoded string.
I've checked web.xml and there's the utf-8 encoding filter, all pages are marqued as utf-8 and browser is sending right charset headers. Any idea on what's going on?
You may want to check this out:
http://forum.springsource.org/showthread.php?81858-ResponseBody-and-UTF-8
The short of it is that if you are using annotated methods then the messageconverter being used has a default character set. You can change this setting in your web.xml by setting the supported media types.
However, if your service doesn't like that media type, you may get a 406 error. You can create your own string message converter and set the default encoding, but there is no easy way with the built in HttpStringMessageConverter.
Alternately you can re-encode a string to a different character set:
String newresponse = new String(responseString.getBytes("ISO-8859-1"), "UTF-8");
You may also want to check out the related question here: How to get UTF-8 working in Java webapps?
the solution is simple by add produces = "text/plain;charset=UTF-8" to request mapping you can force spring mvc to encode the returned text.

WebService remove <xml> tag from my XmlDocument

I use a WebService to transform and XmlDocument into a PDF.
The XmlDocument I send to the Web service looks like this.
<?xml version="1.0" encoding="utf-16" ?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
...
</fo:root>
I had a problem so I went in debug mod to find out that when the XmlDocument object is transferred from my asp website itself to the Web Service which works on .NET 1.1 sees his
xml tag. Is there a reason why this tag is removed? Could it be caused by the SOAP response?
Is there a way around other than manually add the tag back in the document?
Edit
To answer John's question, yes I mean the processing instruction. It just goes off and I was wondering why because the library I use to convert doesn't work without it. If I manually add it, it works fine but I just wanted to know why it disappear.
Edit 2
Even if it isn't a tag, the library that requires the XmlDocument just doesn't work without it that's why I need it. Other than that, the rest of the document is processed correctly. The generated Reference.cs from the Web Reference looked like this for the called method :
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GeneratePdfFromXml", RequestNamespace="http://tempuri.org", ResponseNamespace="http://tempuri.org", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")]
public byte[] GeneratePdfFromXml(XmlNode FormattedObjectXml) {
object[] results = this.Invoke("GeneratePdfFromXml", new object[] {
FormattedObjectXml});
return ((byte[])(results[0]));
}
It is the same issue as another problem I had, in which the XmlDocument are referenced as XmlNode since the SOAP response is a XmlDocument itself.
I just changed this to a string ; MyXmlDocument.OuterXml;
That way, everything is kept and no problem.
It is most likely an encoding issue. The XML Declaration is claiming the document is in UTF-16, which is two bytes per character. The other library probably is assuming, in its absence, some other encoding.
You will never get an XML Declaration or processing instruction passed to via an XmlNode, XmlElement or XmlDocument parameter to an ASMX service. The reason is obvious if you think about it. The SOAP Request would be something like:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Body>
<parameter>
<?xml version="1.0" encoding="utf-16" ?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
</fo:root>
</parameter>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But an XML declaration can only appear at the very beginning of the document, so this is invalid.
The solution, as you found, is to send this XML as a string. Make your parameter type string, and either use XmlNode.OuterXml.

Resources