[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-07 Thread Alex Dettinger (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16429421#comment-16429421
 ] 

Alex Dettinger commented on CAMEL-12415:


Indeed, it's safe. I will backport.

> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Assignee: Alex Dettinger
>Priority: Minor
> Fix For: 2.22.0
>
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-07 Thread Claus Ibsen (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16429276#comment-16429276
 ] 

Claus Ibsen commented on CAMEL-12415:
-

I wonder if this is a candidate to backport to 2.21.x branch ?

> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Assignee: Alex Dettinger
>Priority: Minor
> Fix For: 2.22.0
>
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16424544#comment-16424544
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on issue #2277: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#issuecomment-378385093
 
 
   Merged into master. Thanks for contribution :+1: .


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Assignee: Alex Dettinger
>Priority: Minor
> Fix For: 2.22.0
>
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16424545#comment-16424545
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger closed pull request #2277: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
index 8283af650a4..b2ec41bd23f 100644
--- 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
+++ 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
@@ -298,8 +298,9 @@ protected void doStop() throws Exception {
 if (isPrettyPrint()) {
 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, 
Boolean.TRUE);
 }
-if (exchange != null && 
exchange.getProperty(Exchange.CHARSET_NAME, String.class) != null) {
-marshaller.setProperty(Marshaller.JAXB_ENCODING, 
exchange.getProperty(Exchange.CHARSET_NAME, String.class));
+String charset = exchange != null ? 
exchange.getProperty(Exchange.CHARSET_NAME, String.class) : null;
+if (charset != null) {
+marshaller.setProperty(Marshaller.JAXB_ENCODING, charset);
 }
 Object toMarshall = value;
 if (objectFactoryMethod != null) {
@@ -314,7 +315,7 @@ protected void doStop() throws Exception {
 }
 if (needFiltering(exchange)) {
 XMLStreamWriter writer = 
parentTypeConverter.convertTo(XMLStreamWriter.class, buffer);
-FilteringXmlStreamWriter filteringWriter = new 
FilteringXmlStreamWriter(writer);
+FilteringXmlStreamWriter filteringWriter = new 
FilteringXmlStreamWriter(writer, charset);
 marshaller.marshal(toMarshall, filteringWriter);
 } else {
 marshaller.marshal(toMarshall, buffer);
diff --git 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
index 7af3d727702..3a82b1443cd 100644
--- 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
+++ 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
@@ -36,6 +36,7 @@
 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
 
 private XMLStreamWriter writer;
+private String encoding;
 
 /**
  * @param writer
@@ -45,6 +46,18 @@ public FilteringXmlStreamWriter(XMLStreamWriter writer) {
 this.writer = writer;
 }
 
+/**
+ * @param writer
+ *target writer to wrap.
+ * @param encoding
+ *the encoding to write in the xml prolog.
+ *
+ */
+public FilteringXmlStreamWriter(XMLStreamWriter writer, String encoding) {
+this.writer = writer;
+this.encoding = encoding;
+}
+
 /**
  * This method applies filtering before delegating call to {@link #writer}.
  */
@@ -181,7 +194,11 @@ public void writeProcessingInstruction(String target) 
throws XMLStreamException
 }
 
 public void writeStartDocument() throws XMLStreamException {
-writer.writeStartDocument();
+if (encoding != null) {
+this.writeStartDocument(encoding, null);
+} else {
+writer.writeStartDocument();
+}
 }
 
 public void writeStartDocument(String encoding, String version) throws 
XMLStreamException {
@@ -189,7 +206,11 @@ public void writeStartDocument(String encoding, String 
version) throws XMLStream
 }
 
 public void writeStartDocument(String version) throws XMLStreamException {
-writer.writeStartDocument(version);
+if (encoding != null) {
+this.writeStartDocument(encoding, version);
+} else {
+writer.writeStartDocument(version);
+}
 }
 
 public void writeStartElement(String prefix, String localName, String 
namespaceURI)
diff --git 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
index ea74d37dad5..35a208aa4e2 100644
--- 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
+++ 

[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16424546#comment-16424546
 ] 

ASF GitHub Bot commented on CAMEL-12415:


Github user aldettinger closed the pull request at:

https://github.com/apache/camel/pull/2277


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Assignee: Alex Dettinger
>Priority: Minor
> Fix For: 2.22.0
>
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-03 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16423941#comment-16423941
 ] 

ASF GitHub Bot commented on CAMEL-12415:


oscerd commented on issue #2277: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#issuecomment-378232536
 
 
   @aldettinger can you review? It looks good to me.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-02 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16423061#comment-16423061
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII commented on issue #2277: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#issuecomment-378029387
 
 
   Added requested changes.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-02 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16422819#comment-16422819
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178595038
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 ##
 @@ -206,9 +206,10 @@ void doMarshal(Exchange exchange, Object graph, 
OutputStream stream, Marshaller
 // only marshal if its possible
 if (introspector.isElement(element)) {
 if (asXmlStreamWriter(exchange)) {
-XMLStreamWriter writer = 
typeConverter.convertTo(XMLStreamWriter.class, stream);
+XMLStreamWriter writer = 
typeConverter.convertTo(XMLStreamWriter.class, exchange, stream);
 if (needFiltering(exchange)) {
-writer = new FilteringXmlStreamWriter(writer);
+String charset = 
exchange.getProperty(Exchange.CHARSET_NAME, String.class);
 
 Review comment:
   Could you please change the method signature to `doMarshal(..., OutputStream 
stream, String charset, ...)` and get the charset from there ?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
>

[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-04-02 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16422818#comment-16422818
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178595397
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 ##
 @@ -226,9 +227,10 @@ void doMarshal(Exchange exchange, Object graph, 
OutputStream stream, Marshaller
 if (instance != null) {
 Object toMarshall = 
objectFactoryMethod.invoke(instance, element);
 if (asXmlStreamWriter(exchange)) {
-XMLStreamWriter writer = 
typeConverter.convertTo(XMLStreamWriter.class, stream);
+XMLStreamWriter writer = 
typeConverter.convertTo(XMLStreamWriter.class, exchange, stream);
 if (needFiltering(exchange)) {
-writer = new FilteringXmlStreamWriter(writer);
+String charset = 
exchange.getProperty(Exchange.CHARSET_NAME, String.class);
 
 Review comment:
   Same here , we could also remove this line.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> 

[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16421033#comment-16421033
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII commented on a change in pull request #2277: CAMEL-12415 - camel-jaxb, 
fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178374103
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
 ##
 @@ -36,13 +36,18 @@
 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
 
 private XMLStreamWriter writer;
+private String encoding;
 
 /**
  * @param writer
  *target writer to wrap.
+ * @param encoding
+ *the encoding to write in header
+ *
  */
-public FilteringXmlStreamWriter(XMLStreamWriter writer) {
+public FilteringXmlStreamWriter(XMLStreamWriter writer, String encoding) {
 this.writer = writer;
+this.encoding = encoding != null ? encoding.toUpperCase() : null;
 
 Review comment:
   I thought it would nicer for consumers of the produced XML. While lowercase 
is allowed by the standard and parsers should support it, there are parsers 
that break on lowercase. None I know of that break on uppercase (this could be 
because I never have used Shift_JIS, or other encodings with lowercase IANA 
names, so I can see why forcing uppercase might be a bad idea).
   
   I originally thought all IANA names were uppercase, which they are not. And 
this will take the choice out of the users hands. I'll remove it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> 

[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420921#comment-16420921
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII commented on a change in pull request #2277: CAMEL-12415 - camel-jaxb, 
fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178376173
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 ##
 @@ -258,6 +238,27 @@ void doMarshal(Exchange exchange, Object graph, 
OutputStream stream, Marshaller
 }
 }
 
+private void performWrite(Exchange exchange, OutputStream stream, 
XMLStreamWriter writer, Marshaller marshaller, Object toMarshall) throws 
JAXBException {
+if (asXmlStreamWriter(exchange)) {
+marshaller.marshal(toMarshall, writer);
+} else {
+marshaller.marshal(toMarshall, stream);
+}
+}
+
 
 Review comment:
   Thanks, missed that. I'll revert it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420916#comment-16420916
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII commented on a change in pull request #2277: CAMEL-12415 - camel-jaxb, 
fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178374103
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
 ##
 @@ -36,13 +36,18 @@
 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
 
 private XMLStreamWriter writer;
+private String encoding;
 
 /**
  * @param writer
  *target writer to wrap.
+ * @param encoding
+ *the encoding to write in header
+ *
  */
-public FilteringXmlStreamWriter(XMLStreamWriter writer) {
+public FilteringXmlStreamWriter(XMLStreamWriter writer, String encoding) {
 this.writer = writer;
+this.encoding = encoding != null ? encoding.toUpperCase() : null;
 
 Review comment:
   It is nicer for consumers of the produced XML. While lowercase is allowed by 
the standard and parsers should support it, there are parsers that break on 
lowercase. None I know of that break on uppercase.
   
   Standard also uses uppercase.
   https://www.iana.org/assignments/character-sets/character-sets.xhtml
   
   This might break the users expectation though, but in this case it might be 
nice to help the user do what will cause them the least pain. What do you think?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> 

[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420818#comment-16420818
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178341456
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 ##
 @@ -258,6 +238,27 @@ void doMarshal(Exchange exchange, Object graph, 
OutputStream stream, Marshaller
 }
 }
 
+private void performWrite(Exchange exchange, OutputStream stream, 
XMLStreamWriter writer, Marshaller marshaller, Object toMarshall) throws 
JAXBException {
+if (asXmlStreamWriter(exchange)) {
+marshaller.marshal(toMarshall, writer);
+} else {
+marshaller.marshal(toMarshall, stream);
+}
+}
+
+private XMLStreamWriter getWriter(Exchange exchange, OutputStream stream) {
+XMLStreamWriter writer = 
typeConverter.convertTo(XMLStreamWriter.class, exchange, stream);
+if (needFiltering(exchange)) {
 
 Review comment:
   Moreover, it hides the interesting changes (I mean the 2 lines above)


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420814#comment-16420814
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178341246
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 ##
 @@ -258,6 +238,27 @@ void doMarshal(Exchange exchange, Object graph, 
OutputStream stream, Marshaller
 }
 }
 
+private void performWrite(Exchange exchange, OutputStream stream, 
XMLStreamWriter writer, Marshaller marshaller, Object toMarshall) throws 
JAXBException {
+if (asXmlStreamWriter(exchange)) {
+marshaller.marshal(toMarshall, writer);
+} else {
+marshaller.marshal(toMarshall, stream);
+}
+}
+
 
 Review comment:
   With the proposed refactoring, getWriter is called at each marshall attempt 
(performance) and even when `asXmlStreamWriter(exchange)` is false (behavior 
change). I would not include this change.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420815#comment-16420815
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178340769
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
 ##
 @@ -36,13 +36,18 @@
 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
 
 private XMLStreamWriter writer;
+private String encoding;
 
 /**
  * @param writer
  *target writer to wrap.
+ * @param encoding
+ *the encoding to write in header
+ *
  */
-public FilteringXmlStreamWriter(XMLStreamWriter writer) {
+public FilteringXmlStreamWriter(XMLStreamWriter writer, String encoding) {
 this.writer = writer;
+this.encoding = encoding != null ? encoding.toUpperCase() : null;
 
 Review comment:
   Could you please explain why we would need to store it upper case please ?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420811#comment-16420811
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178342671
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
 ##
 @@ -295,11 +295,13 @@ protected void doStop() throws Exception {
 Marshaller marshaller = context.createMarshaller();
 Writer buffer = new StringWriter();
 
+
 
 Review comment:
   No big deal, but if you could avoid introducing blank line.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420813#comment-16420813
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178342501
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
 ##
 @@ -36,13 +36,18 @@
 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
 
 private XMLStreamWriter writer;
+private String encoding;
 
 /**
  * @param writer
  *target writer to wrap.
+ * @param encoding
+ *the encoding to write in header
 
 Review comment:
   At first read, I interpreted 'header' as 'camel header'. Did you mean xml 
prolog instead ?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420816#comment-16420816
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178340643
 
 

 ##
 File path: 
components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
 ##
 @@ -36,13 +36,18 @@
 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
 
 private XMLStreamWriter writer;
+private String encoding;
 
 /**
  * @param writer
  *target writer to wrap.
+ * @param encoding
+ *the encoding to write in header
+ *
  */
-public FilteringXmlStreamWriter(XMLStreamWriter writer) {
 
 Review comment:
   Keeping the old constructor along with the new one would avoid an API break. 
This way you would leverage the good implementation you have done in 
`writeStartDocument` overloads.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420812#comment-16420812
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178341639
 
 

 ##
 File path: 
components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriterTest.java
 ##
 @@ -42,7 +42,7 @@
 
 @Before
 public void setUp() {
-filteringXmlStreamWriter = new 
FilteringXmlStreamWriter(xmlStreamWriterMock);
+filteringXmlStreamWriter = new 
FilteringXmlStreamWriter(xmlStreamWriterMock, null);
 
 Review comment:
   Could be avoided by removing the API break mentioned earlier.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-30 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16420817#comment-16420817
 ] 

ASF GitHub Bot commented on CAMEL-12415:


aldettinger commented on a change in pull request #2277: CAMEL-12415 - 
camel-jaxb, fix options combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277#discussion_r178341934
 
 

 ##
 File path: 
components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitEncodingAndXMLCharFilteringTest.java
 ##
 @@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.example;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxb.JaxbDataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+
+/**
+ * @version 
+ */
+public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport {
+
+@Override
+public void setUp() throws Exception {
+deleteDirectory("target/charset");
+super.setUp();
+}
+
+@Test
+public void testIsoAndCharacterFiltering() throws Exception {
+PurchaseOrder order = new PurchaseOrder();
+//Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
spouting whale
+String name = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
+String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
//Spouting whale has become spaces
+order.setName(name);
+order.setAmount(123.45);
+order.setPrice(2.22);
+
+MockEndpoint result = getMockEndpoint("mock:file");
+result.expectedFileExists("target/charset/output.xml");
+
 
 Review comment:
   And indeed the resulting file does not contain the spouting whale anymore 
with your fix. Seems that it was UTF-8 encoded before. Good catch :+1:.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> 

[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-29 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16419588#comment-16419588
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII opened a new pull request #2277: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNon…
URL: https://github.com/apache/camel/pull/2277
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-29 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16419589#comment-16419589
 ] 

ASF GitHub Bot commented on CAMEL-12415:


GitHub user IIlllII opened a pull request:

https://github.com/apache/camel/pull/2277

CAMEL-12415 - camel-jaxb, fix options combination: encoding,filterNon…



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/IIlllII/camel CAMEL-12415-2

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/camel/pull/2277.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #2277


commit 9e1b372bc8cff1b9189bd4319ea8ea6b085a7e56
Author: Jonas Waage 
Date:   2018-03-29T16:33:44Z

CAMEL-12415 - camel-jaxb, fix options combination: 
encoding,filterNonXmlChars




> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-29 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16419399#comment-16419399
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII closed pull request #2276: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNonXmlChars
URL: https://github.com/apache/camel/pull/2276
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
index 8283af650a4..24e51ed537f 100644
--- 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
+++ 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
@@ -295,11 +295,13 @@ protected void doStop() throws Exception {
 Marshaller marshaller = context.createMarshaller();
 Writer buffer = new StringWriter();
 
+
 if (isPrettyPrint()) {
 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, 
Boolean.TRUE);
 }
-if (exchange != null && 
exchange.getProperty(Exchange.CHARSET_NAME, String.class) != null) {
-marshaller.setProperty(Marshaller.JAXB_ENCODING, 
exchange.getProperty(Exchange.CHARSET_NAME, String.class));
+String charset = exchange != null ? 
exchange.getProperty(Exchange.CHARSET_NAME, String.class) : null;
+if (charset != null) {
+marshaller.setProperty(Marshaller.JAXB_ENCODING, charset);
 }
 Object toMarshall = value;
 if (objectFactoryMethod != null) {
@@ -314,7 +316,7 @@ protected void doStop() throws Exception {
 }
 if (needFiltering(exchange)) {
 XMLStreamWriter writer = 
parentTypeConverter.convertTo(XMLStreamWriter.class, buffer);
-FilteringXmlStreamWriter filteringWriter = new 
FilteringXmlStreamWriter(writer);
+FilteringXmlStreamWriter filteringWriter = new 
FilteringXmlStreamWriter(writer, charset);
 marshaller.marshal(toMarshall, filteringWriter);
 } else {
 marshaller.marshal(toMarshall, buffer);
diff --git 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
index 7af3d727702..49e0df3c2cc 100644
--- 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
+++ 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FilteringXmlStreamWriter.java
@@ -36,13 +36,18 @@
 NonXmlCharFilterer nonXmlCharFilterer = new NonXmlCharFilterer();
 
 private XMLStreamWriter writer;
+private String encoding;
 
 /**
  * @param writer
  *target writer to wrap.
+ * @param encoding
+ *the encoding to write in header
+ *
  */
-public FilteringXmlStreamWriter(XMLStreamWriter writer) {
+public FilteringXmlStreamWriter(XMLStreamWriter writer, String encoding) {
 this.writer = writer;
+this.encoding = encoding != null ? encoding.toUpperCase() : null;
 }
 
 /**
@@ -181,7 +186,11 @@ public void writeProcessingInstruction(String target) 
throws XMLStreamException
 }
 
 public void writeStartDocument() throws XMLStreamException {
-writer.writeStartDocument();
+if (encoding != null) {
+this.writeStartDocument(encoding, null);
+} else {
+writer.writeStartDocument();
+}
 }
 
 public void writeStartDocument(String encoding, String version) throws 
XMLStreamException {
@@ -189,7 +198,11 @@ public void writeStartDocument(String encoding, String 
version) throws XMLStream
 }
 
 public void writeStartDocument(String version) throws XMLStreamException {
-writer.writeStartDocument(version);
+if (encoding != null) {
+this.writeStartDocument(encoding, version);
+} else {
+writer.writeStartDocument(version);
+}
 }
 
 public void writeStartElement(String prefix, String localName, String 
namespaceURI)
diff --git 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
 
b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
index ea74d37dad5..0500210261c 100644
--- 
a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
+++ 

[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-29 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16419398#comment-16419398
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII commented on issue #2276: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNonXmlChars
URL: https://github.com/apache/camel/pull/2276#issuecomment-377304454
 
 
   Got some other commits in here, sorry I'll make a new one


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-29 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16419400#comment-16419400
 ] 

ASF GitHub Bot commented on CAMEL-12415:


Github user IIlllII closed the pull request at:

https://github.com/apache/camel/pull/2276


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-29 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16419361#comment-16419361
 ] 

ASF GitHub Bot commented on CAMEL-12415:


IIlllII opened a new pull request #2276: CAMEL-12415 - camel-jaxb, fix options 
combination: encoding,filterNonXmlChars
URL: https://github.com/apache/camel/pull/2276
 
 
   Please tell me if anything needs to be changed.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CAMEL-12415) Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong data

2018-03-29 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/CAMEL-12415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16419362#comment-16419362
 ] 

ASF GitHub Bot commented on CAMEL-12415:


GitHub user IIlllII opened a pull request:

https://github.com/apache/camel/pull/2276

CAMEL-12415 - camel-jaxb, fix options combination: 
encoding,filterNonXmlChars

Please tell me if anything needs to be changed.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/IIlllII/camel master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/camel/pull/2276.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #2276


commit 64169aed7e0c8f07853565fac4e9822f26c83647
Author: Jonas Waage 
Date:   2017-12-04T23:34:55Z

CAMEL-12062 Propagate encoding in property

commit 8c387e4f40ea13f61fe7cb6c87ea3d6f4f91f4b1
Author: Jonas Waage 
Date:   2018-03-20T19:13:40Z

Merge remote-tracking branch 'upstream/master'

commit ae41f78bb38f3402fbbf386057f14bd4187cf768
Author: Jonas Waage 
Date:   2018-03-29T16:33:44Z

CAMEL-12415 - camel-jaxb, fix options combination: 
encoding,filterNonXmlChars




> Camel-jaxb option "encoding" with option "filterNonXmlChars" generate wrong 
> data
> 
>
> Key: CAMEL-12415
> URL: https://issues.apache.org/jira/browse/CAMEL-12415
> Project: Camel
>  Issue Type: Bug
>  Components: camel-jaxb
>Affects Versions: 2.21.0
> Environment: OS X 13.3, Java 8
>Reporter: Jonas Waage
>Priority: Minor
>
> When using the jaxb-component to marshal.
> The properties:
>  * Encoding
>  * FilterNonXmlChars
> do not work together correctly.
> FilterNonXmlChars will ignore the set encoding, and make the output bytes 
> UTF-8 encoded.
>  I would either expect this to just work, and by that I mean bytes should be 
> encoded as the set encoding, or minimally fail during startup of the route 
> with an exception explaining that these properties does not work together. 
> I'd really prefer the first, since I want to use the functionality of both.
> I have provided a patch which makes this work.I have done a small refactoring 
> to not have to duplicate more code. I can rewrite this if it is a problem.
> Below is a test which will reproduce the problem.
> {code:java}
> public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport 
> {
> @Override
> public void setUp() throws Exception {
> deleteDirectory("target/charset");
> super.setUp();
> }
> @Test
> public void testIsoAndCharacterFiltering() throws Exception {
> PurchaseOrder order = new PurchaseOrder();
> //Data containing characters ÆØÅæøå that differ in utf-8 and iso + a 
> spouting whale
> String name = 
> "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5\uD83D\uDC33\uFFFD";
> String expected = "\u00c6\u00d8\u00C5\u00e6\u00f8\u00e5  \uFFFD"; 
> //Spouting whale has become spaces
> order.setName(name);
> order.setAmount(123.45);
> order.setPrice(2.22);
> MockEndpoint result = getMockEndpoint("mock:file");
> result.expectedFileExists("target/charset/output.xml");
> template.sendBody("direct:start", order);
> assertMockEndpointsSatisfied();
> JAXBContext jaxbContext = 
> JAXBContext.newInstance("org.apache.camel.example");
> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
> InputStream inputStream = new 
> FileInputStream("target/charset/output.xml");
> Reader reader = new InputStreamReader(inputStream, "ISO-8859-1");
> PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
> assertEquals(expected, obj.getName());
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> JaxbDataFormat jaxb = new 
> JaxbDataFormat("org.apache.camel.example");
> jaxb.setFilterNonXmlChars(true);
> jaxb.setEncoding("iso-8859-1");
> from("direct:start")
> .marshal(jaxb)
> 
> .to("file:target/charset/?fileName=output.xml=iso-8859-1");
> }
> };
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)