You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/05/19 08:46:44 UTC

[2/4] camel git commit: Added camel-restlet docs to Gitbook

Added camel-restlet docs to Gitbook


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

Branch: refs/heads/master
Commit: 036ee6ba10aeee0a08c2f876415904ad39132317
Parents: e27f632
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu May 19 10:34:27 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu May 19 10:34:27 2016 +0200

----------------------------------------------------------------------
 .../camel-restlet/src/main/docs/restlet.adoc    | 396 +++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                  |   1 +
 2 files changed, 397 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/036ee6ba/components/camel-restlet/src/main/docs/restlet.adoc
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/docs/restlet.adoc b/components/camel-restlet/src/main/docs/restlet.adoc
new file mode 100644
index 0000000..03a3e8a
--- /dev/null
+++ b/components/camel-restlet/src/main/docs/restlet.adoc
@@ -0,0 +1,396 @@
+[[Restlet-RestletComponent]]
+Restlet Component
+~~~~~~~~~~~~~~~~~
+
+The *Restlet* component provides http://www.restlet.org[Restlet] based
+link:endpoint.html[endpoints] for consuming and producing RESTful
+resources.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-restlet</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+[[Restlet-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+----------------------------
+restlet:restletUrl[?options]
+----------------------------
+
+Format of restletUrl:
+
+[source,java]
+--------------------------------------------
+protocol://hostname[:port][/resourcePattern]
+--------------------------------------------
+
+Restlet promotes decoupling of protocol and application concerns. The
+reference implementation of
+http://www.noelios.com/products/restlet-engine[Restlet Engine] supports
+a number of protocols. However, we have tested the HTTP protocol only.
+The default port is port 80. We do not automatically switch default port
+based on the protocol yet.
+
+You can append query options to the URI in the following format,
+`?option=value&option=value&...`
+
+�
+
+INFO: It seems Restlet is case sensitive in understanding headers. For example
+to use content-type, use Content-Type, and for location use Location and
+so on.
+
+WARNING: We have received a report about drop in performance in camel-restlet in
+Camel 2.14.0 and 2.14.1. We have reported this to the Restlet team in
+https://github.com/restlet/restlet-framework-java/issues/996[issue 996].
+To remedy the issue then from Camel 2.14.2 onwards you can set
+synchronous=true as option on the endpoint uris, Or set it on the
+RestletComponent as a global option so all endpoints inherit this
+option.
+
+[[Restlet-Options]]
+Options
+^^^^^^^
+
+
+// component options: START
+The Restlet component supports 20 options which are listed below.
+
+
+
+{% raw %}
+[width="100%",cols="2s,1m,8",options="header"]
+|=======================================================================
+| Name | Java Type | Description
+| controllerDaemon | Boolean | Indicates if the controller thread should be a daemon (not blocking JVM exit).
+| controllerSleepTimeMs | Integer | Time for the controller thread to sleep between each control.
+| inboundBufferSize | Integer | The size of the buffer when reading messages.
+| maxConnectionsPerHost | Integer | Maximum number of concurrent connections per host (IP address).
+| maxThreads | Integer | Maximum threads that will service requests.
+| lowThreads | Integer | Number of worker threads determining when the connector is considered overloaded.
+| maxTotalConnections | Integer | Maximum number of concurrent connections in total.
+| minThreads | Integer | Minimum threads waiting to service requests.
+| outboundBufferSize | Integer | The size of the buffer when writing messages.
+| persistingConnections | Boolean | Indicates if connections should be kept alive after a call.
+| pipeliningConnections | Boolean | Indicates if pipelining connections are supported.
+| threadMaxIdleTimeMs | Integer | Time for an idle thread to wait for an operation before being collected.
+| useForwardedForHeader | Boolean | Lookup the X-Forwarded-For header supported by popular proxies and caches and uses it to populate the Request.getClientAddresses() method result. This information is only safe for intermediary components within your local network. Other addresses could easily be changed by setting a fake header and should not be trusted for serious security checks.
+| reuseAddress | Boolean | Enable/disable the SO_REUSEADDR socket option. See java.io.ServerSocketreuseAddress property for additional details.
+| maxQueued | Integer | Maximum number of calls that can be queued if there aren't any worker thread available to service them. If the value is '0' then no queue is used and calls are rejected if no worker thread is immediately available. If the value is '-1' then an unbounded queue is used and calls are never rejected.
+| disableStreamCache | boolean | Determines whether or not the raw input stream from Restlet is cached or not (Camel will read the stream into a in memory/overflow to file Stream caching) cache. By default Camel will cache the Restlet input stream to support reading it multiple times to ensure Camel can retrieve all data from the stream. However you can set this option to true when you for example need to access the raw stream such as streaming it directly to a file or other persistent store. DefaultRestletBinding will copy the request input stream into a stream cache and put it into message body if this option is false to support reading the stream multiple times.
+| port | int | To configure the port number for the restlet consumer routes. This allows to configure this once to reuse the same port for these consumers.
+| synchronous | Boolean | Whether to use synchronous Restlet Client for the producer. Setting this option to true can yield faster performance as it seems the Restlet synchronous Client works better.
+| enabledConverters | List | A list of converters to enable as full class name or simple class name. All the converters automatically registered are enabled if empty or null
+| headerFilterStrategy | HeaderFilterStrategy | To use a custom HeaderFilterStrategy to filter header to and from Camel message.
+|=======================================================================
+{% endraw %}
+// component options: END
+
+
+
+// endpoint options: START
+The Restlet component supports 21 endpoint options which are listed below:
+
+{% raw %}
+[width="100%",cols="2s,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| protocol | common |  | String | *Required* The protocol to use which is http or https
+| host | common |  | String | *Required* The hostname of the restlet service
+| port | common | 80 | int | *Required* The port number of the restlet service
+| uriPattern | common |  | String | The resource pattern such as /customer/id
+| restletMethod | common | GET | Method | On a producer endpoint specifies the request method to use. On a consumer endpoint specifies that the endpoint consumes only restletMethod requests.
+| bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
+| restletMethods | consumer |  | String | Specify one or more methods separated by commas (e.g. restletMethods=postput) to be serviced by a restlet consumer endpoint. If both restletMethod and restletMethods options are specified the restletMethod setting is ignored. The possible methods are: ALLCONNECTDELETEGETHEADOPTIONSPATCHPOSTPUTTRACE
+| restletUriPatterns | consumer |  | List | Specify one ore more URI templates to be serviced by a restlet consumer endpoint using the notation to reference a List in the Camel Registry. If a URI pattern has been defined in the endpoint URI both the URI pattern defined in the endpoint and the restletUriPatterns option will be honored.
+| exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
+| connectTimeout | producer | 30000 | int | The Client will give up connection if the connection is timeout 0 for unlimited wait.
+| socketTimeout | producer | 30000 | int | The Client socket receive timeout 0 for unlimited wait.
+| throwExceptionOnFailure | producer | true | boolean | Whether to throw exception on a producer failure. If this option is false then the http status code is set as a message header which can be checked if it has an error value.
+| autoCloseStream | producer (advanced) | false | boolean | Whether to auto close the stream representation as response from calling a REST service using the restlet producer. If the response is streaming and the option streamRepresentation is enabled then you may want to auto close the InputStream from the streaming response to ensure the input stream is closed when the Camel Exchange is done being routed. However if you need to read the stream outside a Camel route you may need to not auto close the stream.
+| streamRepresentation | producer (advanced) | false | boolean | Whether to support stream representation as response from calling a REST service using the restlet producer. If the response is streaming then this option can be enabled to use an java.io.InputStream as the message body on the Camel Message body. If using this option you may want to enable the autoCloseStream option as well to ensure the input stream is closed when the Camel Exchange is done being routed. However if you need to read the stream outside a Camel route you may need to not auto close the stream.
+| disableStreamCache | advanced | false | boolean | Determines whether or not the raw input stream from Restlet is cached or not (Camel will read the stream into a in memory/overflow to file Stream caching) cache. By default Camel will cache the Restlet input stream to support reading it multiple times to ensure Camel can retrieve all data from the stream. However you can set this option to true when you for example need to access the raw stream such as streaming it directly to a file or other persistent store. DefaultRestletBinding will copy the request input stream into a stream cache and put it into message body if this option is false to support reading the stream multiple times.
+| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange
+| headerFilterStrategy | advanced |  | HeaderFilterStrategy | To use a custom HeaderFilterStrategy to filter header to and from Camel message.
+| restletBinding | advanced |  | RestletBinding | To use a custom RestletBinding to bind between Restlet and Camel message.
+| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
+| restletRealm | security |  | Map | To configure the security realms of restlet as a map.
+| sslContextParameters | security |  | SSLContextParameters | To configure security using SSLContextParameters.
+|=======================================================================
+{% endraw %}
+// endpoint options: END
+
+
+[[Restlet-MessageHeaders]]
+Message Headers
+^^^^^^^^^^^^^^^
+
+[width="100%",cols="10%,10%,80%",options="header",]
+|=======================================================================
+|Name |Type |Description
+
+|`Content-Type` |`String` |Specifies the content type, which can be set on the OUT message by the
+application/processor. The value is the `content-type` of the response
+message. If this header is not set, the content type is based on the
+object type of the OUT message body. In Camel 2.3 onward, if the
+Content-Type header is specified in the Camel IN message, the value of
+the header determine the content type for the Restlet request message.��
+Otherwise, it is defaulted to "application/x-www-form-urlencoded'. Prior
+to release 2.3, it is not possible to change the request content type
+default.
+
+|`CamelAcceptContentType` |`String` |*Since Camel 2.9.3, 2.10.0:* The HTTP Accept request header.
+
+|`CamelHttpMethod` |`String` |The HTTP request method. This is set in the IN message header.
+
+|`CamelHttpQuery` |`String` |The query string of the request URI. It is set on the IN message by
+`DefaultRestletBinding` when the restlet component receives a request.
+
+|`CamelHttpResponseCode` |`String` or `Integer` |The response code can be set on the OUT message by the
+application/processor. The value is the response code of the response
+message. If this header is not set, the response code is set by the
+restlet runtime engine.
+
+|`CamelHttpUri` |`String` |The HTTP request URI. This is set in the IN message header.
+
+|`CamelRestletLogin` |`String` |Login name for basic authentication. It is set on the IN message by the
+application and gets filtered before the restlet request header by
+Camel.
+
+|`CamelRestletPassword` |`String` |Password name for basic authentication. It is set on the IN message by
+the application and gets filtered before the restlet request header by
+Camel.
+
+|`CamelRestletRequest` |`Request` |*Camel 2.8:* The `org.restlet.Request` object which holds all request
+details.
+
+|`CamelRestletResponse` |`Response` |*Camel 2.8:* The `org.restlet.Response` object. You can use this to
+create responses using the API from Restlet. See examples below.
+
+|`org.restlet.*` |  |Attributes of a Restlet message that get propagated to Camel IN headers.
+
+|`cache-control` |`String` or `List<CacheDirective>` |*Camel 2.11:* User can set the cache-control with the String value or
+the List of CacheDirective of Restlet from the camel message header.
+|=======================================================================
+
+[[Restlet-MessageBody]]
+Message Body
+^^^^^^^^^^^^
+
+Camel will store the restlet response from the external server on the
+OUT body. All headers from the IN message will be copied to the OUT
+message, so that headers are preserved during routing.
+
+[[Restlet-Samples]]
+Samples
+^^^^^^^
+
+[[Restlet-RestletEndpointwithAuthentication]]
+Restlet Endpoint with Authentication
+++++++++++++++++++++++++++++++++++++
+
+The following route starts a `restlet` consumer endpoint that listens
+for `POST` requests on http://localhost:8080. The processor creates a
+response that echoes the request body and the value of the `id` header.
+
+The `restletRealm` setting in the URI query is used to look up a Realm
+Map in the registry. If this option is specified, the restlet consumer
+uses the information to authenticate user logins. Only _authenticated_
+requests can access the resources. In this sample, we create a Spring
+application context that serves as a registry. The bean ID of the Realm
+Map should match the _restletRealmRef_.
+
+The following sample starts a `direct` endpoint that sends requests to
+the server on http://localhost:8080 (that is, our restlet consumer
+endpoint).
+
+That is all we need. We are ready to send a request and try out the
+restlet component:
+
+The sample client sends a request to the `direct:start-auth` endpoint
+with the following headers:
+
+* `CamelRestletLogin` (used internally by Camel)
+* `CamelRestletPassword` (used internally by Camel)
+* `id` (application header)
+
+NOTE: `org.apache.camel.restlet.auth.login` and
+`org.apache.camel.restlet.auth.password` will not be propagated as
+Restlet header.
+
+The sample client gets a response like the following:
+
+[source,text]
+--------------------------------------------------
+received [<order foo='1'/>] as an order id = 89531
+--------------------------------------------------
+
+[[Restlet-SinglerestletendpointtoservicemultiplemethodsandURItemplates]]
+Single restlet endpoint to service multiple methods and URI templates
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+It is possible to create a single route to service multiple HTTP methods
+using the `restletMethods` option. This snippet also shows how to
+retrieve the request method from the header:
+
+In addition to servicing multiple methods, the next snippet shows how to
+create an endpoint that supports multiple URI templates using the
+`restletUriPatterns` option. The request URI is available in the header
+of the IN message as well. If a URI pattern has been defined in the
+endpoint URI (which is not the case in this sample), both the URI
+pattern defined in the endpoint and the `restletUriPatterns` option will
+be honored.
+
+The `restletUriPatterns=#uriTemplates` option references the
+`List<String>` bean defined in the Spring XML configuration.
+
+[source,xml]
+--------------------------------------------------------
+<util:list id="uriTemplates">
+    <value>/users/{username}</value>
+    <value>/atom/collection/{id}/component/{cid}</value>
+</util:list>
+--------------------------------------------------------
+
+[[Restlet-UsingRestletAPItopopulateresponse]]
+Using Restlet API to populate response
+++++++++++++++++++++++++++++++++++++++
+
+*Available as of Camel 2.8*
+
+You may want to use the `org.restlet.Response` API to populate the
+response. This gives you full access to the Restlet API and fine grained
+control of the response. See the route snippet below where we generate
+the response from an inlined Camel link:processor.html[Processor]:
+
+*Generating response using Restlet Response API*
+
+[[Restlet-Configuringmaxthreadsoncomponent]]
+Configuring max threads on component
+++++++++++++++++++++++++++++++++++++
+
+To configure the max threads options you must do this on the component,
+such as:
+
+[source,xml]
+-------------------------------------------------------------------------------
+<bean id="restlet" class="org.apache.camel.component.restlet.RestletComponent">
+  <property name="maxThreads" value="100"/>
+</bean>
+-------------------------------------------------------------------------------
+
+[[Restlet-UsingtheRestletservletwithinawebapp]]
+Using the Restlet servlet within a webapp
++++++++++++++++++++++++++++++++++++++++++
+
+*Available as of Camel 2.8* +
+ There are
+http://www.restlet.org/documentation/2.0/jee/ext/org/restlet/ext/servlet/ServerServlet.html[three
+possible ways] to configure a Restlet application within a servlet
+container and using the subclassed SpringServerServlet enables
+configuration within Camel by injecting the Restlet Component.
+
+Use of the Restlet servlet within a servlet container enables routes to
+be configured with relative paths in URIs (removing the restrictions of
+hard-coded absolute URIs) and for the hosting servlet container to
+handle incoming requests (rather than have to spawn a separate server
+process on a new port).
+
+To configure, add the following to your camel-context.xml;
+
+[source,xml]
+-----------------------------------------------------------------------------------------------
+<camelContext>
+  <route id="RS_RestletDemo">
+    <from uri="restlet:/demo/{id}" />
+    <transform>
+      <simple>Request type : ${header.CamelHttpMethod} and ID : ${header.id}</simple>
+    </transform>
+  </route> 
+</camelContext>
+
+<bean id="RestletComponent" class="org.restlet.Component" />
+
+<bean id="RestletComponentService" class="org.apache.camel.component.restlet.RestletComponent">
+  <constructor-arg index="0">
+    <ref bean="RestletComponent" />
+  </constructor-arg>
+</bean>
+-----------------------------------------------------------------------------------------------
+
+And add this to your web.xml;
+
+[source,xml]
+---------------------------------------------------------------------------
+<!-- Restlet Servlet -->
+<servlet>
+  <servlet-name>RestletServlet</servlet-name>
+  <servlet-class>org.restlet.ext.spring.SpringServerServlet</servlet-class>
+  <init-param>
+    <param-name>org.restlet.component</param-name>
+    <param-value>RestletComponent</param-value>
+  </init-param>
+</servlet>
+
+<servlet-mapping>
+  <servlet-name>RestletServlet</servlet-name>
+  <url-pattern>/rs/*</url-pattern>
+</servlet-mapping>
+---------------------------------------------------------------------------
+
+You will then be able to access the deployed route at
+http://localhost:8080/mywebapp/rs/demo/1234 where;
+
+localhost:8080 is the server and port of your servlet container +
+ mywebapp is the name of your deployed webapp +
+ Your browser will then show the following content;
+
+[source,java]
+----------------------------------
+"Request type : GET and ID : 1234"
+----------------------------------
+
+You will need to add dependency on the Spring extension to restlet which
+you can do in your Maven pom.xml file:
+
+[source,xml]
+-------------------------------------------------
+<dependency>
+  <groupId>org.restlet.jee</groupId>
+  <artifactId>org.restlet.ext.spring</artifactId>
+  <version>${restlet-version}</version>
+</dependency>
+-------------------------------------------------
+
+And you would need to add dependency on the restlet maven repository as
+well:
+
+[source,xml]
+--------------------------------------------------
+<repository>  
+   <id>maven-restlet</id>  
+   <name>Public online Restlet repository</name>  
+   <url>http://maven.restlet.org</url>  
+</repository>
+--------------------------------------------------
+
+[[Restlet-SeeAlso]]
+See Also
+^^^^^^^^
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]
+

http://git-wip-us.apache.org/repos/asf/camel/blob/036ee6ba/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 2cf6ae4..cadf448 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -222,6 +222,7 @@
     * [Quartz2](quartz2.adoc)
     * [Quickfix](quickfix.adoc)
     * [RabbitMQ](rabbitmq.adoc)
+    * [Restlet](restlet.adoc)
     * [Scp](scp.adoc)
     * [SJMS](sjms.adoc)
     * [SJMS Batch](sjms-batch.adoc)