camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7484 Added an option to JaxbDataFormat to include schema location
Date Fri, 06 Jun 2014 11:31:21 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5ebf252c2 -> ff3ecc603


CAMEL-7484 Added an option to JaxbDataFormat to include schema location


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ff3ecc60
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ff3ecc60
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ff3ecc60

Branch: refs/heads/master
Commit: ff3ecc60331d6f0656d61805bca00da6042f06a7
Parents: 5ebf252
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Jun 6 19:29:20 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Jun 6 19:29:20 2014 +0800

----------------------------------------------------------------------
 .../camel/model/dataformat/JaxbDataFormat.java     | 13 +++++++++++++
 .../camel/converter/jaxb/JaxbDataFormat.java       | 13 +++++++++++++
 .../java/org/apache/camel/jaxb/CamelJaxbTest.java  | 17 +++++++++++++++++
 .../org/apache/camel/jaxb/CamelJaxbTest.xml        |  2 +-
 4 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ff3ecc60/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
b/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
index a0bc6f2..716f9c6 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
@@ -58,6 +58,8 @@ public class JaxbDataFormat extends DataFormatDefinition {
     private String namespacePrefixRef;
     @XmlAttribute
     private String xmlStreamWriterWrapper;
+    @XmlAttribute
+    private String schemaLocation;
 
     public JaxbDataFormat() {
         super("jaxb");
@@ -156,6 +158,14 @@ public class JaxbDataFormat extends DataFormatDefinition {
         this.xmlStreamWriterWrapper = xmlStreamWriterWrapperRef;
     }
 
+    public String getSchemaLocation() {
+        return schemaLocation;
+    }
+
+    public void setSchemaLocation(String schemaLocation) {
+        this.schemaLocation = schemaLocation;
+    }
+
     @Override
     protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext)
{
         Boolean answer = ObjectHelper.toBoolean(getPrettyPrint());
@@ -201,5 +211,8 @@ public class JaxbDataFormat extends DataFormatDefinition {
         if (xmlStreamWriterWrapper != null) {
             setProperty(camelContext, dataFormat, "xmlStreamWriterWrapper", xmlStreamWriterWrapper);
         }
+        if (schemaLocation != null) {
+            setProperty(camelContext, dataFormat, "schemaLocation", schemaLocation);
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ff3ecc60/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
----------------------------------------------------------------------
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 f63d91d..ae33062 100644
--- 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
@@ -77,6 +77,8 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat,
CamelC
     private JAXBContext context;
     private String contextPath;
     private String schema;
+    private String schemaLocation;
+   
     private boolean prettyPrint = true;
     private boolean ignoreJAXBElement = true;
     private boolean filterNonXmlChars;
@@ -123,6 +125,9 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat,
CamelC
             if (isFragment()) {
                 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
             }
+            if (ObjectHelper.isNotEmpty(schemaLocation)) {
+                marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation);
+            }
             if (namespacePrefixMapper != null) {
                 marshaller.setProperty(namespacePrefixMapper.getRegistrationKey(), namespacePrefixMapper);
             }
@@ -321,6 +326,14 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat,
CamelC
     public void setXmlStreamWriterWrapper(JaxbXmlStreamWriterWrapper xmlStreamWriterWrapper)
{
         this.xmlStreamWriterWrapper = xmlStreamWriterWrapper;
     }
+    
+    public String getSchemaLocation() {
+        return schemaLocation;
+    }
+
+    public void setSchemaLocation(String schemaLocation) {
+        this.schemaLocation = schemaLocation;
+    }
 
     @Override
     @SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/camel/blob/ff3ecc60/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
index ab1daf5..a57e389 100644
--- a/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
+++ b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
@@ -79,6 +79,22 @@ public class CamelJaxbTest extends CamelTestSupport {
         assertTrue("Non-xml character unexpectedly did not get into marshalled contents",
body
                 .contains("\u0004"));
     }
+    
+    @Test
+    public void testMarshalWithSchemaLocation() throws Exception {
+        PersonType person = new PersonType();
+        person.setFirstName("foo");
+        person.setLastName("bar");
+
+        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+        resultEndpoint.expectedMessageCount(1);
+        template.sendBody("direct:marshal", person);
+        resultEndpoint.assertIsSatisfied();
+
+        String body = resultEndpoint.getReceivedExchanges().get(0).getIn().getBody(String.class);
+        assertTrue("We should get the schemaLocation here", body
+                .contains("schemaLocation=\"person.xsd\""));
+    }
 
     @Test
     public void testCustomXmlStreamWriter() throws InterruptedException {
@@ -143,6 +159,7 @@ public class CamelJaxbTest extends CamelTestSupport {
 
             public void configure() throws Exception {
                 JaxbDataFormat dataFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
+                dataFormat.setSchemaLocation("person.xsd");
                 dataFormat.setIgnoreJAXBElement(false);
 
                 JaxbDataFormat filterEnabledFormat = new JaxbDataFormat("org.apache.camel.foo.bar");

http://git-wip-us.apache.org/repos/asf/camel/blob/ff3ecc60/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
b/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
index 1742ec8..b57b473 100644
--- a/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
+++ b/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
@@ -43,7 +43,7 @@
     <route>
       <from uri="direct:marshal"/>
       <marshal>
-        <jaxb contextPath="org.apache.camel.foo.bar"/>
+        <jaxb contextPath="org.apache.camel.foo.bar" schemaLocation="person.xsd"/>
       </marshal>          
       <to uri="mock:result"/>
     </route>


Mime
View raw message