I'm running Mule 3.8 CE and my JAXB context and marshaller always create files declared like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
However the files are always UTF-16, and they get marshalled to utf-16, but the declaration says otherwise and I haven't found a way to solve that. I'm not sure how to set properties on my marshaller in Mule?
Feels a little stupid to have an external script just for replacing that string.
Regards
Related
I know Spring Integration is rather old but I have a piece of code that needs small modification to move on. I need to split the incoming XML message and preserve the parent node. Here is my XML:
<Order>
<Item>A</Item>
<Item>B</Item>
</Order>
And I want to split into 2 XMLs and preserve the XSD validation.
<Order>
<Item>A</Item>
</Order>
and
<Order>
<Item>B</Item>
</Order>
Did this:
<beans xmlns:int-xml="http://www.springframework.org/schema/integration/xml">
...
<int-xml:xpath-splitter id="splitter">
<int-xml:xpath-expression expression="/Order/Item"/>
</int-xml:xpath-splitter>
...
It split into
<Item>A</Item>
and
<Item>B</Item>
but I need the parent to be there. Anyway to make it works? Thanks in Advance.
What you need is an <int-xml:xslt-transformer> after your <int-xml:xpath-splitter>.
See Reference Manual for more info: https://docs.spring.io/spring-integration/docs/5.2.0.RELEASE/reference/html/xml.html#xml-xslt-payload-transformers
You need to learn what is XSLT and so on.
I know Spring Integration is rather old
??
It is actively maintained and enhanced; there was a completely new release this month.
You either need a custom splitter, or you can add a transformer after the splitter to add the outer node.
I have the same problem as Set request character encoding of JSF input submitted values to UTF-8 in GlassFish, the submitted values arrive as Mojibake. However, the answer is targeted at GlassFish and I'm using JBoss AS 7.
I've already specified the JDBC connection URL to use UTF-8:
jdbc:mysql://localhost:3306/mydb?useUnicode=yes&characterEncoding=UTF-8
And in top of my JSF page:
<?xml version='1.0' encoding='UTF-8' ?>
How can I solve the same problem in JBoss AS 7? Or better, in a more generic way so that it works in all servers?
The question which you linked to has already excluded the DB encoding from being the cause because the problem already occurs during printing/redisplaying the submitted value before saving in DB. Thus, the problem is in HTTP request encoding.
Your JDBC connection URL with the charset specified,
jdbc:mysql://localhost:3306/mydb?useUnicode=yes&characterEncoding=UTF-8
only tells the MySQL JDBC driver to use UTF-8 to decode values in SQL queries before sending it to DB. This is not only completely beyond JSF's scope, but this is also not the cause of your problem, provided that you're absolutely positive that you've the same problem as in the linked question.
Your XML prolog with the charset specified,
<?xml version='1.0' encoding='UTF-8' ?>
only tells the XML parser to use UTF-8 to decode the XML source before building the XML tree around it. The XML parser actually being used is SAX as internally used by Facelets during JSF view build time. This part has completely nothing to do with HTTP request/response encoding and is thus very unlikely the cause of your problem.
None of them sets the HTTP request encoding, while you need to set the HTTP request encoding. The question which you linked to already shows how to do that for the Glassfish server. In your case, you're however using JBoss AS server. The Glassfish-specific setting is then inapplicable and JBoss doesn't support anything like that. You'd need to bring in a custom servlet filter to do the job. E.g.
#WebFilter("/*")
public class CharacterEncodingFilter implements Filter {
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
// ...
}
In standalone.xml, add atributte url-charset="UTF-8" in the tag http-listener name="default", and add atributte default-encoding="UTF-8" in the tag servlet-container.
Adding this to JBOSS_HOME/standalone/configuration/standalone.xml solved it for me:
<system-properties>
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
</system-properties>
Got it from https://developer.jboss.org/message/643825#643825
I'm trying to make a section of my SOAP request look like this:
<![CDATA[<?xml version="1.0" encoding="UTF-8"?><placeholder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WirelessEdgeInfo_v1_0.xsd"/>]]>
However, it looks like this after it has been escaped by underlying JAXB:
<![CDATA[<?xml version="1.0"
encoding="UTF-8"?> <placeholder
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="WirelessEdgeInfo_v1_0.xsd"/>]]>
I have looked at numerous examples, such as using MOXy and also implementing a CharacterEscapeHandler adapter or XmlAdapter HOWEVER the problem is the same for ALL these implementations. That is, it always comes down to this:
marshaller.setProperty(CharacterEscapeHandler.class.getName(),
new XmlCharacterHandler());
Setting a property in the marshaller.
However, in my case, I am using annotations generated through WSImport to generate my Web Services code dynamically when I execute the client SOAP call.
i.e. I do not have access to the marshaller object.
SO for me, how can I unescape the CDATA section of a String variable I need to pass in if I cannot set any property on the marshaller type?
Can I somehow "hack" or trick JAXB to tell it not to escape CDATA values? Or can I use annotations or somehow dynamically indicate unescaping?
I tried the following Adapter via annotation but of course this did not work:
#XmlJavaTypeAdapter(value=CDATAAdapter.class) //this is not working right now
protected String variableXmlContent;
variableXmlContent still ended up escaped. I also tried unescaping variableXmlContent and setting it as an input value, but it still came out the same way, unescaped.
An XML element value containing <, >, & is escaped by the marshaller using <, >, &.
Thus, if the XML element should contain
<![CDATA[ ... ]]>
the result in the XML file will be
<![CDATA[ ... ]]>
I suspect that the text to be passed as an XML element is
<?xml version="1.0" ... v1_0.xsd"/>
Now if I had to write this by hand into an XML file, I'd write it into a "CDATA section", but a (JAXB) marshaller will simply treat those three characters as I described before, and that's it.
<?xml version="1.0" ... v1_0.xsd"/>
It is pointless to try and make any XML marshaller use the CDATA mechanism, and there is no such thing as a "CDATA value" requiring special treatment - so there is no such special treatment.
I see that Android Studio creates all XML layout files without the starting
<?xml version="1.0" encoding="utf-8"?>
When did this become unnecessary? I remember that previously it would have generated compile-time error.
If it did not become unnecessary, but the compiler simply ignores it, is it a good practice not to use it?
I'm working in an erp project using Visual Studio 2008 Sp1, I've a typed dataset it was containg alot of datatable and alot of table adapter the .Designer.cs file was 8 MB, suddenly when i was trying to openit using visual studio designer the following code comes to me
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="erpDataSet" targetNamespace="http://tempuri.org/erpDataSet1.xsd" xmlns:mstns="http://tempuri.org/erpDataSet1.xsd" xmlns="http://tempuri.org/erpDataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<Connections>
<Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="erpConnectionString" IsAppSettingsProperty="true" Modifier="Assembly" Name="erpConnectionString (Settings)" ParameterPrefix="#" PropertyReference="ApplicationSettings.Sbic.Pro
My XSD file content has gone, :( :( :(
I don't understand why, and how can i recover it.
i mad something but i don't know if it is the reason for that or not, My connectionstring was in the settings "app.config" i removed it and add it to the resources of another project that is refernced by the main project.
what can i do, pleaze help me.
If I understand your problem, you were adding code to the ".Designer.cs". That file is an auto-generated file. Every time you re-save the XSD file, the designer.cs file will be regenerated. You should never add content to a designer.cs file. If you need to add functionality to the dataset, you can extend the dataset by making a "partial" class in a different file using the same namespace that you find in the generated file.