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 2014/12/10 08:12:30 UTC
[3/3] camel git commit: CAMEL-8139: rest-dsl Allow to configure data
format properties for IN vs OUT
CAMEL-8139: rest-dsl Allow to configure data format properties for IN vs OUT
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4feec4fb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4feec4fb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4feec4fb
Branch: refs/heads/camel-2.14.x
Commit: 4feec4fb59f15358cc03470024be8e22236b711f
Parents: f0bfd0e
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 10 08:11:37 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 10 08:11:58 2014 +0100
----------------------------------------------------------------------
.../camel/model/rest/RestBindingDefinition.java | 34 ++++++++++++++++----
...estletBindingInJaxbOutStringWithXmlTest.java | 2 +-
2 files changed, 29 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4feec4fb/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
index eac4829..1691ee8 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestBindingDefinition.java
@@ -124,7 +124,7 @@ public class RestBindingDefinition extends NoOutputDefinition<RestBindingDefinit
IntrospectionSupport.setProperty(context.getTypeConverter(), json, "unmarshalType", clazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), json, "useList", type.endsWith("[]"));
}
- setAdditionalConfiguration(context, json);
+ setAdditionalConfiguration(context, json, "json.in.");
context.addService(json);
Class<?> outClazz = null;
@@ -136,7 +136,7 @@ public class RestBindingDefinition extends NoOutputDefinition<RestBindingDefinit
IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "unmarshalType", outClazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), outJson, "useList", outType.endsWith("[]"));
}
- setAdditionalConfiguration(context, outJson);
+ setAdditionalConfiguration(context, outJson, "json.out.");
context.addService(outJson);
}
@@ -170,7 +170,7 @@ public class RestBindingDefinition extends NoOutputDefinition<RestBindingDefinit
JAXBContext jc = JAXBContext.newInstance(clazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), jaxb, "context", jc);
}
- setAdditionalConfiguration(context, jaxb);
+ setAdditionalConfiguration(context, jaxb, "xml.in.");
context.addService(jaxb);
Class<?> outClazz = null;
@@ -186,23 +186,45 @@ public class RestBindingDefinition extends NoOutputDefinition<RestBindingDefinit
JAXBContext jc = JAXBContext.newInstance(clazz);
IntrospectionSupport.setProperty(context.getTypeConverter(), outJaxb, "context", jc);
}
- setAdditionalConfiguration(context, outJaxb);
+ setAdditionalConfiguration(context, outJaxb, "xml.out.");
context.addService(outJaxb);
}
return new RestBindingProcessor(json, jaxb, outJson, outJaxb, consumes, produces, mode, skip, cors, corsHeaders);
}
- private void setAdditionalConfiguration(CamelContext context, DataFormat dataFormat) throws Exception {
+ private void setAdditionalConfiguration(CamelContext context, DataFormat dataFormat, String prefix) throws Exception {
if (context.getRestConfiguration().getDataFormatProperties() != null && !context.getRestConfiguration().getDataFormatProperties().isEmpty()) {
// must use a copy as otherwise the options gets removed during introspection setProperties
Map<String, Object> copy = new HashMap<String, Object>();
- copy.putAll(context.getRestConfiguration().getDataFormatProperties());
+
+ // filter keys on prefix
+ // - either its a known prefix and must match the prefix parameter
+ // - or its a common configuration that we should always use
+ for (Map.Entry<String, Object> entry : context.getRestConfiguration().getDataFormatProperties().entrySet()) {
+ String key = entry.getKey();
+ String copyKey;
+ boolean known = isKeyKnownPrefix(key);
+ if (known) {
+ // remove the prefix from the key to use
+ copyKey = key.substring(prefix.length());
+ } else {
+ // use the key as is
+ copyKey = key;
+ }
+ if (!known || key.startsWith(prefix)) {
+ copy.put(copyKey, entry.getValue());
+ }
+ }
IntrospectionSupport.setProperties(context.getTypeConverter(), dataFormat, copy);
}
}
+ private boolean isKeyKnownPrefix(String key) {
+ return key.startsWith("json.in.") || key.startsWith("json.out.") || key.startsWith("xml.in.") || key.startsWith("xml.out.");
+ }
+
public String getConsumes() {
return consumes;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4feec4fb/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletBindingInJaxbOutStringWithXmlTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletBindingInJaxbOutStringWithXmlTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletBindingInJaxbOutStringWithXmlTest.java
index 10f1c7f..415e01c 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletBindingInJaxbOutStringWithXmlTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletBindingInJaxbOutStringWithXmlTest.java
@@ -52,7 +52,7 @@ public class RestRestletBindingInJaxbOutStringWithXmlTest extends RestletTestSup
public void configure() throws Exception {
restConfiguration().component("restlet").host("localhost").port(portNum).bindingMode(RestBindingMode.auto)
// turn off must be JAXB as we create the output type ourselves as xml in a String type
- .dataFormatProperty("mustBeJAXBElement", "false");
+ .dataFormatProperty("xml.out.mustBeJAXBElement", "false");
// use the rest DSL to define the rest services
rest("/users/")