You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/03/07 15:28:29 UTC
[3/3] camel git commit: noNamespaceSchemaLocation and unit test
noNamespaceSchemaLocation and unit test
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f34dd1c7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f34dd1c7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f34dd1c7
Branch: refs/heads/master
Commit: f34dd1c757a4413b3fd43b5f2516cfc1c20a5a22
Parents: 2e9163f
Author: jonmcewen <jo...@hotmail.com>
Authored: Fri Mar 4 11:24:03 2016 +0000
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Mar 7 15:25:00 2016 +0100
----------------------------------------------------------------------
.../camel/converter/jaxb/JaxbDataFormat.java | 12 ++++
.../jaxb/CamelJaxbNoNamespaceSchemaTest.java | 63 ++++++++++++++++++++
2 files changed, 75 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f34dd1c7/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 7a205fe..3436561 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
@@ -82,6 +82,7 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, DataFo
private String contextPath;
private String schema;
private String schemaLocation;
+ private String noNamespaceSchemaLocation;
private boolean prettyPrint = true;
private boolean ignoreJAXBElement = true;
@@ -138,6 +139,9 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, DataFo
if (ObjectHelper.isNotEmpty(schemaLocation)) {
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation);
}
+ if (ObjectHelper.isNotEmpty(noNamespaceSchemaLocation)) {
+ marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, noNamespaceSchemaLocation);
+ }
if (namespacePrefixMapper != null) {
marshaller.setProperty(namespacePrefixMapper.getRegistrationKey(), namespacePrefixMapper);
}
@@ -363,6 +367,14 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, DataFo
this.schemaLocation = schemaLocation;
}
+ public String getNoNamespaceSchemaLocation() {
+ return schemaLocation;
+ }
+
+ public void setNoNamespaceSchemaLocation(String schemaLocation) {
+ this.noNamespaceSchemaLocation = schemaLocation;
+ }
+
@Override
@SuppressWarnings("unchecked")
protected void doStart() throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/f34dd1c7/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbNoNamespaceSchemaTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbNoNamespaceSchemaTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbNoNamespaceSchemaTest.java
new file mode 100644
index 0000000..efe60f7
--- /dev/null
+++ b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbNoNamespaceSchemaTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.jaxb;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxb.JaxbDataFormat;
+import org.apache.camel.foo.bar.PersonType;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+
+public class CamelJaxbNoNamespaceSchemaTest extends CamelTestSupport {
+
+ @Test
+ public void testMarshalWithNoNamespaceSchemaLocation() 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("noNamespaceSchemaLocation=\"person-no-namespace.xsd\""));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ JaxbDataFormat dataFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
+ dataFormat.setNoNamespaceSchemaLocation("person-no-namespace.xsd");
+ dataFormat.setIgnoreJAXBElement(false);
+
+
+ from("direct:marshal")
+ .marshal(dataFormat)
+ .to("mock:result");
+
+ }
+ };
+ }
+
+}