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/01/30 08:50:05 UTC
[1/3] camel git commit: XML JSON Data Format Asciidoc documentation
Repository: camel
Updated Branches:
refs/heads/master 2210dd5ce -> 83151a1f2
XML JSON Data Format Asciidoc documentation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/83151a1f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/83151a1f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/83151a1f
Branch: refs/heads/master
Commit: 83151a1f236d89e3dfef0dc46b18855035e91ef9
Parents: 674b8cd
Author: Antonin Stefanutti <an...@stefanutti.fr>
Authored: Fri Jan 29 20:02:47 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jan 30 08:10:47 2016 +0100
----------------------------------------------------------------------
.../camel-xmljson/src/main/docs/xmljson.adoc | 378 +++++++++++++++++++
docs/user-manual/en/SUMMARY.md | 6 +-
2 files changed, 381 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/83151a1f/components/camel-xmljson/src/main/docs/xmljson.adoc
----------------------------------------------------------------------
diff --git a/components/camel-xmljson/src/main/docs/xmljson.adoc b/components/camel-xmljson/src/main/docs/xmljson.adoc
new file mode 100644
index 0000000..c5fc195
--- /dev/null
+++ b/components/camel-xmljson/src/main/docs/xmljson.adoc
@@ -0,0 +1,378 @@
+[[XmlJson-XMLJSONDataFormat]]
+XML JSON Data Format (`camel-xmljson`)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+*Available as of Camel 2.10*
+
+Camel already supports a number of data formats to perform XML and
+JSON-related conversions, but all of them require a POJO either as an
+input (for marshalling) or produce a POJO as output (for unmarshalling).
+This data format provides the capability to convert from XML to JSON and
+vice-versa directly, without stepping through intermediate POJOs.
+
+This data format leverages the
+http://json-lib.sourceforge.net/[Json-lib] library to achieve direct
+conversion. In this context, XML is considered the high-level format,
+while JSON is the low-level format. Hence, the marshal/unmarshal
+semantics are assigned as follows:
+
+* marshalling => converting from XML to JSON
+* unmarshalling => converting from JSON to XML.
+
+[[XmlJson-Options]]
+Options
+^^^^^^^
+
+This data format supports the following options. You can set them via
+all DSLs. The defaults marked with (*) are determined by json-lib,
+rather than the code of the data format itself. They are reflected here
+for convenience so that you don't have to dot back and forth with the
+json-lib docs.
+
+[width="100%",cols="1s,1m,1m,4",options="header",]
+|=======================================================================
+|Name |Type |Default |Description
+|`encoding` |`String` |UTF-8 (*) |*Used when* *unmarshalling* *(JSON to
+XML conversion).* Sets the encoding for the call to
+http://json-lib.sourceforge.net/apidocs/net/sf/json/xml/XMLSerializer.html#write(net.sf.json.JSON,%20java.lang.String)[`XMLSerializer.write()`]
+method, hence it is only used when producing XML. +
+When producing JSON, the encoding is determined by the input String
+being processed. If the conversion is performed on an InputStream,
+json-lib uses the platform's default encoding (e.g. determined by the
+`file.encoding` system property).
+
+|`elementName` |`String` |'e' (*) |*Used when* *unmarshalling*** (JSON
+to XML conversion).** Specifies the name of the XML elements
+representing each array element. See
+http://json-lib.sourceforge.net/snippets.html#JSONObject_to_XML_change_node_names[json-lib
+doc].
+
+|`arrayName` |`String` |'a' (*) |*Used when* *unmarshalling*** (JSON to
+XML conversion).** Specifies the name of the top-level XML element. +
+For example, when converting `[1, 2, 3]`, it will be output by default
+as `<a><e>1</e><e>2</e><e>3</e></a>`. By setting this option or
+rootName, you can alter the name of element 'a'.
+
+|`rootName` |`String` |none (*) |*Used when* *unmarshalling*** (JSON to
+XML conversion).** When converting any JSON construct (object, array,
+null) to XML (unmarshalling), it specifies the name of the top-level
+element. +
+If not set, json-lib will use `arrayName` or `objectName` (default
+value: 'o', at the current time it is not configurable in this data
+format). If set to 'root', the JSON string `{ 'x': 'value1', 'y' :
+'value2' }` would turn into `<root><x>value1</x><y>value2</y></root>`,
+otherwise the 'root' element would be named 'o'.
+
+|`namespaceLenient` |`Boolean` |false (*) |*Used when*
+*unmarshalling*** (JSON to XML conversion).** According to the json-lib
+docs: "Flag to be tolerant to incomplete namespace prefixes." In most
+cases, json-lib automatically changes this flag at runtime to match the
+processing.
+
+|`namespaceMappings` |`List<NamespacesPerElementMapping>` |none |*Used
+when* *unmarshalling*** (JSON to XML conversion).** Binds namespace
+prefixes and URIs to specific JSON
+elements. `NamespacesPerElementMapping` is a wrapper around an element
+name + a Map of prefixes against URIs.
+
+|`expandableProperties` |`List<String>` |none |*Used when*
+*unmarshalling*** (JSON to XML conversion).** With expandable
+properties, JSON array elements are converted to XML as a sequence of
+repetitive XML elements with the local name equal to the JSON key, for
+example: `{ number: 1,2,3 }`, normally converted to:
+`<number><e>1</e><e>2</e><e>3</e></number>` (where e can be modified by
+setting `elementName`), would instead translate to
+`<number>1</number><number>2</number><number>3</number>`, if `number` is
+set as an expandable property
+
+|`typeHints` |`TypeHintsEnum` |YES a|
+*Used when* *unmarshalling*** (JSON to XML conversion).** Adds type
+hints to the resulting XML to aid conversion back to JSON. See
+documentation
+http://json-lib.sourceforge.net/apidocs/net/sf/json/xml/XMLSerializer.html[here]
+for an explanation. `TypeHintsEnum` comprises the following values,
+which lead to different combinations of the underlying XMLSerializer's
+`typeHintsEnabled` and `typeHintsCompatibility` flags:
+
+* `TypeHintsEnum.NO` => `typeHintsEnabled` = `false`
+* `TypeHintsEnum.YES` => `typeHintsEnabled` =
+true, `typeHintsCompatibility` = `true`
+* `TypeHintsEnum.WITH_PREFIX` => `typeHintsEnabled` =
+true, `typeHintsCompatibility` = `false`
+
+|`forceTopLevelObject` |`Boolean` |false (*) |*Used when* *marshalling*
+*(XML to JSON conversion).* Determines whether the resulting JSON will
+start off with a top-most element whose name matches the XML root
+element. If disabled, XML string `<a><x>1</x><y>2</y></a>` turns into `{
+'x: '1', 'y': '2' }`. Otherwise, it turns into `{ 'a': { 'x: '1', 'y':
+'2' }}`.
+
+|`skipWhitespace` |`Boolean` |false (*) |*Used when*
+*marshalling*** (XML to JSON conversion).** Determines whether white
+spaces between XML elements will be regarded as text values or
+disregarded.
+
+|`trimSpaces` |`Boolean` |false (*) |*Used when* *marshalling*** (XML to
+JSON conversion).** Determines whether leading and trailing white spaces
+will be omitted from String values.
+
+|`skipNamespaces` |`Boolean` |false (*) |*Used when*
+*marshalling*** (XML to JSON conversion).** Signals whether namespaces
+should be ignored. By default they will be added to the JSON output
+using `@xmlns` elements.
+
+|`removeNamespacePrefixes` |`Boolean` |false (*) |*Used when*
+*marshalling*** (XML to JSON conversion).** Removes the namespace
+prefixes from XML qualified elements, so that the resulting JSON string
+does not contain them.
+|=======================================================================
+
+[[XmlJson-BasicUsagewithJavaDSL]]
+Basic Usage with Java DSL
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+[[XmlJson-Explicitlyinstantiatingthedataformat]]
+Explicitly instantiating the data format
+++++++++++++++++++++++++++++++++++++++++
+
+Just instantiate the `XmlJsonDataFormat` from package
+`org.apache.camel.dataformat.xmljson`. Make sure you have installed the
+`camel-xmljson` feature (if running on OSGi) or that you've included
+`camel-xmljson-{version}.jar` and its transitive dependencies in your
+classpath. Example initialization with a default configuration:
+
+[source,java]
+----
+XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
+----
+
+To tune the behaviour of the data format as per the options above, use
+the appropriate setters:
+
+[source,java]
+----
+XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
+xmlJsonFormat.setEncoding("UTF-8");
+xmlJsonFormat.setForceTopLevelObject(true);
+xmlJsonFormat.setTrimSpaces(true);
+xmlJsonFormat.setRootName("newRoot");
+xmlJsonFormat.setSkipNamespaces(true);
+xmlJsonFormat.setRemoveNamespacePrefixes(true);
+xmlJsonFormat.setExpandableProperties(Arrays.asList("d", "e"));
+----
+
+Once you've instantiated the data format, the next step is to actually
+use the it from within the `marshal()` and `unmarshal()` DSL elements:
+
+[source,java]
+----
+// from XML to JSON
+from("direct:marshal").marshal(xmlJsonFormat).to("mock:json");
+// from JSON to XML
+from("direct:unmarshal").unmarshal(xmlJsonFormat).to("mock:xml");
+----
+
+[[XmlJson-Definingthedataformatin-line]]
+Defining the data format in-line
+++++++++++++++++++++++++++++++++
+
+Alternatively, you can define the data format inline by using the
+`xmljson()` DSL element:
+
+[source,java]
+----
+// from XML to JSON - inline dataformat
+from("direct:marshalInline").marshal().xmljson().to("mock:jsonInline");
+// from JSON to XML - inline dataformat
+from("direct:unmarshalInline").unmarshal().xmljson().to("mock:xmlInline");
+----
+
+If you wish, you can even pass in a `Map<String, String>` to the inline
+methods to provide custom options:
+
+[source,java]
+----
+Map<String, String> xmlJsonOptions = new HashMap<String, String>();
+xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ENCODING, "UTF-8");
+xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ROOT_NAME, "newRoot");
+xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.SKIP_NAMESPACES, "true");
+xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.REMOVE_NAMESPACE_PREFIXES, "true");
+xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.EXPANDABLE_PROPERTIES, "d e");
+
+// from XML to JSON - inline dataformat w/ options
+from("direct:marshalInlineOptions").marshal().xmljson(xmlJsonOptions).to("mock:jsonInlineOptions");
+// form JSON to XML - inline dataformat w/ options
+from("direct:unmarshalInlineOptions").unmarshal().xmljson(xmlJsonOptions).to("mock:xmlInlineOptions");
+----
+
+[[XmlJson-BasicusagewithSpringorBlueprintDSL]]
+Basic usage with Spring or Blueprint DSL
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Within the `<dataFormats>` block, simply configure an `xmljson` element
+with unique IDs:
+
+[source,xml]
+----
+<dataFormats>
+ <xmljson id="xmljson"/>
+ <xmljson id="xmljsonWithOptions" forceTopLevelObject="true" trimSpaces="true" rootName="newRoot" skipNamespaces="true"
+ removeNamespacePrefixes="true" expandableProperties="d e"/>
+</dataFormats>
+----
+
+Then you simply refer to the data format object within your
+`<marshal />` and `<unmarshal />` DSLs:
+
+[source,xml]
+----
+<route>
+ <from uri="direct:marshal"/>
+ <marshal ref="xmljson"/>
+ <to uri="mock:json" />
+</route>
+
+<route>
+ <from uri="direct:unmarshalWithOptions"/>
+ <unmarshal ref="xmljsonWithOptions"/>
+ <to uri="mock:xmlWithOptions"/>
+</route>
+----
+
+Enabling XML DSL autocompletion for this component is easy: just refer
+to the appropriate http://camel.apache.org/xml-reference.html[Schema
+locations], depending on whether you're using
+http://camel.apache.org/schema/spring/[Spring] or
+http://camel.apache.org/schema/blueprint/[Blueprint] DSL. Remember that
+this data format is available from Camel 2.10 onwards, so only schemas
+from that version onwards will include these new XML elements and
+attributes.
+
+The syntax with link:using-osgi-blueprint-with-camel.html[Blueprint] is
+identical to that of the Spring DSL. Just ensure the correct namespaces
+and schemaLocations are in use.
+
+[[XmlJson-Namespacemappings]]
+Namespace mappings
+^^^^^^^^^^^^^^^^^^
+
+XML has namespaces to fully qualify elements and attributes; JSON
+doesn't. You need to take this into account when performing XML-JSON
+conversions.
+
+To bridge the gap, http://json-lib.sourceforge.net/[Json-lib] has an
+option to bind namespace declarations in the form of prefixes and
+namespace URIs to XML output elements while unmarshalling (i.e.
+converting from JSON to XML). For example, provided the following JSON
+string:
+
+[source,json]
+----
+{ "pref1:a": "value1", "pref2:b": "value2" }
+----
+
+you can ask Json-lib to output namespace declarations on elements
+`pref1:a` and `pref2:b` to bind the prefixes `pref1` and `pref2` to
+specific namespace URIs.
+
+To use this feature, simply create
+`XmlJsonDataFormat.NamespacesPerElementMapping` objects and add them to
+the `namespaceMappings` option (which is a `List`).
+
+The `XmlJsonDataFormat.NamespacesPerElementMapping` holds an element
+name and a Map of [prefix => namespace URI]. To facilitate mapping
+multiple prefixes and namespace URIs, the
+`NamespacesPerElementMapping(String element, String pipeSeparatedMappings)`
+constructor takes a String-based pipe-separated sequence of [prefix,
+namespaceURI] pairs in the following way:
+`|ns2|http://camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|`.
+
+In order to define a default namespace, just leave the corresponding key
+field empty:
+`|ns1|http://camel.apache.org/test1||http://camel.apache.org/default|`.
+
+Binding namespace declarations to an element name = empty string will
+attach those namespaces to the root element.
+
+The full code would look like that:
+
+[source,java]
+----
+XmlJsonDataFormat namespacesFormat = new XmlJsonDataFormat();
+List<XmlJsonDataFormat.NamespacesPerElementMapping> namespaces = new ArrayList<XmlJsonDataFormat.NamespacesPerElementMapping>();
+namespaces.add(new XmlJsonDataFormat.
+ NamespacesPerElementMapping("", "|ns1|http://camel.apache.org/test1||http://camel.apache.org/default|"));
+namespaces.add(new XmlJsonDataFormat.
+ NamespacesPerElementMapping("surname", "|ns2|http://camel.apache.org/personalData|" +
+ "ns3|http://camel.apache.org/personalData2|"));
+namespacesFormat.setNamespaceMappings(namespaces);
+namespacesFormat.setRootElement("person");
+----
+
+And you can achieve the same in Spring DSL.
+
+[[XmlJson-Example]]
+Example
++++++++
+
+Using the namespace bindings in the Java snippet above on the following
+JSON string:
+
+[source,json]
+----
+{ "name": "Raul", "surname": "Kripalani", "f": true, "g": null}
+----
+
+
+
+Would yield the following XML:
+
+[source,xml]
+----
+<person xmlns="http://camel.apache.org/default" xmlns:ns1="http://camel.apache.org/test1">
+ <f>true</f>
+ <g null="true"/>
+ <name>Raul</name>
+ <surname xmlns:ns2="http://camel.apache.org/personalData" xmlns:ns3="http://camel.apache.org/personalData2">Kripalani</surname>
+</person>
+----
+
+Remember that the JSON spec defines a JSON object as follows:
+
+_________________________________________________________
+An object is an unordered set of name/value pairs. [...].
+_________________________________________________________
+
+That's why the elements are in a different order in the output XML.
+
+[[XmlJson-Dependencies]]
+Dependencies
+^^^^^^^^^^^^
+
+To use the link:xmljson.html[XmlJson] dataformat in your camel routes
+you need to add the following dependency to your pom:
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-xmljson</artifactId>
+ <version>x.x.x</version>
+ <!-- Use the same version as camel-core, but remember that this component is only available from 2.10 onwards -->
+</dependency>
+
+<!-- And also XOM must be included. XOM cannot be included by default due to an incompatible
+license with ASF; so add this manually -->
+<dependency>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ <version>1.2.5</version>
+</dependency>
+----
+
+[[XmlJson-SeeAlso]]
+See Also
+^^^^^^^^
+
+* link:data-format.html[Data Format]
+* http://json-lib.sourceforge.net/[json-lib]
http://git-wip-us.apache.org/repos/asf/camel/blob/83151a1f/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 0d5f21a..18f8465 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -113,7 +113,7 @@
* [Expession Languages](languages.adoc)
* [Bean Language](bean-language.adoc)
* [Constant](constant.adoc)
-
-* [Data Formats](data-format.adoc)
-->
-
+
+* Data Formats
+ * [XML JSON](xmljson.adoc)
[2/3] camel git commit: REST DSL with CDI example
Posted by da...@apache.org.
REST DSL with CDI example
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/674b8cd2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/674b8cd2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/674b8cd2
Branch: refs/heads/master
Commit: 674b8cd2eb1f2c937121a62fc0ce8cb0df9a4c9f
Parents: c6859dd
Author: Antonin Stefanutti <an...@stefanutti.fr>
Authored: Fri Jan 29 19:13:09 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jan 30 08:10:47 2016 +0100
----------------------------------------------------------------------
examples/README.md | 1 +
.../camel-example-cdi-rest-servlet/README.md | 79 ++++++++++
examples/camel-example-cdi-rest-servlet/pom.xml | 151 +++++++++++++++++++
.../example/cdi/rest/servlet/Application.java | 59 ++++++++
.../src/main/resources/log4j.properties | 27 ++++
.../src/main/webapp/WEB-INF/beans.xml | 24 +++
.../src/main/webapp/WEB-INF/web.xml | 41 +++++
.../example/cdi/rest/servlet/RestCdiTest.java | 61 ++++++++
examples/pom.xml | 1 +
9 files changed, 444 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/README.md
----------------------------------------------------------------------
diff --git a/examples/README.md b/examples/README.md
index 35a4b30..9b204ad 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -51,6 +51,7 @@ All examples have been sort by type/category
* [camel-example-cdi](camel-example-cdi/README.md)
* [camel-example-cdi-metrics](camel-example-cdi-metrics/README.md)
* [camel-example-cdi-properties](camel-example-cdi-properties/README.md)
+* [camel-example-cdi-rest-servlet](camel-example-cdi-rest-servlet/README.md)
* [camel-example-widget-gadget-java](camel-example-widget-gadget-cdi/README.md)
##### OSGi
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/camel-example-cdi-rest-servlet/README.md
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-rest-servlet/README.md b/examples/camel-example-cdi-rest-servlet/README.md
new file mode 100644
index 0000000..9355282
--- /dev/null
+++ b/examples/camel-example-cdi-rest-servlet/README.md
@@ -0,0 +1,79 @@
+# REST DSL / Servlet Example - CDI
+
+### Introduction
+
+This example illustrates the Camel REST DSL being used in a Java application
+that uses CDI as dependency injection framework.
+
+The example uses the [`camel-servlet`][Servlet component] component
+as the underlying HTTP engine to service REST APIs defined with the Camel
+REST DSL.
+
+This example uses JBoss Weld as the minimal CDI container to run the application,
+and is deployed in Jetty as Servlet engine, though you can run the application
+in any CDI compliant container and Servlet container.
+
+[Servlet component]: http://camel.apache.org/servlet.html
+
+### Build
+
+You can build this example using:
+
+ mvn package
+
+### Run
+
+You can run this example using:
+
+ mvn jetty:run
+
+When the Camel application runs, you should see the following messages
+being logged to the console, e.g.:
+```
+2016-01-29 18:52:57,591 [main ] INFO servletWeldServlet - WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
+2016-01-29 18:52:58,313 [main ] INFO servletJetty - WELD-ENV-001200: Jetty 7.2+ detected, CDI injection will be available in Servlets and Filters. Injection into Listeners should work on Jetty 9.1.1 and newer.
+2016-01-29 18:52:58,885 [main ] INFO CdiCamelExtension - Camel CDI is starting Camel context [hello]
+2016-01-29 18:52:58,886 [main ] INFO DefaultCamelContext - Apache Camel 2.17-SNAPSHOT (CamelContext: hello) is starting
+2016-01-29 18:52:59,237 [main ] INFO DefaultCamelContext - Route: route1 started and consuming from: Endpoint[servlet:/say/hello?httpMethodRestrict=GET]
+2016-01-29 18:52:59,242 [main ] INFO DefaultCamelContext - Route: route2 started and consuming from: Endpoint[servlet:/say/hello/%7Bname%7D?httpMethodRestrict=GET]
+2016-01-29 18:52:59,242 [main ] INFO DefaultCamelContext - Total 2 routes, of which 2 is started.
+2016-01-29 18:52:59,243 [main ] INFO DefaultCamelContext - Apache Camel 2.17-SNAPSHOT (CamelContext: hello) started in 0.357 seconds
+2016-01-29 18:52:59,439 [main ] INFO servletWeldServlet - WELD-ENV-001006: org.jboss.weld.environment.servlet.EnhancedListener used for ServletContext notifications
+2016-01-29 18:52:59,439 [main ] INFO servletWeldServlet - WELD-ENV-001009: org.jboss.weld.environment.servlet.Listener used for ServletRequest and HttpSession notifications
+2016-01-29 18:52:59,471 [main ] INFO CamelHttpTransportServlet - Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=]
+[INFO] Started ServerConnector@63f7f62{HTTP/1.1}{0.0.0.0:8080}
+[INFO] Started @12857ms
+[INFO] Started Jetty Server
+```
+
+Then you can open the following URL into your Web browser, <http://localhost:8080/camel/say/hello/>, and
+being responded with `Hello World!`.
+
+Otherwise, in a separate prompt, by running:
+
+```
+curl http://localhost:8080/camel/say/hello/Antonin
+```
+
+You should being responded with the following message:
+
+```
+Hello Antonin, I'm CamelContext(hello)!
+```
+
+And see the following message being logged by the Camel application:
+
+```
+016-01-29 19:03:20,293 [tp1211352799-18] INFO route2 - Hello Antonin, I'm CamelContext(hello)!
+```
+
+The Camel application can be stopped pressing <kbd>ctrl</kbd>+<kbd>c</kbd> in the shell.
+
+### Forum, Help, etc
+
+If you hit an problems please let us know on the Camel Forums
+ <http://camel.apache.org/discussion-forums.html>
+
+Please help us make Apache Camel better - we appreciate any feedback you may have. Enjoy!
+
+The Camel riders!
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/camel-example-cdi-rest-servlet/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-rest-servlet/pom.xml b/examples/camel-example-cdi-rest-servlet/pom.xml
new file mode 100755
index 0000000..79d9bda
--- /dev/null
+++ b/examples/camel-example-cdi-rest-servlet/pom.xml
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>examples</artifactId>
+ <version>2.17-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-cdi-rest-servlet</artifactId>
+ <name>Camel :: Example :: CDI :: REST :: Servlet</name>
+ <description>REST DSL / Servlet with CDI example</description>
+ <packaging>war</packaging>
+
+ <dependencies>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-cdi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-servlet</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- CDI API -->
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>${cdi-api-1.2-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+
+ <!-- test -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ <version>${hamcrest-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <version>${arquillian-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.testenricher</groupId>
+ <artifactId>arquillian-testenricher-resource</artifactId>
+ <version>${arquillian-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+ <artifactId>shrinkwrap-descriptors-depchain</artifactId>
+ <version>${shrinkwrap-descriptors-version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld.servlet</groupId>
+ <artifactId>weld-servlet</artifactId>
+ <version>${weld2-version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>jetty</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>${jetty9-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-annotations</artifactId>
+ <version>${jetty9-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-jetty-embedded-9</artifactId>
+ <version>1.0.0.CR2</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-container-spi</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <!-- allows running this example with mvn jetty:run -->
+ <plugin>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <version>${jetty9-version}</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/camel-example-cdi-rest-servlet/src/main/java/org/apache/camel/example/cdi/rest/servlet/Application.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-rest-servlet/src/main/java/org/apache/camel/example/cdi/rest/servlet/Application.java b/examples/camel-example-cdi-rest-servlet/src/main/java/org/apache/camel/example/cdi/rest/servlet/Application.java
new file mode 100644
index 0000000..9a24d72
--- /dev/null
+++ b/examples/camel-example-cdi-rest-servlet/src/main/java/org/apache/camel/example/cdi/rest/servlet/Application.java
@@ -0,0 +1,59 @@
+/**
+ * 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.cdi.rest.servlet;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Header;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.cdi.ContextName;
+
+public class Application {
+
+ @ContextName("hello")
+ public static class HelloRoute extends RouteBuilder {
+
+ @Override
+ public void configure() {
+ restConfiguration().component("servlet");
+
+ rest("/say/")
+ .produces("text/plain")
+ .get("hello")
+ .route()
+ .transform().constant("Hello World!")
+ .endRest()
+ .get("hello/{name}")
+ .route()
+ .bean("hello")
+ .log("${body}");
+ }
+ }
+
+ @Named("hello")
+ public static class Hello {
+
+ @Inject
+ CamelContext context;
+
+ public String hello(@Header("name") String name) {
+ return "Hello " + name + ", I'm " + context + "!";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/camel-example-cdi-rest-servlet/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-rest-servlet/src/main/resources/log4j.properties b/examples/camel-example-cdi-rest-servlet/src/main/resources/log4j.properties
new file mode 100755
index 0000000..f5aae04
--- /dev/null
+++ b/examples/camel-example-cdi-rest-servlet/src/main/resources/log4j.properties
@@ -0,0 +1,27 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+# default properties to initialise log4j
+log4j.rootLogger=INFO, console
+
+# settings for specific packages
+#log4j.logger.org.apache.camel.cdi=DEBUG
+
+# Console appender
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/beans.xml b/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/beans.xml
new file mode 100755
index 0000000..2691bcf
--- /dev/null
+++ b/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+ http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
+ version="1.1" bean-discovery-mode="all">
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/web.xml b/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..0673337
--- /dev/null
+++ b/examples/camel-example-cdi-rest-servlet/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,41 @@
+<!--
+ 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.
+-->
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <display-name>My Web Application</display-name>
+
+ <!-- The listener that kick-starts CDI -->
+ <listener>
+ <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
+ </listener>
+
+ <!-- Camel servlet -->
+ <servlet>
+ <servlet-name>CamelServlet</servlet-name>
+ <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <!-- Camel servlet mapping -->
+ <servlet-mapping>
+ <servlet-name>CamelServlet</servlet-name>
+ <url-pattern>/camel/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java b/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java
new file mode 100644
index 0000000..3188035
--- /dev/null
+++ b/examples/camel-example-cdi-rest-servlet/src/test/java/org/apache/camel/example/cdi/rest/servlet/RestCdiTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.cdi.rest.servlet;
+
+import java.net.URL;
+import java.nio.file.Paths;
+
+import org.apache.camel.util.IOHelper;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+
+@RunWith(Arquillian.class)
+public class RestCdiTest {
+
+ @Deployment
+ public static Archive<?> createTestArchive() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addClass(Application.class)
+ .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
+ .setWebXML(Paths.get("src/main/webapp/WEB-INF/web.xml").toFile());
+ }
+
+ @Test
+ @RunAsClient
+ public void testWithPath(@ArquillianResource URL url) throws Exception {
+ assertThat(IOHelper.loadText(new URL(url, "camel/say/hello").openStream()), is(equalTo("Hello World!\n")));
+ }
+
+ @Test
+ @RunAsClient
+ public void testWithUriTemplate(@ArquillianResource URL url) throws Exception {
+ assertThat(IOHelper.loadText(new URL(url, "camel/say/hello/Antonin").openStream()), is(equalTo("Hello Antonin, I'm CamelContext(hello)!\n")));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/674b8cd2/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 03142e8..78fc546 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -39,6 +39,7 @@
<module>camel-example-cdi</module>
<module>camel-example-cdi-metrics</module>
<module>camel-example-cdi-properties</module>
+ <module>camel-example-cdi-rest-servlet</module>
<module>camel-example-cxf</module>
<module>camel-example-cxf-blueprint</module>
<module>camel-example-cxf-osgi</module>
[3/3] camel git commit: CAMEL-9542 - add labels to new options
Posted by da...@apache.org.
CAMEL-9542 - add labels to new options
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c6859ddf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c6859ddf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c6859ddf
Branch: refs/heads/master
Commit: c6859ddf073b7c4d77457a46aba43e11a3f953aa
Parents: 2210dd5
Author: lburgazzoli <lb...@gmail.com>
Authored: Fri Jan 29 17:45:52 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jan 30 08:10:47 2016 +0100
----------------------------------------------------------------------
.../component/geocoder/GeoCoderEndpoint.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c6859ddf/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
index 63d5262..03d021b 100644
--- a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
+++ b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
@@ -54,23 +54,23 @@ public class GeoCoderEndpoint extends DefaultEndpoint {
private String clientKey;
@UriParam
private boolean headersOnly;
- @UriParam
+ @UriParam(label = "proxy")
private String proxyHost;
- @UriParam
+ @UriParam(label = "proxy")
private Integer proxyPort;
- @UriParam
+ @UriParam(label = "proxy")
private String proxyAuthMethod;
- @UriParam
+ @UriParam(label = "proxy")
private String proxyAuthUsername;
- @UriParam
+ @UriParam(label = "proxy")
private String proxyAuthPassword;
- @UriParam
+ @UriParam(label = "proxy")
private String proxyAuthDomain;
- @UriParam
+ @UriParam(label = "proxy")
private String proxyAuthHost;
- @UriParam
+ @UriParam(label = "advanced")
private HttpClientConfigurer httpClientConfigurer;
- @UriParam
+ @UriParam(label = "advanced")
private HttpConnectionManager httpConnectionManager;
public GeoCoderEndpoint() {